@@ -4664,6 +4664,75 @@ void RegisterTests_Widgets(ImGuiTestEngine* e)
4664
4664
};
4665
4665
#endif
4666
4666
4667
+ #if IMGUI_VERSION_NUM >= 19071
4668
+ // ## Test box-selection + exercise Assets Browser a little.
4669
+ // This test is probably fragile because are are dealing with Assets Browser instead of duplicating it in our code.
4670
+ t = IM_REGISTER_TEST (e, " widgets" , " widgets_multiselect_boxselect" );
4671
+ t->TestFunc = [](ImGuiTestContext* ctx)
4672
+ {
4673
+ ImGuiContext& g = *GImGui;
4674
+ ctx->MenuCheck (" //Dear ImGui Demo/Examples/Assets Browser" );
4675
+ ctx->SetRef (" Example: Assets Browser" );
4676
+ ctx->WindowResize (" " , ImVec2 (750 , 600 )); // FIXME: Calculated for 15 item wide (15 * 32) + (15-1+2) * 10 + Parent/Child Padding + Scrollbar
4677
+ ctx->MenuClick (" File/Clear items" );
4678
+ ctx->MenuClick (" File/Add 10000 items" );
4679
+ ctx->MenuAction (ImGuiTestAction_Open, " Options" );
4680
+ ctx->ItemInputValue (" //$FOCUSED/Icon Size" , 32 .0f );
4681
+ ctx->ItemInputValue (" //$FOCUSED/Icon Spacing" , 10 );
4682
+ ctx->ItemInputValue (" //$FOCUSED/Icon Hit Spacing" , 4 );
4683
+
4684
+ ImGuiWindow* child_window = ctx->WindowInfo (" Assets" ).Window ;
4685
+ IM_CHECK (child_window != NULL );
4686
+ ctx->SetRef (child_window);
4687
+ ctx->ScrollToTop (" " );
4688
+ ImGuiMultiSelectState* ms_storage = ImGui::GetMultiSelectState (ctx->GetID (" " ));
4689
+ IM_CHECK (ms_storage != NULL );
4690
+ IM_CHECK_EQ (ms_storage->LastSelectionSize , 0 );
4691
+ // g.DebugLogFlags |= ImGuiDebugLogFlags_OutputToTestEngine;
4692
+ ctx->ItemClick (" $$7" );
4693
+ IM_CHECK_EQ (ms_storage->LastSelectionSize , 1 );
4694
+ ctx->KeyPress (ImGuiKey_Escape);
4695
+ IM_CHECK_EQ (ms_storage->LastSelectionSize , 0 );
4696
+
4697
+ // Box-select part of a row, then a rectangle
4698
+ ctx->ItemDragAndDrop (" $$0" , " $$5" );
4699
+ IM_CHECK_EQ (ms_storage->LastSelectionSize , 6 );
4700
+ ctx->ItemDragAndDrop (" $$20" , " $$105" );
4701
+ IM_CHECK_EQ (ms_storage->LastSelectionSize , 6 * 6 );
4702
+ ctx->KeyPress (ImGuiKey_Escape);
4703
+
4704
+ // Box-select from void
4705
+ ImGuiTestItemInfo item_1 = ctx->ItemInfo (" $$1" );
4706
+ ImGuiTestItemInfo item_2 = ctx->ItemInfo (" $$2" );
4707
+ ctx->MouseMoveToPos ((item_1.RectFull .GetCenter () + item_2.RectFull .GetCenter ()) * 0 .5f );
4708
+ IM_CHECK (ImGui::IsAnyItemHovered () == false );
4709
+ IM_CHECK_EQ (ms_storage->LastSelectionSize , 0 );
4710
+ ctx->MouseClick (0 );
4711
+ IM_CHECK_EQ (ms_storage->LastSelectionSize , 0 ); // Verify we are over void
4712
+ ctx->MouseDown (0 );
4713
+ ctx->MouseMove (" $$22" , ImGuiTestOpFlags_NoCheckHoveredId);
4714
+ ctx->MouseUp (0 );
4715
+ IM_CHECK_EQ (ms_storage->LastSelectionSize , 2 * 5 );
4716
+
4717
+ // Verify that first selected item was turned into NavId
4718
+ IM_CHECK_EQ (g.NavId , ctx->GetID (" $$2" ));
4719
+
4720
+ // Exercise box-select scroll (in a very basic way)
4721
+ IM_CHECK_EQ (child_window->Scroll .y , 0 .0f );
4722
+ ctx->ItemClick (" $$0" );
4723
+ ctx->MouseMove (" $$3" );
4724
+ ctx->MouseDown (0 );
4725
+ ctx->MouseMoveToPos (ImGui::GetMousePos () + ImVec2 (0 , 1000 ));
4726
+ ctx->SleepNoSkip (2 .0f , 0 .1f );
4727
+ ctx->MouseUp (0 );
4728
+ IM_CHECK_GT (child_window->Scroll .y , 0 .0f );
4729
+
4730
+ ctx->MenuUncheck (" //Dear ImGui Demo/Examples/Assets Browser" );
4731
+ };
4732
+ #endif
4733
+
4734
+ #endif // #ifdef IMGUI_HAS_MULTI_SELECT
4735
+
4667
4736
// ## Basic test for GetTypingSelectRequest()
4668
4737
// Technically this API doesn't require MultiSelect but it's easier for us to reuse that code.
4669
4738
t = IM_REGISTER_TEST (e, " widgets" , " widgets_typingselect" );
@@ -4765,8 +4834,6 @@ void RegisterTests_Widgets(ImGuiTestEngine* e)
4765
4834
IM_CHECK (vars.Selection0 .SelectionSize == 1 && vars.Selection0 .GetSelected (2 ));
4766
4835
};
4767
4836
4768
- #endif // #ifdef IMGUI_HAS_MULTI_SELECT
4769
-
4770
4837
// ## Test Selectable() with ImGuiSelectableFlags_SpanAllColumns inside Columns()
4771
4838
t = IM_REGISTER_TEST (e, " widgets" , " widgets_selectable_span_all_columns" );
4772
4839
t->GuiFunc = [](ImGuiTestContext* ctx)
0 commit comments