@@ -4172,6 +4172,67 @@ void RegisterTests_Widgets(ImGuiTestEngine* e)
4172
4172
IM_CHECK_EQ (g.NavId , ctx->GetID (" ##Menu_01/Item 3" ));
4173
4173
};
4174
4174
4175
+ // ## Test main menubar automatically releasing focus + bug overriding layer (#8355)
4176
+ t = IM_REGISTER_TEST (e, " widgets" , " widgets_menu_mainmenubar_release_focus" );
4177
+ t->GuiFunc = [](ImGuiTestContext* ctx)
4178
+ {
4179
+ auto & vars = ctx->GenericVars ;
4180
+ ImGui::Begin (" Test Window" , NULL , ImGuiWindowFlags_NoSavedSettings);
4181
+ ImGui::Button (" OK" );
4182
+ ImGui::End ();
4183
+ if (ImGui::BeginMainMenuBar ())
4184
+ {
4185
+ if (ImGui::BeginMenu (" File" ))
4186
+ {
4187
+ ImGui::MenuItem (" Hedhehog" );
4188
+ ImGui::EndMenu ();
4189
+ }
4190
+ ImGui::Button (" BUTTON" );
4191
+ ImGui::SetNextItemWidth (100 );
4192
+ ImGui::InputText (" InputText1" , vars.Str1 , IM_ARRAYSIZE (vars.Str1 ));
4193
+ if (ImGui::BeginTable (" Table" , 1 ))
4194
+ {
4195
+ ImGui::TableNextColumn ();
4196
+ ImGui::SetNextItemWidth (100 );
4197
+ ImGui::InputText (" InputText2" , vars.Str1 , IM_ARRAYSIZE (vars.Str1 ));
4198
+ ImGui::EndTable ();
4199
+ }
4200
+ ImGui::EndMainMenuBar ();
4201
+ }
4202
+ };
4203
+ t->TestFunc = [](ImGuiTestContext* ctx)
4204
+ {
4205
+ ImGuiContext& g = *GImGui;
4206
+ ImGuiWindow* test_window = ctx->GetWindowByRef (" /Test Window" );
4207
+ ctx->ItemClick (" /Test Window/OK" );
4208
+ IM_CHECK_EQ (g.NavWindow , test_window);
4209
+
4210
+ // It's not well specced, but MenuLayer->MainLayer is currently effectively done on FocusWindow(),
4211
+ // which closing a menu does, but not e.g. clicking a button. That's why we press Escape.
4212
+ // It may be the saner behavior that we limit this to closing menu, so maybe current behavior i the best.
4213
+ ctx->ItemClick (" /##MainMenuBar/##menubar/BUTTON" ); // FIXME-TESTS: It's pretty shitty we don't have a clear standard to use that yet (soon)
4214
+ IM_CHECK_EQ (g.NavLayer , ImGuiNavLayer_Menu);
4215
+ ctx->KeyPress (ImGuiKey_Escape); // Leave menu layer
4216
+ IM_CHECK_EQ (g.NavLayer , ImGuiNavLayer_Main);
4217
+ IM_CHECK_EQ (g.NavWindow , test_window);
4218
+
4219
+ ctx->ItemClick (" /##MainMenuBar/##menubar/InputText1" );
4220
+ IM_CHECK_EQ (g.NavLayer , ImGuiNavLayer_Menu);
4221
+ ctx->KeyPress (ImGuiKey_Escape); // Deactivate InputText
4222
+ ctx->KeyPress (ImGuiKey_Escape); // Leave menu layer
4223
+ ctx->Yield ();
4224
+ IM_CHECK_EQ (g.NavLayer , ImGuiNavLayer_Main);
4225
+ IM_CHECK_EQ (g.NavWindow , test_window);
4226
+
4227
+ ctx->ItemClick (" /##MainMenuBar/##menubar/Table/InputText2" );
4228
+ IM_CHECK_EQ (g.NavLayer , ImGuiNavLayer_Menu);
4229
+ ctx->KeyPress (ImGuiKey_Escape); // Deactivate InputText
4230
+ ctx->KeyPress (ImGuiKey_Escape); // Leave menu layer
4231
+ ctx->Yield ();
4232
+ IM_CHECK_EQ (g.NavLayer , ImGuiNavLayer_Main);
4233
+ IM_CHECK_EQ (g.NavWindow , test_window);
4234
+ };
4235
+
4175
4236
#ifdef IMGUI_HAS_MULTISELECT
4176
4237
4177
4238
static const char * ExampleNames[] =
0 commit comments