mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 03:58:47 +02:00
BeginMainMenuBar: Followup to 1e41bad9
. Removed public window flag. DisplaySafeAreaPadding defaults to (3,3) instead of (4.4). Comments, tab to spaces, Changelog. (#1439)
This commit is contained in:
27
imgui.cpp
27
imgui.cpp
@ -831,7 +831,7 @@ ImGuiStyle::ImGuiStyle()
|
||||
GrabRounding = 0.0f; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
|
||||
ButtonTextAlign = ImVec2(0.5f,0.5f);// Alignment of button text when button is larger than text.
|
||||
DisplayWindowPadding = ImVec2(22,22); // Window positions are clamped to be visible within the display area by at least this amount. Only covers regular windows.
|
||||
DisplaySafeAreaPadding = ImVec2(4,4); // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows.
|
||||
DisplaySafeAreaPadding = ImVec2(3,3); // If you cannot see the edge of your screen (e.g. on a TV) increase the safe area padding. Covers popups/tooltips as well regular windows.
|
||||
MouseCursorScale = 1.0f; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later.
|
||||
AntiAliasedLines = true; // Enable anti-aliasing on lines/borders. Disable if you are really short on CPU/GPU.
|
||||
AntiAliasedFill = true; // Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.)
|
||||
@ -5802,6 +5802,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
window->WindowPadding = style.WindowPadding;
|
||||
if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & (ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_Popup)) && window->WindowBorderSize == 0.0f)
|
||||
window->WindowPadding = ImVec2(0.0f, (flags & ImGuiWindowFlags_MenuBar) ? style.WindowPadding.y : 0.0f);
|
||||
window->DC.MenuBarOffset.x = ImMax(ImMax(window->WindowPadding.x, style.ItemSpacing.x), g.NextWindowData.MenuBarOffsetMinVal.x);
|
||||
window->DC.MenuBarOffset.y = g.NextWindowData.MenuBarOffsetMinVal.y;
|
||||
|
||||
// Collapse window by double-clicking on title bar
|
||||
// At this point we don't have a clipping rectangle setup yet, so we can use the title bar area for hit detection and drawing
|
||||
@ -6017,8 +6019,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
// Menu bar
|
||||
if (flags & ImGuiWindowFlags_MenuBar)
|
||||
{
|
||||
if (flags & ImGuiWindowFlags_MainMenuBar)
|
||||
window->DC.MenuBarOffset.y = g.Style.DisplaySafeAreaPadding.y;
|
||||
ImRect menu_bar_rect = window->MenuBarRect();
|
||||
menu_bar_rect.ClipWith(window->Rect()); // Soft clipping, in particular child window don't have minimum size covering the menu bar so this is useful for them.
|
||||
window->DrawList->AddRectFilled(menu_bar_rect.Min, menu_bar_rect.Max, GetColorU32(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, ImDrawCornerFlags_Top);
|
||||
@ -6097,9 +6097,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
window->DC.NavLayerActiveMask = window->DC.NavLayerActiveMaskNext;
|
||||
window->DC.NavLayerActiveMaskNext = 0x00;
|
||||
window->DC.MenuBarAppending = false;
|
||||
window->DC.MenuBarOffset = ImVec2( ImMax(window->WindowPadding.x, style.ItemSpacing.x), 0.0f );
|
||||
if (flags & ImGuiWindowFlags_MainMenuBar)
|
||||
window->DC.MenuBarOffset += g.Style.DisplaySafeAreaPadding;
|
||||
window->DC.LogLinePosY = window->DC.CursorPos.y - 9999.0f;
|
||||
window->DC.ChildWindows.resize(0);
|
||||
window->DC.LayoutType = ImGuiLayoutType_Vertical;
|
||||
@ -11142,15 +11139,19 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool* p_selected,
|
||||
return false;
|
||||
}
|
||||
|
||||
// For the main menu bar, which cannot be moved, we honor g.Style.DisplaySafeAreaPadding to ensure text can be visible on a TV set.
|
||||
bool ImGui::BeginMainMenuBar()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
g.NextWindowData.MenuBarOffsetMinVal = ImVec2(g.Style.DisplaySafeAreaPadding.x, ImMax(g.Style.DisplaySafeAreaPadding.y - g.Style.FramePadding.y, 0.0f));
|
||||
SetNextWindowPos(ImVec2(0.0f, 0.0f));
|
||||
SetNextWindowSize(ImVec2(g.IO.DisplaySize.x, g.Style.DisplaySafeAreaPadding.y + g.FontBaseSize + g.Style.FramePadding.y * 2.0f));
|
||||
SetNextWindowSize(ImVec2(g.IO.DisplaySize.x, g.NextWindowData.MenuBarOffsetMinVal.y + g.FontBaseSize + g.Style.FramePadding.y));
|
||||
PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
||||
PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0,0));
|
||||
bool haveWindow = Begin("##MainMenuBar", NULL, ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoScrollbar|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_MenuBar|ImGuiWindowFlags_MainMenuBar);
|
||||
if (!haveWindow || !BeginMenuBar())
|
||||
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar;
|
||||
bool is_open = Begin("##MainMenuBar", NULL, window_flags) && BeginMenuBar();
|
||||
g.NextWindowData.MenuBarOffsetMinVal = ImVec2(0.0f, 0.0f);
|
||||
if (!is_open)
|
||||
{
|
||||
End();
|
||||
PopStyleVar(2);
|
||||
@ -11184,14 +11185,14 @@ bool ImGui::BeginMenuBar()
|
||||
BeginGroup(); // Save position
|
||||
PushID("##menubar");
|
||||
|
||||
// We don't clip with regular window clipping rectangle as it is already set to the area below. However we clip with window full rect.
|
||||
// We remove 1 worth of rounding to Max.x to that text in long menus don't tend to display over the lower-right rounded area, which looks particularly glitchy.
|
||||
// We don't clip with current window clipping rectangle as it is already set to the area below. However we clip with window full rect.
|
||||
// We remove 1 worth of rounding to Max.x to that text in long menus and small windows don't tend to display over the lower-right rounded area, which looks particularly glitchy.
|
||||
ImRect bar_rect = window->MenuBarRect();
|
||||
ImRect clip_rect(ImFloor(bar_rect.Min.x + 0.5f), ImFloor(bar_rect.Min.y + window->WindowBorderSize + 0.5f), ImFloor(ImMax(bar_rect.Min.x, bar_rect.Max.x - window->WindowRounding) + 0.5f), ImFloor(bar_rect.Max.y + 0.5f));
|
||||
clip_rect.ClipWith(window->WindowRectClipped);
|
||||
PushClipRect(clip_rect.Min, clip_rect.Max, false);
|
||||
|
||||
window->DC.CursorPos = ImVec2(bar_rect.Min.x + window->DC.MenuBarOffset.x, bar_rect.Min.y + window->DC.MenuBarOffset.y);// + g.Style.FramePadding.y);
|
||||
window->DC.CursorPos = ImVec2(bar_rect.Min.x + window->DC.MenuBarOffset.x, bar_rect.Min.y + window->DC.MenuBarOffset.y);
|
||||
window->DC.LayoutType = ImGuiLayoutType_Horizontal;
|
||||
window->DC.NavLayerCurrent++;
|
||||
window->DC.NavLayerCurrentMask <<= 1;
|
||||
@ -11231,7 +11232,7 @@ void ImGui::EndMenuBar()
|
||||
IM_ASSERT(window->DC.MenuBarAppending);
|
||||
PopClipRect();
|
||||
PopID();
|
||||
window->DC.MenuBarOffset = ImVec2( window->DC.CursorPos.x - window->MenuBarRect().Min.x, 0.0f );
|
||||
window->DC.MenuBarOffset.x = window->DC.CursorPos.x - window->MenuBarRect().Min.x; // Save horizontal position so next append can reuse it. This is kinda equivalent to a per-layer CursorPos.
|
||||
window->DC.GroupStack.back().AdvanceCursor = false;
|
||||
EndGroup();
|
||||
window->DC.LayoutType = ImGuiLayoutType_Vertical;
|
||||
|
Reference in New Issue
Block a user