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
This commit is contained in:
parent
e17df47303
commit
93b8040f57
Notes:
blender-bot
2024-03-22 15:57:27 +01:00
Referenced by issue #77408, Continued Outliner Improvements Design
|
@ -1968,7 +1968,7 @@ static int insert_key_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UN
|
|||
/* call the menu, which will call this operator again, hence the canceled */
|
||||
pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE);
|
||||
layout = UI_popup_menu_layout(pup);
|
||||
uiItemsEnumO(layout, "ANIM_OT_keyframe_insert_menu", "type");
|
||||
uiItemsEnumO(layout, "ANIM_OT_keyframe_insert_menu", "type", false);
|
||||
UI_popup_menu_end(C, pup);
|
||||
|
||||
return OPERATOR_INTERFACE;
|
||||
|
|
|
@ -479,7 +479,7 @@ static int keyingset_active_menu_invoke(bContext *C, wmOperator *op, const wmEve
|
|||
/* call the menu, which will call this operator again, hence the canceled */
|
||||
pup = UI_popup_menu_begin(C, op->type->name, ICON_NONE);
|
||||
layout = UI_popup_menu_layout(pup);
|
||||
uiItemsEnumO(layout, "ANIM_OT_keying_set_active_set", "type");
|
||||
uiItemsEnumO(layout, "ANIM_OT_keying_set_active_set", "type", false);
|
||||
UI_popup_menu_end(C, pup);
|
||||
|
||||
return OPERATOR_INTERFACE;
|
||||
|
|
|
@ -5940,7 +5940,7 @@ static int toggle_cyclic_invoke(bContext *C, wmOperator *op, const wmEvent *UNUS
|
|||
if (nu->type == CU_NURBS) {
|
||||
pup = UI_popup_menu_begin(C, IFACE_("Direction"), ICON_NONE);
|
||||
layout = UI_popup_menu_layout(pup);
|
||||
uiItemsEnumO(layout, op->type->idname, "direction");
|
||||
uiItemsEnumO(layout, op->type->idname, "direction", false);
|
||||
UI_popup_menu_end(C, pup);
|
||||
return OPERATOR_INTERFACE;
|
||||
}
|
||||
|
|
|
@ -1403,7 +1403,7 @@ static int gpencil_layer_change_invoke(bContext *C, wmOperator *op, const wmEven
|
|||
/* call the menu, which will call this operator again, hence the canceled */
|
||||
pup = UI_popup_menu_begin(C, op->type->name, ICON_NONE);
|
||||
layout = UI_popup_menu_layout(pup);
|
||||
uiItemsEnumO(layout, "GPENCIL_OT_layer_change", "layer");
|
||||
uiItemsEnumO(layout, "GPENCIL_OT_layer_change", "layer", false);
|
||||
UI_popup_menu_end(C, pup);
|
||||
|
||||
return OPERATOR_INTERFACE;
|
||||
|
|
|
@ -2212,7 +2212,7 @@ void uiItemEnumO_string(uiLayout *layout,
|
|||
const char *opname,
|
||||
const char *propname,
|
||||
const char *value);
|
||||
void uiItemsEnumO(uiLayout *layout, const char *opname, const char *propname);
|
||||
void uiItemsEnumO(uiLayout *layout, const char *opname, const char *propname, int flag);
|
||||
void uiItemBooleanO(uiLayout *layout,
|
||||
const char *name,
|
||||
int icon,
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -256,7 +256,7 @@ static int unpack_all_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(
|
|||
layout = UI_popup_menu_layout(pup);
|
||||
|
||||
uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT);
|
||||
uiItemsEnumO(layout, "FILE_OT_unpack_all", "method");
|
||||
uiItemsEnumO(layout, "FILE_OT_unpack_all", "method", false);
|
||||
|
||||
UI_popup_menu_end(C, pup);
|
||||
|
||||
|
|
|
@ -2658,7 +2658,7 @@ static int outliner_operator_menu(bContext *C, const char *opname)
|
|||
|
||||
/* set this so the default execution context is the same as submenus */
|
||||
uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_REGION_WIN);
|
||||
uiItemsEnumO(layout, ot->idname, RNA_property_identifier(ot->prop));
|
||||
uiItemsEnumO(layout, ot->idname, RNA_property_identifier(ot->prop), false);
|
||||
|
||||
uiItemS(layout);
|
||||
|
||||
|
|
|
@ -187,7 +187,7 @@ static int select_orientation_invoke(bContext *C,
|
|||
|
||||
pup = UI_popup_menu_begin(C, IFACE_("Orientation"), ICON_NONE);
|
||||
layout = UI_popup_menu_layout(pup);
|
||||
uiItemsEnumO(layout, "TRANSFORM_OT_select_orientation", "orientation");
|
||||
uiItemsEnumO(layout, "TRANSFORM_OT_select_orientation", "orientation", false);
|
||||
UI_popup_menu_end(C, pup);
|
||||
|
||||
return OPERATOR_INTERFACE;
|
||||
|
|
|
@ -346,6 +346,15 @@ static PointerRNA rna_uiItemOMenuHold(uiLayout *layout,
|
|||
return opptr;
|
||||
}
|
||||
|
||||
static void rna_uiItemsEnumO(uiLayout *layout,
|
||||
const char *opname,
|
||||
const char *propname,
|
||||
const bool icon_only)
|
||||
{
|
||||
int flag = icon_only ? UI_ITEM_R_ICON_ONLY : 0;
|
||||
uiItemsFullEnumO(layout, opname, propname, NULL, uiLayoutGetOperatorContext(layout), flag);
|
||||
}
|
||||
|
||||
static void rna_uiItemMenuEnumO(uiLayout *layout,
|
||||
bContext *C,
|
||||
const char *opname,
|
||||
|
@ -972,11 +981,12 @@ void RNA_api_ui_layout(StructRNA *srna)
|
|||
"Item. Places a button into the layout to call an Operator");
|
||||
}
|
||||
|
||||
func = RNA_def_function(srna, "operator_enum", "uiItemsEnumO");
|
||||
func = RNA_def_function(srna, "operator_enum", "rna_uiItemsEnumO");
|
||||
parm = RNA_def_string(func, "operator", NULL, 0, "", "Identifier of the operator");
|
||||
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
|
||||
parm = RNA_def_string(func, "property", NULL, 0, "", "Identifier of property in operator");
|
||||
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
|
||||
RNA_def_boolean(func, "icon_only", false, "", "Draw only icons in buttons, no text");
|
||||
|
||||
func = RNA_def_function(srna, "operator_menu_enum", "rna_uiItemMenuEnumO");
|
||||
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
|
||||
|
|
Loading…
Reference in New Issue