@@ -914,6 +914,127 @@ void RegisterTests_Widgets(ImGuiTestEngine* e)
914
914
status.Clear ();
915
915
};
916
916
917
+ #if IMGUI_VERSION_NUM >= 19165
918
+ // ## Test the IsItemDeactivatedXXX() functions while interrupted (#5184, #5904, #6766, #8303, #8004?)
919
+ t = IM_REGISTER_TEST (e, " widgets" , " widgets_status_deactivate_interrupted" );
920
+ t->GuiFunc = [](ImGuiTestContext* ctx)
921
+ {
922
+ ImGuiTestGenericVars& vars = ctx->GenericVars ;
923
+ ImGui::Begin (" Test Window" , NULL , ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize);
924
+
925
+ ImGui::SliderInt (" Step" , &vars.Step , 0 , 2 );
926
+
927
+ ImGui::ButtonEx (" Right click (1)" , ImVec2 (0 , 0 ), ImGuiButtonFlags_MouseButtonRight);
928
+ ImGui::Text (" F1 to ClearActiveID()" );
929
+ ImGui::Text (" F2 to SetWindowFocus(NULL)" );
930
+ ImGui::Text (" F3 to Open Modal" );
931
+ if (ImGui::Shortcut (ImGuiKey_F1, ImGuiInputFlags_RouteGlobal))
932
+ ImGui::ClearActiveID ();
933
+ if (ImGui::Shortcut (ImGuiKey_F2, ImGuiInputFlags_RouteGlobal))
934
+ ImGui::SetWindowFocus (NULL );
935
+ if (ImGui::Shortcut (ImGuiKey_F3, ImGuiInputFlags_RouteGlobal))
936
+ ImGui::OpenPopup (" Modal 1" );
937
+ if (ImGui::BeginPopupModal (" Modal 1" ))
938
+ {
939
+ ImGui::Text (" Interrupted!" );
940
+ if (ImGui::Shortcut (ImGuiKey_Escape))
941
+ ImGui::CloseCurrentPopup ();
942
+ ImGui::EndPopup ();
943
+ }
944
+
945
+ bool ret = false ;
946
+ // if (ImGui::GetActiveID() != ctx->GetID("//Test Window/Field"))
947
+ // vars.Str1[0] = 0;
948
+
949
+ if (vars.Step == 0 )
950
+ ret = ImGui::InputText (" Field" , vars.Str1 , IM_ARRAYSIZE (vars.Str1 ));
951
+ else if (vars.Step == 1 )
952
+ ImGui::InputTextMultiline (" Field" , vars.Str1 , IM_ARRAYSIZE (vars.Str1 ));
953
+ else if (vars.Step == 2 )
954
+ ret = ImGui::SliderFloat3 (" Slider3" , &vars.Color1 .x , 0 .0f , 1 .0f );
955
+ vars.Status .QueryInc (ret);
956
+
957
+ bool is_item_activated = ImGui::IsItemActivated ();
958
+ if (is_item_activated)
959
+ vars.Str1 [0 ] = 0 ;
960
+
961
+ if (is_item_activated) IMGUI_DEBUG_LOG (" IsItemActivated()\n " );
962
+ bool is_item_deactivated = ImGui::IsItemDeactivated ();
963
+ if (is_item_deactivated) IMGUI_DEBUG_LOG (" IsItemDeactivated(): '%s'\n " , vars.Str1 );
964
+ bool is_item_deactivated_after_edit = ImGui::IsItemDeactivatedAfterEdit ();
965
+ if (is_item_deactivated_after_edit) IMGUI_DEBUG_LOG (" IsItemDeactivatedAfterEdit(): '%s'\n " , vars.Str1 );
966
+
967
+ ImGui::ButtonEx (" Right click (2)" , ImVec2 (0 , 0 ), ImGuiButtonFlags_MouseButtonRight);
968
+ ImGui::Text (" F5 to ClearActiveID()" );
969
+ ImGui::Text (" F6 to SetWindowFocus(NULL)" );
970
+ ImGui::Text (" F7 to Open Modal" );
971
+ if (ImGui::Shortcut (ImGuiKey_F5, ImGuiInputFlags_RouteGlobal))
972
+ ImGui::ClearActiveID ();
973
+ if (ImGui::Shortcut (ImGuiKey_F6, ImGuiInputFlags_RouteGlobal))
974
+ ImGui::SetWindowFocus (NULL );
975
+ if (ImGui::Shortcut (ImGuiKey_F7, ImGuiInputFlags_RouteGlobal))
976
+ ImGui::OpenPopup (" Modal 2" );
977
+ if (ImGui::BeginPopupModal (" Modal 2" ))
978
+ {
979
+ ImGui::Text (" Interrupted!" );
980
+ if (ImGui::Shortcut (ImGuiKey_Escape))
981
+ ImGui::CloseCurrentPopup ();
982
+ ImGui::EndPopup ();
983
+ }
984
+
985
+ ImGui::End ();
986
+ };
987
+ t->TestFunc = [](ImGuiTestContext* ctx)
988
+ {
989
+ // Accumulate return values over several frames/action into each bool
990
+ ImGuiTestGenericVars& vars = ctx->GenericVars ;
991
+ ImGuiTestGenericItemStatus& status = vars.Status ;
992
+ ImGuiContext& g = *GImGui;
993
+
994
+ ctx->SetRef (" Test Window" );
995
+ for (int step = 0 ; step < 3 ; step++)
996
+ {
997
+ vars.Step = step;
998
+ const int substeps_count = (step == 2 ) ? 10 : 8 ;
999
+ for (int substep = 0 ; substep < substeps_count; substep++)
1000
+ {
1001
+ ctx->LogDebug (" Step %d,%d" , vars.Step , substep);
1002
+ vars.Str1 [0 ] = 0 ;
1003
+ vars.Color1 = ImVec4 ();
1004
+ ctx->Yield ();
1005
+
1006
+ if (step == 2 )
1007
+ ctx->ItemInput (" Slider3/$$1" );
1008
+ else
1009
+ ctx->ItemInput (" Field" );
1010
+ ctx->KeyChars (" 0.5" );
1011
+ status.Clear ();
1012
+ if ((substep / 2 ) == 0 )
1013
+ ctx->ItemClick ((substep & 1 ) ? " Right click (2)" : " Right click (1)" , ImGuiMouseButton_Right);
1014
+ else if ((substep / 2 ) == 1 )
1015
+ ctx->KeyPress ((substep & 1 ) ? ImGuiKey_F5 : ImGuiKey_F1); // ClearActiveID() before/after active id
1016
+ else if ((substep / 2 ) == 2 )
1017
+ ctx->KeyPress ((substep & 1 ) ? ImGuiKey_F6 : ImGuiKey_F2); // SetWindowFocus(NULL) before/after active id
1018
+ else if ((substep / 2 ) == 3 )
1019
+ ctx->KeyPress ((substep & 1 ) ? ImGuiKey_F7 : ImGuiKey_F3); // OpenModal before/after active id
1020
+ else if ((substep / 2 ) == 4 )
1021
+ ctx->KeyPress ((substep & 1 ) ? (ImGuiMod_Shift | ImGuiKey_Tab) : (ImGuiKey_Tab)); // Go to next/prev field
1022
+ IM_CHECK (status.Deactivated == 1 && status.DeactivatedAfterEdit == 1 );
1023
+ if ((substep / 2 ) == 4 )
1024
+ IM_CHECK_NE (g.ActiveId , 0u ); // Tabbed
1025
+ else
1026
+ IM_CHECK_EQ (g.ActiveId , 0u ); // Interrupted
1027
+ if (step == 2 )
1028
+ IM_CHECK_EQ (vars.Color1 .y , 0 .5f ); // SliderFloat3
1029
+ else
1030
+ IM_CHECK_STR_EQ (vars.Str1 , " 0.5" ); // InputText/InputTextMultiline
1031
+ if (substep == 6 || substep == 7 )
1032
+ ctx->KeyPress (ImGuiKey_Escape); // Close modal
1033
+ }
1034
+ }
1035
+ };
1036
+ #endif
1037
+
917
1038
// ## Test the IsItemDeactivatedXXX() functions (e.g. #2550, #1875)
918
1039
t = IM_REGISTER_TEST (e, " widgets" , " widgets_status_multicomponent" );
919
1040
t->GuiFunc = [](ImGuiTestContext* ctx)
0 commit comments