From 58752ad93c24ef5b1dfe7b4adda0874bba7174cd Mon Sep 17 00:00:00 2001 From: Julian Eisel Date: Wed, 15 Feb 2023 16:05:03 +0100 Subject: [PATCH] UI: Ensure menus with icons align all menu item labels Usually in Blender, we try to align the labels of items within a menu, if necessary by adding a blank icon for padding. This wasn't done for menus generated from enum properties (RNA or custom property enums). Now we do it whenever there is at least one item with an icon. --- source/blender/editors/interface/interface.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/interface/interface.cc b/source/blender/editors/interface/interface.cc index 6da7576d513..954b72b5680 100644 --- a/source/blender/editors/interface/interface.cc +++ b/source/blender/editors/interface/interface.cc @@ -4287,6 +4287,7 @@ static void ui_def_but_rna__menu(bContext * /*C*/, uiLayout *layout, void *but_p int totitems = 0; int categories = 0; int entries_nosepr_count = 0; + bool has_item_with_icon = false; for (const EnumPropertyItem *item = item_array; item->identifier; item++, totitems++) { if (!item->identifier[0]) { /* inconsistent, but menus with categories do not look good flipped */ @@ -4298,6 +4299,9 @@ static void ui_def_but_rna__menu(bContext * /*C*/, uiLayout *layout, void *but_p /* We do not want simple separators in `entries_nosepr_count`. */ continue; } + if (item->icon) { + has_item_with_icon = true; + } entries_nosepr_count++; } @@ -4402,11 +4406,18 @@ static void ui_def_but_rna__menu(bContext * /*C*/, uiLayout *layout, void *but_p uiItemS(column); } else { - if (item->icon) { + int icon = item->icon; + /* Use blank icon if there is none for this item (but for some other one) to make sure labels + * align. */ + if (icon == ICON_NONE && has_item_with_icon) { + icon = ICON_BLANK1; + } + + if (icon) { uiDefIconTextButI(block, UI_BTYPE_BUT_MENU, B_NOP, - item->icon, + icon, item->name, 0, 0,