@@ -5578,15 +5578,11 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
5578
5578
ImRect bb_inner (pos, pos + size);
5579
5579
ItemSize (size, 0 .0f );
5580
5580
5581
- // Fill horizontal space.
5582
- ImVec2 window_padding = window->WindowPadding ;
5583
- float max_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? GetWindowContentRegionMax ().x + window->Pos .x : GetContentRegionMaxAbs ().x ;
5584
- float w_draw = ImMax (label_size.x , max_x - window_padding.x - pos.x );
5585
- ImVec2 size_draw ((size_arg.x != 0 && !(flags & ImGuiSelectableFlags_DrawFillAvailWidth)) ? size_arg.x : w_draw, size.y );
5586
-
5587
- ImRect bb_align (pos, pos + size_draw);
5581
+ // Fill horizontal space
5582
+ const float max_x = (flags & ImGuiSelectableFlags_SpanAllColumns) ? GetWindowContentRegionMax ().x + window->Pos .x : GetContentRegionMaxAbs ().x ;
5588
5583
if (size_arg.x == 0 .0f || (flags & ImGuiSelectableFlags_DrawFillAvailWidth))
5589
- bb_align.Max .x += window_padding.x ;
5584
+ size.x = ImMax (label_size.x , max_x - window->WindowPadding .x - pos.x ) + window->WindowPadding .x ;
5585
+ ImRect bb_align (pos, pos + size);
5590
5586
5591
5587
// Selectables are meant to be tightly packed together with no click-gap, so we extend the box to cover spacing between selectable.
5592
5588
ImRect bb_enlarged = bb_align;
@@ -6228,10 +6224,12 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
6228
6224
else
6229
6225
{
6230
6226
// Menu inside a menu
6227
+ // (In a typical menu window where all items are BeginMenu() or MenuItem() calls, extra_w will always be 0.0f.
6228
+ // Only when they are other items sticking out we're going to add spacing, yet only register minimum width into the layout system.
6231
6229
popup_pos = ImVec2 (pos.x , pos.y - style.WindowPadding .y );
6232
- float w = window->DC .MenuColumns .DeclColumns (label_size.x , 0 .0f , IM_FLOOR (g.FontSize * 1 .20f )); // Feedback to next frame
6233
- float extra_w = ImMax (0 .0f , GetContentRegionAvail ().x - w );
6234
- pressed = Selectable (label, menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0 ), ImVec2 (w , 0 .0f ));
6230
+ float min_w = window->DC .MenuColumns .DeclColumns (label_size.x , 0 .0f , IM_FLOOR (g.FontSize * 1 .20f )); // Feedback to next frame
6231
+ float extra_w = ImMax (0 .0f , GetContentRegionAvail ().x - min_w );
6232
+ pressed = Selectable (label, menu_is_open, ImGuiSelectableFlags_NoHoldingActiveID | ImGuiSelectableFlags_SelectOnClick | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0 ), ImVec2 (min_w , 0 .0f ));
6235
6233
ImU32 text_col = GetColorU32 (enabled ? ImGuiCol_Text : ImGuiCol_TextDisabled);
6236
6234
RenderArrow (window->DrawList , pos + ImVec2 (window->DC .MenuColumns .Pos [2 ] + extra_w + g.FontSize * 0 .30f , 0 .0f ), text_col, ImGuiDir_Right);
6237
6235
}
@@ -6376,11 +6374,14 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool selected, boo
6376
6374
}
6377
6375
else
6378
6376
{
6379
- ImVec2 shortcut_size = shortcut ? CalcTextSize (shortcut, NULL ) : ImVec2 (0 .0f , 0 .0f );
6380
- float w = window->DC .MenuColumns .DeclColumns (label_size.x , shortcut_size.x , IM_FLOOR (g.FontSize * 1 .20f )); // Feedback for next frame
6381
- float extra_w = ImMax (0 .0f , GetContentRegionAvail ().x - w);
6382
- pressed = Selectable (label, false , flags | ImGuiSelectableFlags_DrawFillAvailWidth, ImVec2 (w, 0 .0f ));
6383
- if (shortcut_size.x > 0 .0f )
6377
+ // Menu item inside a vertical menu
6378
+ // (In a typical menu window where all items are BeginMenu() or MenuItem() calls, extra_w will always be 0.0f.
6379
+ // Only when they are other items sticking out we're going to add spacing, yet only register minimum width into the layout system.
6380
+ float shortcut_w = shortcut ? CalcTextSize (shortcut, NULL ).x : 0 .0f ;
6381
+ float min_w = window->DC .MenuColumns .DeclColumns (label_size.x , shortcut_w, IM_FLOOR (g.FontSize * 1 .20f )); // Feedback for next frame
6382
+ float extra_w = ImMax (0 .0f , GetContentRegionAvail ().x - min_w);
6383
+ pressed = Selectable (label, false , flags | ImGuiSelectableFlags_DrawFillAvailWidth, ImVec2 (min_w, 0 .0f ));
6384
+ if (shortcut_w > 0 .0f )
6384
6385
{
6385
6386
PushStyleColor (ImGuiCol_Text, g.Style .Colors [ImGuiCol_TextDisabled]);
6386
6387
RenderText (pos + ImVec2 (window->DC .MenuColumns .Pos [1 ] + extra_w, 0 .0f ), shortcut, NULL , false );
0 commit comments