mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Allow resizing the playground.
This commit is contained in:
parent
74112baee7
commit
1d95b191dc
@ -33,9 +33,12 @@ class Playground : public ::testing::Test {
|
||||
private:
|
||||
Renderer renderer_;
|
||||
Point cursor_position_;
|
||||
ISize window_size_ = ISize{1024, 768};
|
||||
|
||||
void SetCursorPosition(Point pos);
|
||||
|
||||
void SetWindowSize(ISize size);
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(Playground);
|
||||
};
|
||||
|
||||
|
||||
@ -78,7 +78,7 @@ Point Playground::GetCursorPosition() const {
|
||||
}
|
||||
|
||||
ISize Playground::GetWindowSize() const {
|
||||
return {1024, 768};
|
||||
return window_size_;
|
||||
}
|
||||
|
||||
void Playground::SetCursorPosition(Point pos) {
|
||||
@ -100,10 +100,6 @@ bool Playground::OpenPlaygroundHere(Renderer::RenderCallback render_callback) {
|
||||
fml::ScopedCleanupClosure terminate([]() { ::glfwTerminate(); });
|
||||
|
||||
::glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
// Recreation of the target render buffer is not setup in the playground yet.
|
||||
// So prevent users from resizing and getting confused that their math is
|
||||
// wrong.
|
||||
::glfwWindowHint(GLFW_RESIZABLE, false);
|
||||
|
||||
auto window_title = GetWindowTitle(flutter::testing::GetCurrentTestName());
|
||||
auto window =
|
||||
@ -114,6 +110,16 @@ bool Playground::OpenPlaygroundHere(Renderer::RenderCallback render_callback) {
|
||||
}
|
||||
|
||||
::glfwSetWindowUserPointer(window, this);
|
||||
::glfwSetWindowSizeCallback(
|
||||
window, [](GLFWwindow* window, int width, int height) -> void {
|
||||
auto playground =
|
||||
reinterpret_cast<Playground*>(::glfwGetWindowUserPointer(window));
|
||||
if (!playground) {
|
||||
return;
|
||||
}
|
||||
playground->SetWindowSize(
|
||||
ISize{std::max(width, 0), std::max(height, 0)});
|
||||
});
|
||||
::glfwSetKeyCallback(window, &PlaygroundKeyCallback);
|
||||
::glfwSetCursorPosCallback(window, [](GLFWwindow* window, double x,
|
||||
double y) {
|
||||
@ -138,6 +144,11 @@ bool Playground::OpenPlaygroundHere(Renderer::RenderCallback render_callback) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const auto layer_size = layer.bounds.size;
|
||||
const auto layer_scale = layer.contentsScale;
|
||||
layer.drawableSize = CGSizeMake(layer_size.width * layer_scale,
|
||||
layer_size.height * layer_scale);
|
||||
|
||||
Renderer::RenderCallback wrapped_callback = [render_callback](auto& pass) {
|
||||
pass.SetLabel("Playground Main Render Pass");
|
||||
return render_callback(pass);
|
||||
@ -193,4 +204,8 @@ std::shared_ptr<Texture> Playground::CreateTextureForFixture(
|
||||
return texture;
|
||||
}
|
||||
|
||||
void Playground::SetWindowSize(ISize size) {
|
||||
window_size_ = size;
|
||||
}
|
||||
|
||||
} // namespace impeller
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user