diff options
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 3 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_region_popover.c | 24 |
2 files changed, 23 insertions, 4 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 3b2a80c1e05..5ef3e5d8987 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -562,7 +562,8 @@ int UI_popover_panel_invoke(struct bContext *C, bool keep_open, struct ReportList *reports); -uiPopover *UI_popover_begin(struct bContext *C, int menu_width) ATTR_NONNULL(1); +uiPopover *UI_popover_begin(struct bContext *C, int menu_width, bool from_active_button) + ATTR_NONNULL(1); void UI_popover_end(struct bContext *C, struct uiPopover *head, struct wmKeyMap *keymap); struct uiLayout *UI_popover_layout(uiPopover *head); void UI_popover_once_clear(uiPopover *pup); diff --git a/source/blender/editors/interface/interface_region_popover.c b/source/blender/editors/interface/interface_region_popover.c index 53c96fb72a7..028d99ac052 100644 --- a/source/blender/editors/interface/interface_region_popover.c +++ b/source/blender/editors/interface/interface_region_popover.c @@ -72,6 +72,7 @@ struct uiPopover { uiBlock *block; uiLayout *layout; uiBut *but; + ARegion *butregion; /* Needed for keymap removal. */ wmWindow *window; @@ -325,7 +326,7 @@ int UI_popover_panel_invoke(bContext *C, const char *idname, bool keep_open, Rep block = pup->block; } else { - uiPopover *pup = UI_popover_begin(C, U.widget_unit * pt->ui_units_x); + uiPopover *pup = UI_popover_begin(C, U.widget_unit * pt->ui_units_x, false); layout = UI_popover_layout(pup); UI_paneltype_draw(C, pt, layout); UI_popover_end(C, pup, NULL); @@ -346,8 +347,11 @@ int UI_popover_panel_invoke(bContext *C, const char *idname, bool keep_open, Rep /** * Only return handler, and set optional title. + * + * \param from_active_button: Use the active button for positioning, + * use when the popover is activated from an operator instead of directly from the button. */ -uiPopover *UI_popover_begin(bContext *C, int ui_size_x) +uiPopover *UI_popover_begin(bContext *C, int ui_size_x, bool from_active_button) { uiPopover *pup = MEM_callocN(sizeof(uiPopover), "popover menu"); if (ui_size_x == 0) { @@ -355,6 +359,20 @@ uiPopover *UI_popover_begin(bContext *C, int ui_size_x) } pup->ui_size_x = ui_size_x; + ARegion *butregion = NULL; + uiBut *but = NULL; + + if (from_active_button) { + butregion = CTX_wm_region(C); + but = UI_region_active_but_get(butregion); + if (but == NULL) { + butregion = NULL; + } + } + + pup->but = but; + pup->butregion = butregion; + /* Operator context default same as menus, change if needed. */ ui_popover_create_block(C, pup, WM_OP_EXEC_REGION_WIN); @@ -387,7 +405,7 @@ void UI_popover_end(bContext *C, uiPopover *pup, wmKeyMap *keymap) } handle = ui_popup_block_create( - C, NULL, NULL, NULL, ui_block_func_POPOVER, pup, ui_block_free_func_POPOVER); + C, pup->butregion, pup->but, NULL, ui_block_func_POPOVER, pup, ui_block_free_func_POPOVER); /* Add handlers. */ UI_popup_handlers_add(C, &window->modalhandlers, handle, 0); |