Browse Source

Tables, Menus: Fixed tables or child windows submitted inside BeginMainMenuBar() being unable to save their settings. (#8356)

Amend error handling (fa178f4) to avoid us setting ImGuiWindowFlags_NoSavedSettings on the wrong window.
ocornut 5 months ago
parent
commit
ae6cfd32a0
2 changed files with 17 additions and 4 deletions
  1. 2 0
      docs/CHANGELOG.txt
  2. 15 4
      imgui_widgets.cpp

+ 2 - 0
docs/CHANGELOG.txt

@@ -75,6 +75,8 @@ Other changes:
 - Tables, Menus: Fixed using BeginTable() in menu layer (any menu bar). (#8355)
 - Tables, Menus: Fixed using BeginTable() in menu layer (any menu bar). (#8355)
   It previously overrode the current layer back to main layer, which caused an issue
   It previously overrode the current layer back to main layer, which caused an issue
   with MainMenuBar attempted to release focus when leaving the menu layer.
   with MainMenuBar attempted to release focus when leaving the menu layer.
+- Tables, Menus: Fixed tables or child windows submitted inside BeginMainMenuBar()
+  being unable to save their settings, as the main menu bar uses _NoSavedSettings. (#8356)
 - ColorEdit, ColorPicker: Fixed alpha preview broken in 1.91.7. (#8336, #8241). [@PathogenDavid]
 - ColorEdit, ColorPicker: Fixed alpha preview broken in 1.91.7. (#8336, #8241). [@PathogenDavid]
 - Tabs, Style: reworked selected overline rendering to better accommodate
 - Tabs, Style: reworked selected overline rendering to better accommodate
   for rounded tabs. Reduced default thickness (style.TabBarOverlineSize),
   for rounded tabs. Reduced default thickness (style.TabBarOverlineSize),

+ 15 - 4
imgui_widgets.cpp

@@ -8755,18 +8755,29 @@ bool ImGui::BeginMainMenuBar()
     float height = GetFrameHeight();
     float height = GetFrameHeight();
     bool is_open = BeginViewportSideBar("##MainMenuBar", viewport, ImGuiDir_Up, height, window_flags);
     bool is_open = BeginViewportSideBar("##MainMenuBar", viewport, ImGuiDir_Up, height, window_flags);
     g.NextWindowData.MenuBarOffsetMinVal = ImVec2(0.0f, 0.0f);
     g.NextWindowData.MenuBarOffsetMinVal = ImVec2(0.0f, 0.0f);
-
-    if (is_open)
-        BeginMenuBar();
-    else
+    if (!is_open)
+    {
         End();
         End();
+        return false;
+    }
+
+    // Temporarily disable _NoSavedSettings, in the off-chance that tables or child windows submitted within the menu-bar may want to use settings. (#8356)
+    g.CurrentWindow->Flags &= ~ImGuiWindowFlags_NoSavedSettings;
+    BeginMenuBar();
     return is_open;
     return is_open;
 }
 }
 
 
 void ImGui::EndMainMenuBar()
 void ImGui::EndMainMenuBar()
 {
 {
     ImGuiContext& g = *GImGui;
     ImGuiContext& g = *GImGui;
+    if (!g.CurrentWindow->DC.MenuBarAppending)
+    {
+        IM_ASSERT_USER_ERROR(0, "Calling EndMainMenuBar() not from a menu-bar!"); // Not technically testing that it is the main menu bar
+        return;
+    }
+
     EndMenuBar();
     EndMenuBar();
+    g.CurrentWindow->Flags |= ImGuiWindowFlags_NoSavedSettings; // Restore _NoSavedSettings (#8356)
 
 
     // When the user has left the menu layer (typically: closed menus through activation of an item), we restore focus to the previous window
     // When the user has left the menu layer (typically: closed menus through activation of an item), we restore focus to the previous window
     // FIXME: With this strategy we won't be able to restore a NULL focus.
     // FIXME: With this strategy we won't be able to restore a NULL focus.