FIXME: Provided a rectangle perhaps e.g. a BeginMenuBarEx() could be used anywhere.. Currently the main responsibility of this function being to setup clip-rect + horizontal layout + menu navigation layer. Ideally we also want this to be responsible for claiming space out of the main window scrolling rectangle, in which case ImGuiWindowFlags_MenuBar will become unnecessary. Then later the same sys
| 9150 | // Ideally we also want this to be responsible for claiming space out of the main window scrolling rectangle, in which case ImGuiWindowFlags_MenuBar will become unnecessary. |
| 9151 | // Then later the same system could be used for multiple menu-bars, scrollbars, side-bars. |
| 9152 | bool ImGui::BeginMenuBar() |
| 9153 | { |
| 9154 | ImGuiWindow* window = GetCurrentWindow(); |
| 9155 | if (window->SkipItems) |
| 9156 | return false; |
| 9157 | if (!(window->Flags & ImGuiWindowFlags_MenuBar)) |
| 9158 | return false; |
| 9159 | |
| 9160 | IM_ASSERT(!window->DC.MenuBarAppending); |
| 9161 | BeginGroup(); // Backup position on layer 0 // FIXME: Misleading to use a group for that backup/restore |
| 9162 | PushID("##MenuBar"); |
| 9163 | |
| 9164 | // 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. |
| 9165 | // 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. |
| 9166 | const float border_top = ImMax(window->WindowBorderSize * 0.5f - window->TitleBarHeight, 0.0f); |
| 9167 | ImRect bar_rect = window->MenuBarRect(); |
| 9168 | ImRect clip_rect(IM_ROUND(bar_rect.Min.x + window->WindowBorderSize * 0.5f), IM_ROUND(bar_rect.Min.y + border_top), IM_ROUND(ImMax(bar_rect.Min.x, bar_rect.Max.x - ImMax(window->WindowRounding, window->WindowBorderSize * 0.5f))), IM_ROUND(bar_rect.Max.y)); |
| 9169 | clip_rect.ClipWith(window->OuterRectClipped); |
| 9170 | PushClipRect(clip_rect.Min, clip_rect.Max, false); |
| 9171 | |
| 9172 | // We overwrite CursorMaxPos because BeginGroup sets it to CursorPos (essentially the .EmitItem hack in EndMenuBar() would need something analogous here, maybe a BeginGroupEx() with flags). |
| 9173 | window->DC.CursorPos = window->DC.CursorMaxPos = ImVec2(bar_rect.Min.x + window->DC.MenuBarOffset.x, bar_rect.Min.y + window->DC.MenuBarOffset.y); |
| 9174 | window->DC.LayoutType = ImGuiLayoutType_Horizontal; |
| 9175 | window->DC.IsSameLine = false; |
| 9176 | window->DC.NavLayerCurrent = ImGuiNavLayer_Menu; |
| 9177 | window->DC.MenuBarAppending = true; |
| 9178 | AlignTextToFramePadding(); |
| 9179 | return true; |
| 9180 | } |
| 9181 | |
| 9182 | void ImGui::EndMenuBar() |
| 9183 | { |
nothing calls this directly
no test coverage detected