Menus: Fixed vertical alignments of MenuItem() calls within a menu bar. (broken by f8fae022). (#4538)

This commit is contained in:
ocornut
2021-09-14 11:09:39 +02:00
parent 82754561e2
commit 7b8bc864e9
3 changed files with 5 additions and 2 deletions

View File

@ -6851,7 +6851,7 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled)
}
else
{
// Menu inside a menu
// Menu inside a regular/vertical menu
// (In a typical menu window where all items are BeginMenu() or MenuItem() calls, extra_w will always be 0.0f.
// Only when they are other items sticking out we're going to add spacing, yet only register minimum width into the layout system.
popup_pos = ImVec2(pos.x, pos.y - style.WindowPadding.y);
@ -7007,10 +7007,11 @@ bool ImGui::MenuItemEx(const char* label, const char* icon, const char* shortcut
// Note that in this situation: we don't render the shortcut, we render a highlight instead of the selected tick mark.
float w = label_size.x;
window->DC.CursorPos.x += IM_FLOOR(style.ItemSpacing.x * 0.5f);
ImVec2 text_pos(window->DC.CursorPos.x + offsets->OffsetLabel, window->DC.CursorPos.y + window->DC.CurrLineTextBaseOffset);
PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(style.ItemSpacing.x * 2.0f, style.ItemSpacing.y));
pressed = Selectable("", selected, flags, ImVec2(w, 0.0f));
PopStyleVar();
RenderText(pos + ImVec2(offsets->OffsetLabel, 0.0f), label);
RenderText(text_pos, label);
window->DC.CursorPos.x += IM_FLOOR(style.ItemSpacing.x * (-1.0f + 0.5f)); // -1 spacing to compensate the spacing added when Selectable() did a SameLine(). It would also work to call SameLine() ourselves after the PopStyleVar().
}
else