mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 20:07:01 +00: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:
parent
1e41bad90f
commit
6a0b2627ad
@ -49,6 +49,8 @@ Other Changes:
|
|||||||
|
|
||||||
- Settings: Fixed saving an empty .ini file if CreateContext/DestroyContext are called without a single call to NewFrame(). (#1741)
|
- Settings: Fixed saving an empty .ini file if CreateContext/DestroyContext are called without a single call to NewFrame(). (#1741)
|
||||||
- Window: Fixed default proportional item width lagging by one frame on resize.
|
- Window: Fixed default proportional item width lagging by one frame on resize.
|
||||||
|
- MenuBar: Made BeginMainMenuBar() honor style.DisplaySafeAreaPadding so the text can be made visible on TV settings that don't display all pixels. (#1439) [@dougbinks]
|
||||||
|
- Style: Changed default style.DisplaySafeAreaPadding values from (4,4) to (3,3) so it is smaller than FramePadding and has no effect on main menu bar on a computer. (#1439)
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
|
|
||||||
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.)
|
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;
|
window->WindowPadding = style.WindowPadding;
|
||||||
if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & (ImGuiWindowFlags_AlwaysUseWindowPadding | ImGuiWindowFlags_Popup)) && window->WindowBorderSize == 0.0f)
|
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->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
|
// 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
|
// 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
|
// Menu bar
|
||||||
if (flags & ImGuiWindowFlags_MenuBar)
|
if (flags & ImGuiWindowFlags_MenuBar)
|
||||||
{
|
{
|
||||||
if (flags & ImGuiWindowFlags_MainMenuBar)
|
|
||||||
window->DC.MenuBarOffset.y = g.Style.DisplaySafeAreaPadding.y;
|
|
||||||
ImRect menu_bar_rect = window->MenuBarRect();
|
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.
|
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);
|
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.NavLayerActiveMask = window->DC.NavLayerActiveMaskNext;
|
||||||
window->DC.NavLayerActiveMaskNext = 0x00;
|
window->DC.NavLayerActiveMaskNext = 0x00;
|
||||||
window->DC.MenuBarAppending = false;
|
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.LogLinePosY = window->DC.CursorPos.y - 9999.0f;
|
||||||
window->DC.ChildWindows.resize(0);
|
window->DC.ChildWindows.resize(0);
|
||||||
window->DC.LayoutType = ImGuiLayoutType_Vertical;
|
window->DC.LayoutType = ImGuiLayoutType_Vertical;
|
||||||
@ -11142,15 +11139,19 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool* p_selected,
|
|||||||
return false;
|
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()
|
bool ImGui::BeginMainMenuBar()
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
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));
|
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_WindowRounding, 0.0f);
|
||||||
PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(0,0));
|
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);
|
ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_MenuBar;
|
||||||
if (!haveWindow || !BeginMenuBar())
|
bool is_open = Begin("##MainMenuBar", NULL, window_flags) && BeginMenuBar();
|
||||||
|
g.NextWindowData.MenuBarOffsetMinVal = ImVec2(0.0f, 0.0f);
|
||||||
|
if (!is_open)
|
||||||
{
|
{
|
||||||
End();
|
End();
|
||||||
PopStyleVar(2);
|
PopStyleVar(2);
|
||||||
@ -11184,14 +11185,14 @@ bool ImGui::BeginMenuBar()
|
|||||||
BeginGroup(); // Save position
|
BeginGroup(); // Save position
|
||||||
PushID("##menubar");
|
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 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 don't tend to display over the lower-right rounded area, which looks particularly glitchy.
|
// 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 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));
|
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);
|
clip_rect.ClipWith(window->WindowRectClipped);
|
||||||
PushClipRect(clip_rect.Min, clip_rect.Max, false);
|
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.LayoutType = ImGuiLayoutType_Horizontal;
|
||||||
window->DC.NavLayerCurrent++;
|
window->DC.NavLayerCurrent++;
|
||||||
window->DC.NavLayerCurrentMask <<= 1;
|
window->DC.NavLayerCurrentMask <<= 1;
|
||||||
@ -11231,7 +11232,7 @@ void ImGui::EndMenuBar()
|
|||||||
IM_ASSERT(window->DC.MenuBarAppending);
|
IM_ASSERT(window->DC.MenuBarAppending);
|
||||||
PopClipRect();
|
PopClipRect();
|
||||||
PopID();
|
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;
|
window->DC.GroupStack.back().AdvanceCursor = false;
|
||||||
EndGroup();
|
EndGroup();
|
||||||
window->DC.LayoutType = ImGuiLayoutType_Vertical;
|
window->DC.LayoutType = ImGuiLayoutType_Vertical;
|
||||||
|
5
imgui.h
5
imgui.h
@ -581,8 +581,7 @@ enum ImGuiWindowFlags_
|
|||||||
ImGuiWindowFlags_Tooltip = 1 << 25, // Don't use! For internal use by BeginTooltip()
|
ImGuiWindowFlags_Tooltip = 1 << 25, // Don't use! For internal use by BeginTooltip()
|
||||||
ImGuiWindowFlags_Popup = 1 << 26, // Don't use! For internal use by BeginPopup()
|
ImGuiWindowFlags_Popup = 1 << 26, // Don't use! For internal use by BeginPopup()
|
||||||
ImGuiWindowFlags_Modal = 1 << 27, // Don't use! For internal use by BeginPopupModal()
|
ImGuiWindowFlags_Modal = 1 << 27, // Don't use! For internal use by BeginPopupModal()
|
||||||
ImGuiWindowFlags_ChildMenu = 1 << 28, // Don't use! For internal use by BeginMenu()
|
ImGuiWindowFlags_ChildMenu = 1 << 28 // Don't use! For internal use by BeginMenu()
|
||||||
ImGuiWindowFlags_MainMenuBar = 1 << 29 // Don't use! For internal use by BeginMainMenuBar()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Flags for ImGui::InputText()
|
// Flags for ImGui::InputText()
|
||||||
@ -981,7 +980,7 @@ struct ImGuiStyle
|
|||||||
float GrabRounding; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
|
float GrabRounding; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
|
||||||
ImVec2 ButtonTextAlign; // Alignment of button text when button is larger than text. Defaults to (0.5f,0.5f) for horizontally+vertically centered.
|
ImVec2 ButtonTextAlign; // Alignment of button text when button is larger than text. Defaults to (0.5f,0.5f) for horizontally+vertically centered.
|
||||||
ImVec2 DisplayWindowPadding; // Window positions are clamped to be visible within the display area by at least this amount. Only covers regular windows.
|
ImVec2 DisplayWindowPadding; // Window positions are clamped to be visible within the display area by at least this amount. Only covers regular windows.
|
||||||
ImVec2 DisplaySafeAreaPadding; // 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.
|
ImVec2 DisplaySafeAreaPadding; // If you cannot see the edges of your screen (e.g. on a TV) increase the safe area padding. Apply to popups/tooltips as well regular windows. NB: Prefer configuring your TV sets correctly!
|
||||||
float MouseCursorScale; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later.
|
float MouseCursorScale; // Scale software rendered mouse cursor (when io.MouseDrawCursor is enabled). May be removed later.
|
||||||
bool AntiAliasedLines; // Enable anti-aliasing on lines/borders. Disable if you are really tight on CPU/GPU.
|
bool AntiAliasedLines; // Enable anti-aliasing on lines/borders. Disable if you are really tight on CPU/GPU.
|
||||||
bool AntiAliasedFill; // Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.)
|
bool AntiAliasedFill; // Enable anti-aliasing on filled shapes (rounded rectangles, circles, etc.)
|
||||||
|
@ -2169,6 +2169,8 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
|||||||
ImGui::Text("Alignment");
|
ImGui::Text("Alignment");
|
||||||
ImGui::SliderFloat2("WindowTitleAlign", (float*)&style.WindowTitleAlign, 0.0f, 1.0f, "%.2f");
|
ImGui::SliderFloat2("WindowTitleAlign", (float*)&style.WindowTitleAlign, 0.0f, 1.0f, "%.2f");
|
||||||
ImGui::SliderFloat2("ButtonTextAlign", (float*)&style.ButtonTextAlign, 0.0f, 1.0f, "%.2f"); ImGui::SameLine(); ShowHelpMarker("Alignment applies when a button is larger than its text content.");
|
ImGui::SliderFloat2("ButtonTextAlign", (float*)&style.ButtonTextAlign, 0.0f, 1.0f, "%.2f"); ImGui::SameLine(); ShowHelpMarker("Alignment applies when a button is larger than its text content.");
|
||||||
|
ImGui::Text("Safe Area Padding"); ImGui::SameLine(); ShowHelpMarker("Adjust if you cannot see the edges of your screen (e.g. on a TV where scaling has not been configured).");
|
||||||
|
ImGui::SliderFloat2("DisplaySafeAreaPadding", (float*)&style.DisplaySafeAreaPadding, 0.0f, 30.0f, "%.0f");
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,6 +533,7 @@ struct ImGuiNextWindowData
|
|||||||
ImGuiSizeCallback SizeCallback;
|
ImGuiSizeCallback SizeCallback;
|
||||||
void* SizeCallbackUserData;
|
void* SizeCallbackUserData;
|
||||||
float BgAlphaVal;
|
float BgAlphaVal;
|
||||||
|
ImVec2 MenuBarOffsetMinVal; // This is not exposed publicly, so we don't clear it.
|
||||||
|
|
||||||
ImGuiNextWindowData()
|
ImGuiNextWindowData()
|
||||||
{
|
{
|
||||||
@ -544,6 +545,7 @@ struct ImGuiNextWindowData
|
|||||||
SizeCallback = NULL;
|
SizeCallback = NULL;
|
||||||
SizeCallbackUserData = NULL;
|
SizeCallbackUserData = NULL;
|
||||||
BgAlphaVal = FLT_MAX;
|
BgAlphaVal = FLT_MAX;
|
||||||
|
MenuBarOffsetMinVal = ImVec2(0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear()
|
void Clear()
|
||||||
@ -832,7 +834,7 @@ struct IMGUI_API ImGuiDrawContext
|
|||||||
int NavLayerActiveMask; // Which layer have been written to (result from previous frame)
|
int NavLayerActiveMask; // Which layer have been written to (result from previous frame)
|
||||||
int NavLayerActiveMaskNext; // Which layer have been written to (buffer for current frame)
|
int NavLayerActiveMaskNext; // Which layer have been written to (buffer for current frame)
|
||||||
bool MenuBarAppending; // FIXME: Remove this
|
bool MenuBarAppending; // FIXME: Remove this
|
||||||
ImVec2 MenuBarOffset;
|
ImVec2 MenuBarOffset; // MenuBarOffset.x is sort of equivalent of a per-layer CursorPos.x, saved/restored as we switch to the menu bar. The only situation when MenuBarOffset.y is > 0 if when (SafeAreaPadding.y > FramePadding.y), often used on TVs.
|
||||||
ImVector<ImGuiWindow*> ChildWindows;
|
ImVector<ImGuiWindow*> ChildWindows;
|
||||||
ImGuiStorage* StateStorage;
|
ImGuiStorage* StateStorage;
|
||||||
ImGuiLayoutType LayoutType;
|
ImGuiLayoutType LayoutType;
|
||||||
|
Loading…
Reference in New Issue
Block a user