From 93b8040f57297133e7b90c8dfb05088490425cb2 Mon Sep 17 00:00:00 2001 From: Nathan Craddock Date: Tue, 15 Sep 2020 07:40:38 -0600 Subject: UI: Add `icon_only` argument to operator_enum Add an option to only draw icons for operator_enum menus. This is used for drawing inline icon buttons in the outliner context menu for collection color tagging. Part of T77408 Differential Revision: https://developer.blender.org/D8880 --- source/blender/editors/interface/interface_layout.c | 21 ++++++++++++++++----- .../editors/interface/interface_region_menu_pie.c | 2 +- 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'source/blender/editors/interface') diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index f00ce7ee923..7f631923054 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -1214,6 +1214,10 @@ static uiBut *uiItemFullO_ptr_ex(uiLayout *layout, but->flag |= UI_SELECT_DRAW; } + if (flag & UI_ITEM_R_ICON_ONLY) { + UI_but_drawflag_disable(but, UI_BUT_ICON_LEFT); + } + if (layout->redalert) { UI_but_flag_enable(but, UI_BUT_REDALERT); } @@ -1501,7 +1505,14 @@ void uiItemsFullEnumO_items(uiLayout *layout, } RNA_property_enum_set(&tptr, prop, item->value); - uiItemFullO_ptr(target, ot, item->name, item->icon, tptr.data, context, flag, NULL); + uiItemFullO_ptr(target, + ot, + (flag & UI_ITEM_R_ICON_ONLY) ? NULL : item->name, + item->icon, + tptr.data, + context, + flag, + NULL); ui_but_tip_from_enum_item(block->buttons.last, item); } @@ -1509,7 +1520,7 @@ void uiItemsFullEnumO_items(uiLayout *layout, if (item->name) { uiBut *but; - if (item != item_array && !radial && split) { + if (item != item_array && !radial && split != NULL) { target = uiLayoutColumn(split, layout->align); /* inconsistent, but menus with labels do not look good flipped */ @@ -1625,9 +1636,9 @@ void uiItemsFullEnumO(uiLayout *layout, } } -void uiItemsEnumO(uiLayout *layout, const char *opname, const char *propname) +void uiItemsEnumO(uiLayout *layout, const char *opname, const char *propname, int flag) { - uiItemsFullEnumO(layout, opname, propname, NULL, layout->root->opcontext, 0); + uiItemsFullEnumO(layout, opname, propname, NULL, layout->root->opcontext, flag); } /* for use in cases where we have */ @@ -3399,7 +3410,7 @@ static void menu_item_enum_opname_menu(bContext *UNUSED(C), uiLayout *layout, vo MenuItemLevel *lvl = (MenuItemLevel *)(((uiBut *)arg)->func_argN); uiLayoutSetOperatorContext(layout, lvl->opcontext); - uiItemsEnumO(layout, lvl->opname, lvl->propname); + uiItemsEnumO(layout, lvl->opname, lvl->propname, false); layout->root->block->flag |= UI_BLOCK_IS_FLIP; diff --git a/source/blender/editors/interface/interface_region_menu_pie.c b/source/blender/editors/interface/interface_region_menu_pie.c index 631f395390f..a3d8e0820b7 100644 --- a/source/blender/editors/interface/interface_region_menu_pie.c +++ b/source/blender/editors/interface/interface_region_menu_pie.c @@ -261,7 +261,7 @@ int UI_pie_menu_invoke_from_operator_enum(struct bContext *C, layout = UI_pie_menu_layout(pie); layout = uiLayoutRadial(layout); - uiItemsEnumO(layout, opname, propname); + uiItemsEnumO(layout, opname, propname, false); UI_pie_menu_end(C, pie); -- cgit v1.2.3