mirror of
https://github.com/Drezil/imgui.git
synced 2025-04-12 06:04:01 +00:00
Menus: Fix appending to main menubar (#3068).
This commit is contained in:
parent
16a9488c13
commit
e8568f3ec9
@ -6150,18 +6150,23 @@ bool ImGui::BeginMainMenuBar()
|
|||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
ImGuiViewportP* viewport = g.Viewports[0];
|
ImGuiViewportP* viewport = g.Viewports[0];
|
||||||
|
ImGuiWindow* menu_bar_window = FindWindowByName("##MainMenuBar");
|
||||||
|
|
||||||
// For the main menu bar, which cannot be moved, we honor g.Style.DisplaySafeAreaPadding to ensure text can be visible on a TV set.
|
// For the main menu bar, which cannot be moved, we honor g.Style.DisplaySafeAreaPadding to ensure text can be visible on a TV set.
|
||||||
g.NextWindowData.MenuBarOffsetMinVal = ImVec2(g.Style.DisplaySafeAreaPadding.x, ImMax(g.Style.DisplaySafeAreaPadding.y - g.Style.FramePadding.y, 0.0f));
|
g.NextWindowData.MenuBarOffsetMinVal = ImVec2(g.Style.DisplaySafeAreaPadding.x, ImMax(g.Style.DisplaySafeAreaPadding.y - g.Style.FramePadding.y, 0.0f));
|
||||||
|
|
||||||
// Get our rectangle in the work area, and report the size we need for next frame.
|
// Get our rectangle at the top of the work area
|
||||||
// We don't attempt to calculate our height ahead, as it depends on the per-viewport font size. However menu-bar will affect the minimum window size so we'll get the right height.
|
if (menu_bar_window == NULL || menu_bar_window->BeginCount == 0)
|
||||||
ImVec2 menu_bar_pos = viewport->Pos + viewport->CurrWorkOffsetMin;
|
{
|
||||||
ImVec2 menu_bar_size = ImVec2(viewport->Size.x - viewport->CurrWorkOffsetMin.x + viewport->CurrWorkOffsetMax.x, 1.0f);
|
// Set window position
|
||||||
|
// We don't attempt to calculate our height ahead, as it depends on the per-viewport font size. However menu-bar will affect the minimum window size so we'll get the right height.
|
||||||
|
ImVec2 menu_bar_pos = viewport->Pos + viewport->CurrWorkOffsetMin;
|
||||||
|
ImVec2 menu_bar_size = ImVec2(viewport->Size.x - viewport->CurrWorkOffsetMin.x + viewport->CurrWorkOffsetMax.x, 1.0f);
|
||||||
|
SetNextWindowPos(menu_bar_pos);
|
||||||
|
SetNextWindowSize(menu_bar_size);
|
||||||
|
}
|
||||||
|
|
||||||
// Create window
|
// Create window
|
||||||
SetNextWindowPos(menu_bar_pos);
|
|
||||||
SetNextWindowSize(menu_bar_size);
|
|
||||||
SetNextWindowViewport(viewport->ID); // Enforce viewport so we don't create our own viewport when ImGuiConfigFlags_ViewportsNoMerge is set.
|
SetNextWindowViewport(viewport->ID); // Enforce viewport so we don't create our own viewport when ImGuiConfigFlags_ViewportsNoMerge is set.
|
||||||
PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
||||||
PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0, 0)); // Lift normal size constraint, however the presence of a menu-bar will give us the minimum height we want.
|
PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0, 0)); // Lift normal size constraint, however the presence of a menu-bar will give us the minimum height we want.
|
||||||
@ -6169,8 +6174,10 @@ bool ImGui::BeginMainMenuBar()
|
|||||||
bool is_open = Begin("##MainMenuBar", NULL, window_flags) && BeginMenuBar();
|
bool is_open = Begin("##MainMenuBar", NULL, window_flags) && BeginMenuBar();
|
||||||
PopStyleVar(2);
|
PopStyleVar(2);
|
||||||
|
|
||||||
// Feed back into work area using actual window size
|
// Report our size into work area (for next frame) using actual window size
|
||||||
viewport->CurrWorkOffsetMin.y += GetCurrentWindow()->Size.y;
|
menu_bar_window = GetCurrentWindow();
|
||||||
|
if (menu_bar_window->BeginCount == 1)
|
||||||
|
viewport->CurrWorkOffsetMin.y += menu_bar_window->Size.y;
|
||||||
|
|
||||||
g.NextWindowData.MenuBarOffsetMinVal = ImVec2(0.0f, 0.0f);
|
g.NextWindowData.MenuBarOffsetMinVal = ImVec2(0.0f, 0.0f);
|
||||||
if (!is_open)
|
if (!is_open)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user