Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 701c6e6

Browse files
authored
[Impeller] Autoresize playground imgui windows (#37033)
1 parent 95fce00 commit 701c6e6

File tree

5 files changed

+8
-180
lines changed

5 files changed

+8
-180
lines changed

impeller/aiks/aiks_unittests.cc

+2-87
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ TEST_P(AiksTest, CanRenderTiledTexture) {
101101
if (first_frame) {
102102
first_frame = false;
103103
GenerateMipmap(context, texture, "table_mountain_nx");
104-
ImGui::SetNextWindowSize({480, 100});
105-
ImGui::SetNextWindowPos({100, 550});
106104
}
107105

108106
const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
@@ -303,14 +301,7 @@ TEST_P(AiksTest, CanSaveLayerStandalone) {
303301
}
304302

305303
TEST_P(AiksTest, CanRenderLinearGradient) {
306-
bool first_frame = true;
307304
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
308-
if (first_frame) {
309-
first_frame = false;
310-
ImGui::SetNextWindowSize({480, 100});
311-
ImGui::SetNextWindowPos({100, 550});
312-
}
313-
314305
const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
315306
const Entity::TileMode tile_modes[] = {
316307
Entity::TileMode::kClamp, Entity::TileMode::kRepeat,
@@ -361,14 +352,7 @@ TEST_P(AiksTest, CanRenderLinearGradient) {
361352
}
362353

363354
TEST_P(AiksTest, CanRenderLinearGradientManyColors) {
364-
bool first_frame = true;
365355
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
366-
if (first_frame) {
367-
first_frame = false;
368-
ImGui::SetNextWindowSize({480, 100});
369-
ImGui::SetNextWindowPos({100, 550});
370-
}
371-
372356
const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
373357
const Entity::TileMode tile_modes[] = {
374358
Entity::TileMode::kClamp, Entity::TileMode::kRepeat,
@@ -433,14 +417,7 @@ TEST_P(AiksTest, CanRenderLinearGradientManyColors) {
433417
}
434418

435419
TEST_P(AiksTest, CanRenderLinearGradientWayManyColors) {
436-
bool first_frame = true;
437420
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
438-
if (first_frame) {
439-
first_frame = false;
440-
ImGui::SetNextWindowSize({480, 100});
441-
ImGui::SetNextWindowPos({100, 550});
442-
}
443-
444421
const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
445422
const Entity::TileMode tile_modes[] = {
446423
Entity::TileMode::kClamp, Entity::TileMode::kRepeat,
@@ -495,14 +472,7 @@ TEST_P(AiksTest, CanRenderLinearGradientWayManyColors) {
495472
}
496473

497474
TEST_P(AiksTest, CanRenderLinearGradientManyColorsUnevenStops) {
498-
bool first_frame = true;
499475
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
500-
if (first_frame) {
501-
first_frame = false;
502-
ImGui::SetNextWindowSize({480, 100});
503-
ImGui::SetNextWindowPos({100, 550});
504-
}
505-
506476
const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
507477
const Entity::TileMode tile_modes[] = {
508478
Entity::TileMode::kClamp, Entity::TileMode::kRepeat,
@@ -559,14 +529,7 @@ TEST_P(AiksTest, CanRenderLinearGradientManyColorsUnevenStops) {
559529
}
560530

561531
TEST_P(AiksTest, CanRenderRadialGradient) {
562-
bool first_frame = true;
563532
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
564-
if (first_frame) {
565-
first_frame = false;
566-
ImGui::SetNextWindowSize({480, 100});
567-
ImGui::SetNextWindowPos({100, 550});
568-
}
569-
570533
const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
571534
const Entity::TileMode tile_modes[] = {
572535
Entity::TileMode::kClamp, Entity::TileMode::kRepeat,
@@ -614,14 +577,7 @@ TEST_P(AiksTest, CanRenderRadialGradient) {
614577
}
615578

616579
TEST_P(AiksTest, CanRenderRadialGradientManyColors) {
617-
bool first_frame = true;
618580
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
619-
if (first_frame) {
620-
first_frame = false;
621-
ImGui::SetNextWindowSize({480, 100});
622-
ImGui::SetNextWindowPos({100, 550});
623-
}
624-
625581
const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
626582
const Entity::TileMode tile_modes[] = {
627583
Entity::TileMode::kClamp, Entity::TileMode::kRepeat,
@@ -683,14 +639,7 @@ TEST_P(AiksTest, CanRenderRadialGradientManyColors) {
683639
}
684640

685641
TEST_P(AiksTest, CanRenderSweepGradient) {
686-
bool first_frame = true;
687642
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
688-
if (first_frame) {
689-
first_frame = false;
690-
ImGui::SetNextWindowSize({480, 100});
691-
ImGui::SetNextWindowPos({100, 550});
692-
}
693-
694643
const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
695644
const Entity::TileMode tile_modes[] = {
696645
Entity::TileMode::kClamp, Entity::TileMode::kRepeat,
@@ -737,14 +686,7 @@ TEST_P(AiksTest, CanRenderSweepGradient) {
737686
}
738687

739688
TEST_P(AiksTest, CanRenderSweepGradientManyColors) {
740-
bool first_frame = true;
741689
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
742-
if (first_frame) {
743-
first_frame = false;
744-
ImGui::SetNextWindowSize({480, 100});
745-
ImGui::SetNextWindowPos({100, 550});
746-
}
747-
748690
const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
749691
const Entity::TileMode tile_modes[] = {
750692
Entity::TileMode::kClamp, Entity::TileMode::kRepeat,
@@ -835,14 +777,7 @@ TEST_P(AiksTest, CanRenderDifferentShapesWithSameColorSource) {
835777
}
836778

837779
TEST_P(AiksTest, CanPictureConvertToImage) {
838-
bool first_frame = true;
839780
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
840-
if (first_frame) {
841-
first_frame = false;
842-
ImGui::SetNextWindowSize({480, 100});
843-
ImGui::SetNextWindowPos({100, 550});
844-
}
845-
846781
static int size[2] = {1000, 1000};
847782
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
848783
ImGui::SliderInt2("Size", size, 0, 1000);
@@ -1296,13 +1231,7 @@ TEST_P(AiksTest, ColorWheel) {
12961231
std::shared_ptr<Image> color_wheel_image;
12971232
Matrix color_wheel_transform;
12981233

1299-
bool first_frame = true;
13001234
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
1301-
if (first_frame) {
1302-
first_frame = false;
1303-
ImGui::SetNextWindowPos({25, 25});
1304-
}
1305-
13061235
// UI state.
13071236
static int current_blend_index = 3;
13081237
static float dst_alpha = 1;
@@ -1430,19 +1359,12 @@ TEST_P(AiksTest, TransformMultipliesCorrectly) {
14301359

14311360
TEST_P(AiksTest, SolidStrokesRenderCorrectly) {
14321361
// Compare with https://fiddle.skia.org/c/027392122bec8ac2b5d5de00a4b9bbe2
1433-
bool first_frame = true;
14341362
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
1435-
if (first_frame) {
1436-
first_frame = false;
1437-
ImGui::SetNextWindowSize({480, 100});
1438-
ImGui::SetNextWindowPos({100, 550});
1439-
}
1440-
14411363
static Color color = Color::Black().WithAlpha(0.5);
14421364
static float scale = 3;
14431365
static bool add_circle_clip = true;
14441366

1445-
ImGui::Begin("Controls");
1367+
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
14461368
ImGui::ColorEdit4("Color", reinterpret_cast<float*>(&color));
14471369
ImGui::SliderFloat("Scale", &scale, 0, 6);
14481370
ImGui::Checkbox("Circle clip", &add_circle_clip);
@@ -1500,14 +1422,7 @@ TEST_P(AiksTest, SolidStrokesRenderCorrectly) {
15001422

15011423
TEST_P(AiksTest, GradientStrokesRenderCorrectly) {
15021424
// Compare with https://fiddle.skia.org/c/027392122bec8ac2b5d5de00a4b9bbe2
1503-
bool first_frame = true;
15041425
auto callback = [&](AiksContext& renderer, RenderTarget& render_target) {
1505-
if (first_frame) {
1506-
first_frame = false;
1507-
ImGui::SetNextWindowSize({480, 100});
1508-
ImGui::SetNextWindowPos({100, 550});
1509-
}
1510-
15111426
static float scale = 3;
15121427
static bool add_circle_clip = true;
15131428
const char* tile_mode_names[] = {"Clamp", "Repeat", "Mirror", "Decal"};
@@ -1517,7 +1432,7 @@ TEST_P(AiksTest, GradientStrokesRenderCorrectly) {
15171432
static int selected_tile_mode = 0;
15181433
static float alpha = 1;
15191434

1520-
ImGui::Begin("Controls");
1435+
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
15211436
ImGui::SliderFloat("Scale", &scale, 0, 6);
15221437
ImGui::Checkbox("Circle clip", &add_circle_clip);
15231438
ImGui::SliderFloat("Alpha", &alpha, 0, 1);

impeller/display_list/display_list_unittests.cc

+1-39
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,7 @@ TEST_P(DisplayListTest, CanDrawCapsAndJoins) {
9797
}
9898

9999
TEST_P(DisplayListTest, CanDrawArc) {
100-
bool first_frame = true;
101100
auto callback = [&]() {
102-
if (first_frame) {
103-
first_frame = false;
104-
ImGui::SetNextWindowSize({400, 100});
105-
ImGui::SetNextWindowPos({300, 550});
106-
}
107-
108101
static float start_angle = 45;
109102
static float sweep_angle = 270;
110103
static bool use_center = true;
@@ -283,17 +276,10 @@ TEST_P(DisplayListTest, CanDrawWithColorFilterImageFilter) {
283276
TEST_P(DisplayListTest, CanDrawWithImageBlurFilter) {
284277
auto texture = CreateTextureForFixture("embarcadero.jpg");
285278

286-
bool first_frame = true;
287279
auto callback = [&]() {
288-
if (first_frame) {
289-
first_frame = false;
290-
ImGui::SetNextWindowSize({400, 100});
291-
ImGui::SetNextWindowPos({300, 550});
292-
}
293-
294280
static float sigma[] = {10, 10};
295281

296-
ImGui::Begin("Controls");
282+
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
297283
ImGui::SliderFloat2("Sigma", sigma, 0, 100);
298284
ImGui::End();
299285

@@ -361,14 +347,8 @@ TEST_P(DisplayListTest, CanClampTheResultingColorOfColorMatrixFilter) {
361347

362348
TEST_P(DisplayListTest, SaveLayerWithColorMatrixFiltersAndAlphaDrawCorrectly) {
363349
auto texture = CreateTextureForFixture("boston.jpg");
364-
bool first_frame = true;
365350
enum class Type { kUseAsImageFilter, kUseAsColorFilter, kDisableFilter };
366351
auto callback = [&]() {
367-
if (first_frame) {
368-
first_frame = false;
369-
ImGui::SetNextWindowPos({10, 10});
370-
}
371-
372352
static float alpha = 0.5;
373353
static int selected_type = 0;
374354
const char* names[] = {"Use as image filter", "Use as color filter",
@@ -426,14 +406,8 @@ TEST_P(DisplayListTest, SaveLayerWithColorMatrixFiltersAndAlphaDrawCorrectly) {
426406

427407
TEST_P(DisplayListTest, SaveLayerWithBlendFiltersAndAlphaDrawCorrectly) {
428408
auto texture = CreateTextureForFixture("boston.jpg");
429-
bool first_frame = true;
430409
enum class Type { kUseAsImageFilter, kUseAsColorFilter, kDisableFilter };
431410
auto callback = [&]() {
432-
if (first_frame) {
433-
first_frame = false;
434-
ImGui::SetNextWindowPos({10, 10});
435-
}
436-
437411
static float alpha = 0.5;
438412
static int selected_type = 0;
439413
const char* names[] = {"Use as image filter", "Use as color filter",
@@ -479,13 +453,7 @@ TEST_P(DisplayListTest, SaveLayerWithBlendFiltersAndAlphaDrawCorrectly) {
479453
TEST_P(DisplayListTest, CanDrawBackdropFilter) {
480454
auto texture = CreateTextureForFixture("embarcadero.jpg");
481455

482-
bool first_frame = true;
483456
auto callback = [&]() {
484-
if (first_frame) {
485-
first_frame = false;
486-
ImGui::SetNextWindowPos({10, 10});
487-
}
488-
489457
static float sigma[] = {10, 10};
490458
static float ctm_scale = 1;
491459
static bool use_bounds = true;
@@ -775,13 +743,7 @@ TEST_P(DisplayListTest, CanDrawZeroWidthLine) {
775743
TEST_P(DisplayListTest, CanDrawWithMatrixFilter) {
776744
auto boston = CreateTextureForFixture("boston.jpg");
777745

778-
bool first_frame = true;
779746
auto callback = [&]() {
780-
if (first_frame) {
781-
first_frame = false;
782-
ImGui::SetNextWindowPos({10, 10});
783-
}
784-
785747
static int selected_matrix_type = 0;
786748
const char* matrix_type_names[] = {"Matrix", "Local Matrix"};
787749

impeller/entity/entity_unittests.cc

+2-42
Original file line numberDiff line numberDiff line change
@@ -264,22 +264,14 @@ TEST_P(EntityTest, StrokeCapAndJoinTest) {
264264
const Point padding(300, 250);
265265
const Point margin(140, 180);
266266

267-
bool first_frame = true;
268267
auto callback = [&](ContentContext& context, RenderPass& pass) {
269-
if (first_frame) {
270-
first_frame = false;
271-
ImGui::SetNextWindowSize({300, 100});
272-
ImGui::SetNextWindowPos(
273-
{0 * padding.x + margin.x, 1.7f * padding.y + margin.y});
274-
}
275-
276268
// Slightly above sqrt(2) by default, so that right angles are just below
277269
// the limit and acute angles are over the limit (causing them to get
278270
// beveled).
279271
static Scalar miter_limit = 1.41421357;
280272
static Scalar width = 30;
281273

282-
ImGui::Begin("Controls");
274+
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
283275
{
284276
ImGui::SliderFloat("Miter limit", &miter_limit, 0, 30);
285277
ImGui::SliderFloat("Stroke width", &width, 0, 100);
@@ -741,14 +733,7 @@ TEST_P(EntityTest, BlendingModeOptions) {
741733
};
742734
}
743735

744-
bool first_frame = true;
745736
auto callback = [&](ContentContext& context, RenderPass& pass) {
746-
if (first_frame) {
747-
first_frame = false;
748-
ImGui::SetNextWindowSize({350, 200});
749-
ImGui::SetNextWindowPos({200, 450});
750-
}
751-
752737
auto world_matrix = Matrix::MakeScale(GetContentScale());
753738
auto draw_rect = [&context, &pass, &world_matrix](
754739
Rect rect, Color color, BlendMode blend_mode) -> bool {
@@ -792,7 +777,7 @@ TEST_P(EntityTest, BlendingModeOptions) {
792777
return pass.AddCommand(std::move(cmd));
793778
};
794779

795-
ImGui::Begin("Controls");
780+
ImGui::Begin("Controls", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
796781
static Color color1(1, 0, 0, 0.5), color2(0, 1, 0, 0.5);
797782
ImGui::ColorEdit4("Color 1", reinterpret_cast<float*>(&color1));
798783
ImGui::ColorEdit4("Color 2", reinterpret_cast<float*>(&color2));
@@ -879,13 +864,7 @@ TEST_P(EntityTest, GaussianBlurFilter) {
879864
auto boston = CreateTextureForFixture("boston.jpg");
880865
ASSERT_TRUE(boston);
881866

882-
bool first_frame = true;
883867
auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
884-
if (first_frame) {
885-
first_frame = false;
886-
ImGui::SetNextWindowPos({10, 10});
887-
}
888-
889868
const char* input_type_names[] = {"Texture", "Solid Color"};
890869
const char* blur_type_names[] = {"Image blur", "Mask blur"};
891870
const char* pass_variation_names[] = {"Two pass", "Directional"};
@@ -1035,13 +1014,7 @@ TEST_P(EntityTest, MorphologyFilter) {
10351014
auto boston = CreateTextureForFixture("boston.jpg");
10361015
ASSERT_TRUE(boston);
10371016

1038-
bool first_frame = true;
10391017
auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
1040-
if (first_frame) {
1041-
first_frame = false;
1042-
ImGui::SetNextWindowPos({10, 10});
1043-
}
1044-
10451018
const char* morphology_type_names[] = {"Dilate", "Erode"};
10461019
const FilterContents::MorphType morphology_types[] = {
10471020
FilterContents::MorphType::kDilate, FilterContents::MorphType::kErode};
@@ -1563,13 +1536,7 @@ TEST_P(EntityTest, ClipContentsShouldRenderIsCorrect) {
15631536
}
15641537

15651538
TEST_P(EntityTest, RRectShadowTest) {
1566-
bool first_frame = true;
15671539
auto callback = [&](ContentContext& context, RenderPass& pass) {
1568-
if (first_frame) {
1569-
first_frame = false;
1570-
ImGui::SetNextWindowPos({10, 10});
1571-
}
1572-
15731540
static Color color = Color::Red();
15741541
static float corner_radius = 100;
15751542
static float blur_radius = 100;
@@ -1651,14 +1618,7 @@ TEST_P(EntityTest, ColorMatrixFilterEditable) {
16511618
auto bay_bridge = CreateTextureForFixture("bay_bridge.jpg");
16521619
ASSERT_TRUE(bay_bridge);
16531620

1654-
bool first_frame = true;
16551621
auto callback = [&](ContentContext& context, RenderPass& pass) -> bool {
1656-
// If this is the first frame, set the ImGui's initial size and postion.
1657-
if (first_frame) {
1658-
first_frame = false;
1659-
ImGui::SetNextWindowPos({10, 10});
1660-
}
1661-
16621622
// UI state.
16631623
static FilterContents::ColorMatrix color_matrix = {
16641624
1, 0, 0, 0, 0, //

0 commit comments

Comments
 (0)