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_regions.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_regions.c')
-rw-r--r-- | source/blender/editors/interface/interface_regions.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 71124cf8eb7..06d5e5a314e 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -2627,6 +2627,7 @@ struct uiPopupMenu { uiBlock *block; uiLayout *layout; uiBut *but; + ARegion *butregion; int mx, my; bool popup, slideout; @@ -2873,17 +2874,33 @@ uiPopupMenu *UI_popup_menu_begin(bContext *C, const char *title, int icon) return UI_popup_menu_begin_ex(C, title, __func__, icon); } +/** + * Setting the button makes the popup open from the button instead of the cursor. + */ +void UI_popup_menu_but_set(uiPopupMenu *pup, struct ARegion *butregion, uiBut *but) +{ + pup->but = but; + pup->butregion = butregion; +} + /* set the whole structure to work */ void UI_popup_menu_end(bContext *C, uiPopupMenu *pup) { wmWindow *window = CTX_wm_window(C); uiPopupBlockHandle *menu; + uiBut *but = NULL; + ARegion *butregion = NULL; pup->popup = true; pup->mx = window->eventstate->x; pup->my = window->eventstate->y; - - menu = ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_POPUP, pup); + + if (pup->but) { + but = pup->but; + butregion = pup->butregion; + } + + menu = ui_popup_block_create(C, butregion, but, NULL, ui_block_func_POPUP, pup); menu->popup = true; UI_popup_handlers_add(C, &window->modalhandlers, menu, 0); |