diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-11-01 20:30:07 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-11-01 21:01:10 +0300 |
commit | 3ec4d0b51bf3a76725e39a57b0f30bec3edc6882 (patch) | |
tree | 8d99f8552e0cc465a9469f5d569433cbfa3dab88 /source/blender/editors/interface/interface_layout.c | |
parent | 07dbff7dc1d5cfca9fbfb74204a2298e16d471b4 (diff) |
UI: Add UILayout.operator_menu_hold
This is an operator button that opens a menu when the button is held.
Diffstat (limited to 'source/blender/editors/interface/interface_layout.c')
-rw-r--r-- | source/blender/editors/interface/interface_layout.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index 616fc055c03..33dc74cbe23 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -795,7 +795,7 @@ static void ui_item_disabled(uiLayout *layout, const char *name) * \param r_opptr: Optional, initialize with operator properties when not NULL. * Will always be written to even in the case of errors. */ -void uiItemFullO_ptr( +static uiBut *uiItemFullO_ptr_ex( uiLayout *layout, wmOperatorType *ot, const char *name, int icon, IDProperty *properties, int context, int flag, PointerRNA *r_opptr) @@ -862,6 +862,50 @@ void uiItemFullO_ptr( *r_opptr = *opptr; } } + + return but; +} + +static void ui_item_hold_menu(struct bContext *C, ARegion *butregion, uiBut *but) +{ + uiPopupMenu *pup = UI_popup_menu_begin(C, "", ICON_NONE); + uiLayout *layout = UI_popup_menu_layout(pup); + uiBlock *block = layout->root->block; + UI_popup_menu_but_set(pup, butregion, but); + + block->flag |= UI_BLOCK_POPUP_HOLD; + + const char *menu_id = but->hold_argN; + MenuType *mt = WM_menutype_find(menu_id, true); + if (mt) { + Menu menu = {NULL}; + menu.layout = layout; + menu.type = mt; + mt->draw(C, &menu); + } + else { + uiItemL(layout, "Menu Missing:", ICON_NONE); + uiItemL(layout, menu_id, ICON_NONE); + } + UI_popup_menu_end(C, pup); +} + +void uiItemFullO_ptr( + uiLayout *layout, wmOperatorType *ot, + const char *name, int icon, IDProperty *properties, int context, int flag, + PointerRNA *r_opptr) +{ + uiItemFullO_ptr_ex(layout, ot, name, icon, properties, context, flag, r_opptr); +} + +void uiItemFullOMenuHold_ptr( + uiLayout *layout, wmOperatorType *ot, + const char *name, int icon, IDProperty *properties, int context, int flag, + const char *menu_id, + PointerRNA *r_opptr) +{ + uiBut *but = uiItemFullO_ptr_ex(layout, ot, name, icon, properties, context, flag, r_opptr); + UI_but_func_hold_set(but, ui_item_hold_menu, BLI_strdup(menu_id)); } void uiItemFullO( |