Menus: made MenuItem() in a menu bar reflect the 'selected' argument with a highlight. (#4128)

This commit is contained in:
ocornut 2021-05-20 15:00:36 +02:00
parent fd06dc511f
commit 45f5ed52c1
2 changed files with 3 additions and 2 deletions

View File

@ -60,6 +60,7 @@ Other Changes:
- Tables: Sharing more memory buffers between tables, reducing general memory footprints. (#3740)
- TabBar: Fixed mouse reordering with very fast movements (e.g. crossing multiple tabs in a single
frame and then immediately standling still (would only affect automation/bots). [@rokups]
- Menus: made MenuItem() in a menu bar reflect the 'selected' argument with a highlight. (#4128) [@mattelegende]
- Drags, Sliders, Inputs: Specifying a NULL format to Float functions default them to "%.3f" to be
consistent with the compile-time default. (#3922)
- DragScalar: Add default value for v_speed argument to match higher-level functions. (#3922) [@eliasdaler]

View File

@ -6883,11 +6883,11 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, boo
if (window->DC.LayoutType == ImGuiLayoutType_Horizontal)
{
// Mimic the exact layout spacing of BeginMenu() to allow MenuItem() inside a menu bar, which is a little misleading but may be useful
// Note that in this situation we render neither the shortcut neither the selected tick mark
// 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);
PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(style.ItemSpacing.x * 2.0f, style.ItemSpacing.y));
pressed = Selectable(label, false, flags, ImVec2(w, 0.0f));
pressed = Selectable(label, selected, flags, ImVec2(w, 0.0f));
PopStyleVar();
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().
}