From 60a41a82e0de012e0ea9e5fca1a0205bf8261c5d Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Wed, 26 Oct 2022 01:38:30 -0700 Subject: [PATCH] Autoresize playground imgui windows --- impeller/aiks/aiks_unittests.cc | 89 +------------------ .../display_list/display_list_unittests.cc | 40 +-------- impeller/entity/entity_unittests.cc | 44 +-------- impeller/playground/playground.cc | 2 + impeller/renderer/renderer_unittests.cc | 13 +-- 5 files changed, 8 insertions(+), 180 deletions(-) diff --git a/impeller/aiks/aiks_unittests.cc b/impeller/aiks/aiks_unittests.cc index 26aadbeee8ca6..73539134cb924 100644 --- a/impeller/aiks/aiks_unittests.cc +++ b/impeller/aiks/aiks_unittests.cc @@ -100,8 +100,6 @@ TEST_P(AiksTest, CanRenderTiledTexture) { if (first_frame) { first_frame = false; GenerateMipmap(context, texture, "table_mountain_nx"); - ImGui::SetNextWindowSize({480, 100}); - ImGui::SetNextWindowPos({100, 550}); } const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"}; @@ -302,14 +300,7 @@ TEST_P(AiksTest, CanSaveLayerStandalone) { } TEST_P(AiksTest, CanRenderLinearGradient) { - bool first_frame = true; auto callback = [&](AiksContext& renderer, RenderTarget& render_target) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({480, 100}); - ImGui::SetNextWindowPos({100, 550}); - } - const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"}; const Entity::TileMode tile_modes[] = { Entity::TileMode::kClamp, Entity::TileMode::kRepeat, @@ -360,14 +351,7 @@ TEST_P(AiksTest, CanRenderLinearGradient) { } TEST_P(AiksTest, CanRenderLinearGradientManyColors) { - bool first_frame = true; auto callback = [&](AiksContext& renderer, RenderTarget& render_target) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({480, 100}); - ImGui::SetNextWindowPos({100, 550}); - } - const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"}; const Entity::TileMode tile_modes[] = { Entity::TileMode::kClamp, Entity::TileMode::kRepeat, @@ -432,14 +416,7 @@ TEST_P(AiksTest, CanRenderLinearGradientManyColors) { } TEST_P(AiksTest, CanRenderLinearGradientWayManyColors) { - bool first_frame = true; auto callback = [&](AiksContext& renderer, RenderTarget& render_target) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({480, 100}); - ImGui::SetNextWindowPos({100, 550}); - } - const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"}; const Entity::TileMode tile_modes[] = { Entity::TileMode::kClamp, Entity::TileMode::kRepeat, @@ -494,14 +471,7 @@ TEST_P(AiksTest, CanRenderLinearGradientWayManyColors) { } TEST_P(AiksTest, CanRenderLinearGradientManyColorsUnevenStops) { - bool first_frame = true; auto callback = [&](AiksContext& renderer, RenderTarget& render_target) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({480, 100}); - ImGui::SetNextWindowPos({100, 550}); - } - const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"}; const Entity::TileMode tile_modes[] = { Entity::TileMode::kClamp, Entity::TileMode::kRepeat, @@ -558,14 +528,7 @@ TEST_P(AiksTest, CanRenderLinearGradientManyColorsUnevenStops) { } TEST_P(AiksTest, CanRenderRadialGradient) { - bool first_frame = true; auto callback = [&](AiksContext& renderer, RenderTarget& render_target) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({480, 100}); - ImGui::SetNextWindowPos({100, 550}); - } - const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"}; const Entity::TileMode tile_modes[] = { Entity::TileMode::kClamp, Entity::TileMode::kRepeat, @@ -613,14 +576,7 @@ TEST_P(AiksTest, CanRenderRadialGradient) { } TEST_P(AiksTest, CanRenderRadialGradientManyColors) { - bool first_frame = true; auto callback = [&](AiksContext& renderer, RenderTarget& render_target) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({480, 100}); - ImGui::SetNextWindowPos({100, 550}); - } - const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"}; const Entity::TileMode tile_modes[] = { Entity::TileMode::kClamp, Entity::TileMode::kRepeat, @@ -682,14 +638,7 @@ TEST_P(AiksTest, CanRenderRadialGradientManyColors) { } TEST_P(AiksTest, CanRenderSweepGradient) { - bool first_frame = true; auto callback = [&](AiksContext& renderer, RenderTarget& render_target) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({480, 100}); - ImGui::SetNextWindowPos({100, 550}); - } - const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"}; const Entity::TileMode tile_modes[] = { Entity::TileMode::kClamp, Entity::TileMode::kRepeat, @@ -736,14 +685,7 @@ TEST_P(AiksTest, CanRenderSweepGradient) { } TEST_P(AiksTest, CanRenderSweepGradientManyColors) { - bool first_frame = true; auto callback = [&](AiksContext& renderer, RenderTarget& render_target) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({480, 100}); - ImGui::SetNextWindowPos({100, 550}); - } - const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"}; const Entity::TileMode tile_modes[] = { Entity::TileMode::kClamp, Entity::TileMode::kRepeat, @@ -834,14 +776,7 @@ TEST_P(AiksTest, CanRenderDifferentShapesWithSameColorSource) { } TEST_P(AiksTest, CanPictureConvertToImage) { - bool first_frame = true; auto callback = [&](AiksContext& renderer, RenderTarget& render_target) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({480, 100}); - ImGui::SetNextWindowPos({100, 550}); - } - static int size[2] = {1000, 1000}; ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize); ImGui::SliderInt2("Size", size, 0, 1000); @@ -1295,13 +1230,7 @@ TEST_P(AiksTest, ColorWheel) { std::shared_ptr color_wheel_image; Matrix color_wheel_transform; - bool first_frame = true; auto callback = [&](AiksContext& renderer, RenderTarget& render_target) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowPos({25, 25}); - } - // UI state. static int current_blend_index = 3; static float dst_alpha = 1; @@ -1429,19 +1358,12 @@ TEST_P(AiksTest, TransformMultipliesCorrectly) { TEST_P(AiksTest, SolidStrokesRenderCorrectly) { // Compare with https://fiddle.skia.org/c/027392122bec8ac2b5d5de00a4b9bbe2 - bool first_frame = true; auto callback = [&](AiksContext& renderer, RenderTarget& render_target) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({480, 100}); - ImGui::SetNextWindowPos({100, 550}); - } - static Color color = Color::Black().WithAlpha(0.5); static float scale = 3; static bool add_circle_clip = true; - ImGui::Begin("Controls"); + ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize); ImGui::ColorEdit4("Color", reinterpret_cast(&color)); ImGui::SliderFloat("Scale", &scale, 0, 6); ImGui::Checkbox("Circle clip", &add_circle_clip); @@ -1499,14 +1421,7 @@ TEST_P(AiksTest, SolidStrokesRenderCorrectly) { TEST_P(AiksTest, GradientStrokesRenderCorrectly) { // Compare with https://fiddle.skia.org/c/027392122bec8ac2b5d5de00a4b9bbe2 - bool first_frame = true; auto callback = [&](AiksContext& renderer, RenderTarget& render_target) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({480, 100}); - ImGui::SetNextWindowPos({100, 550}); - } - static float scale = 3; static bool add_circle_clip = true; const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"}; @@ -1516,7 +1431,7 @@ TEST_P(AiksTest, GradientStrokesRenderCorrectly) { static int selected_tile_mode = 0; static float alpha = 1; - ImGui::Begin("Controls"); + ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize); ImGui::SliderFloat("Scale", &scale, 0, 6); ImGui::Checkbox("Circle clip", &add_circle_clip); ImGui::SliderFloat("Alpha", &alpha, 0, 1); diff --git a/impeller/display_list/display_list_unittests.cc b/impeller/display_list/display_list_unittests.cc index b5762bbbd45e5..fb637ed509019 100644 --- a/impeller/display_list/display_list_unittests.cc +++ b/impeller/display_list/display_list_unittests.cc @@ -97,14 +97,7 @@ TEST_P(DisplayListTest, CanDrawCapsAndJoins) { } TEST_P(DisplayListTest, CanDrawArc) { - bool first_frame = true; auto callback = [&]() { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({400, 100}); - ImGui::SetNextWindowPos({300, 550}); - } - static float start_angle = 45; static float sweep_angle = 270; static bool use_center = true; @@ -283,17 +276,10 @@ TEST_P(DisplayListTest, CanDrawWithColorFilterImageFilter) { TEST_P(DisplayListTest, CanDrawWithImageBlurFilter) { auto texture = CreateTextureForFixture("embarcadero.jpg"); - bool first_frame = true; auto callback = [&]() { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({400, 100}); - ImGui::SetNextWindowPos({300, 550}); - } - static float sigma[] = {10, 10}; - ImGui::Begin("Controls"); + ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize); ImGui::SliderFloat2("Sigma", sigma, 0, 100); ImGui::End(); @@ -361,14 +347,8 @@ TEST_P(DisplayListTest, CanClampTheResultingColorOfColorMatrixFilter) { TEST_P(DisplayListTest, SaveLayerWithColorMatrixFiltersAndAlphaDrawCorrectly) { auto texture = CreateTextureForFixture("boston.jpg"); - bool first_frame = true; enum class Type { kUseAsImageFilter, kUseAsColorFilter, kDisableFilter }; auto callback = [&]() { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowPos({10, 10}); - } - static float alpha = 0.5; static int selected_type = 0; const char* names[] = {"Use as image filter", "Use as color filter", @@ -426,14 +406,8 @@ TEST_P(DisplayListTest, SaveLayerWithColorMatrixFiltersAndAlphaDrawCorrectly) { TEST_P(DisplayListTest, SaveLayerWithBlendFiltersAndAlphaDrawCorrectly) { auto texture = CreateTextureForFixture("boston.jpg"); - bool first_frame = true; enum class Type { kUseAsImageFilter, kUseAsColorFilter, kDisableFilter }; auto callback = [&]() { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowPos({10, 10}); - } - static float alpha = 0.5; static int selected_type = 0; const char* names[] = {"Use as image filter", "Use as color filter", @@ -479,13 +453,7 @@ TEST_P(DisplayListTest, SaveLayerWithBlendFiltersAndAlphaDrawCorrectly) { TEST_P(DisplayListTest, CanDrawBackdropFilter) { auto texture = CreateTextureForFixture("embarcadero.jpg"); - bool first_frame = true; auto callback = [&]() { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowPos({10, 10}); - } - static float sigma[] = {10, 10}; static float ctm_scale = 1; static bool use_bounds = true; @@ -775,13 +743,7 @@ TEST_P(DisplayListTest, CanDrawZeroWidthLine) { TEST_P(DisplayListTest, CanDrawWithMatrixFilter) { auto boston = CreateTextureForFixture("boston.jpg"); - bool first_frame = true; auto callback = [&]() { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowPos({10, 10}); - } - static int selected_matrix_type = 0; const char* matrix_type_names[] = {"Matrix", "Local Matrix"}; diff --git a/impeller/entity/entity_unittests.cc b/impeller/entity/entity_unittests.cc index 3420166cad10f..ec7b8b06a1c92 100644 --- a/impeller/entity/entity_unittests.cc +++ b/impeller/entity/entity_unittests.cc @@ -264,22 +264,14 @@ TEST_P(EntityTest, StrokeCapAndJoinTest) { const Point padding(300, 250); const Point margin(140, 180); - bool first_frame = true; auto callback = [&](ContentContext& context, RenderPass& pass) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({300, 100}); - ImGui::SetNextWindowPos( - {0 * padding.x + margin.x, 1.7f * padding.y + margin.y}); - } - // Slightly above sqrt(2) by default, so that right angles are just below // the limit and acute angles are over the limit (causing them to get // beveled). static Scalar miter_limit = 1.41421357; static Scalar width = 30; - ImGui::Begin("Controls"); + ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize); { ImGui::SliderFloat("Miter limit", &miter_limit, 0, 30); ImGui::SliderFloat("Stroke width", &width, 0, 100); @@ -741,14 +733,7 @@ TEST_P(EntityTest, BlendingModeOptions) { }; } - bool first_frame = true; auto callback = [&](ContentContext& context, RenderPass& pass) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({350, 200}); - ImGui::SetNextWindowPos({200, 450}); - } - auto world_matrix = Matrix::MakeScale(GetContentScale()); auto draw_rect = [&context, &pass, &world_matrix]( Rect rect, Color color, BlendMode blend_mode) -> bool { @@ -792,7 +777,7 @@ TEST_P(EntityTest, BlendingModeOptions) { return pass.AddCommand(std::move(cmd)); }; - ImGui::Begin("Controls"); + ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize); static Color color1(1, 0, 0, 0.5), color2(0, 1, 0, 0.5); ImGui::ColorEdit4("Color 1", reinterpret_cast(&color1)); ImGui::ColorEdit4("Color 2", reinterpret_cast(&color2)); @@ -879,13 +864,7 @@ TEST_P(EntityTest, GaussianBlurFilter) { auto boston = CreateTextureForFixture("boston.jpg"); ASSERT_TRUE(boston); - bool first_frame = true; auto callback = [&](ContentContext& context, RenderPass& pass) -> bool { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowPos({10, 10}); - } - const char* input_type_names[] = {"Texture", "Solid Color"}; const char* blur_type_names[] = {"Image blur", "Mask blur"}; const char* pass_variation_names[] = {"Two pass", "Directional"}; @@ -1035,13 +1014,7 @@ TEST_P(EntityTest, MorphologyFilter) { auto boston = CreateTextureForFixture("boston.jpg"); ASSERT_TRUE(boston); - bool first_frame = true; auto callback = [&](ContentContext& context, RenderPass& pass) -> bool { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowPos({10, 10}); - } - const char* morphology_type_names[] = {"Dilate", "Erode"}; const FilterContents::MorphType morphology_types[] = { FilterContents::MorphType::kDilate, FilterContents::MorphType::kErode}; @@ -1563,13 +1536,7 @@ TEST_P(EntityTest, ClipContentsShouldRenderIsCorrect) { } TEST_P(EntityTest, RRectShadowTest) { - bool first_frame = true; auto callback = [&](ContentContext& context, RenderPass& pass) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowPos({10, 10}); - } - static Color color = Color::Red(); static float corner_radius = 100; static float blur_radius = 100; @@ -1651,14 +1618,7 @@ TEST_P(EntityTest, ColorMatrixFilterEditable) { auto bay_bridge = CreateTextureForFixture("bay_bridge.jpg"); ASSERT_TRUE(bay_bridge); - bool first_frame = true; auto callback = [&](ContentContext& context, RenderPass& pass) -> bool { - // If this is the first frame, set the ImGui's initial size and postion. - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowPos({10, 10}); - } - // UI state. static FilterContents::ColorMatrix color_matrix = { 1, 0, 0, 0, 0, // diff --git a/impeller/playground/playground.cc b/impeller/playground/playground.cc index 312713c264385..af68c3135c57c 100644 --- a/impeller/playground/playground.cc +++ b/impeller/playground/playground.cc @@ -213,6 +213,8 @@ bool Playground::OpenPlaygroundHere( fml::ScopedCleanupClosure shutdown_imgui_impeller( []() { ImGui_ImplImpeller_Shutdown(); }); + ImGui::SetNextWindowPos({10, 10}); + ::glfwSetWindowSize(window, GetWindowSize().width, GetWindowSize().height); ::glfwSetWindowPos(window, 200, 100); ::glfwShowWindow(window); diff --git a/impeller/renderer/renderer_unittests.cc b/impeller/renderer/renderer_unittests.cc index bdb63c62e4602..32b4f5623bfde 100644 --- a/impeller/renderer/renderer_unittests.cc +++ b/impeller/renderer/renderer_unittests.cc @@ -165,18 +165,11 @@ TEST_P(RendererTest, CanRenderPerspectiveCube) { ASSERT_TRUE(sampler); Vector3 euler_angles; - bool first_frame = true; SinglePassCallback callback = [&](RenderPass& pass) { - if (first_frame) { - first_frame = false; - ImGui::SetNextWindowSize({400, 80}); - ImGui::SetNextWindowPos({20, 20}); - } - static Degrees fov_y(60); static Scalar distance = 10; - ImGui::Begin("Controls"); + ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize); ImGui::SliderFloat("Field of view", &fov_y.degrees, 0, 180); ImGui::SliderFloat("Camera distance", &distance, 0, 30); ImGui::End(); @@ -598,10 +591,6 @@ TEST_P(RendererTest, CanGenerateMipmaps) { bool first_frame = true; Renderer::RenderCallback callback = [&](RenderTarget& render_target) { - if (first_frame) { - ImGui::SetNextWindowPos({10, 10}); - } - const char* mip_filter_names[] = {"None", "Nearest", "Linear"}; const MipFilter mip_filters[] = {MipFilter::kNone, MipFilter::kNearest, MipFilter::kLinear};