diff --git a/source/blender/editors/interface/interface_region_popover.cc b/source/blender/editors/interface/interface_region_popover.cc index 9a2967a5cc2..46d0154fd70 100644 --- a/source/blender/editors/interface/interface_region_popover.cc +++ b/source/blender/editors/interface/interface_region_popover.cc @@ -75,13 +75,21 @@ struct uiPopover { #endif }; -static void ui_popover_create_block(bContext *C, uiPopover *pup, wmOperatorCallContext opcontext) +/** + * \param region: Optional, the region the block will be placed in. Must be set if the popover is + * supposed to support refreshing. + */ +static void ui_popover_create_block(bContext *C, + ARegion *region, + uiPopover *pup, + wmOperatorCallContext opcontext) { BLI_assert(pup->ui_size_x != 0); const uiStyle *style = UI_style_get_dpi(); - pup->block = UI_block_begin(C, nullptr, __func__, UI_EMBOSS); + pup->block = UI_block_begin(C, region, __func__, UI_EMBOSS); + UI_block_flag_enable(pup->block, UI_BLOCK_KEEP_OPEN | UI_BLOCK_POPOVER); #ifdef USE_UI_POPOVER_ONCE if (pup->is_once) { @@ -109,7 +117,7 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v /* Create UI block and layout now if it wasn't done between begin/end. */ if (!pup->layout) { - ui_popover_create_block(C, pup, WM_OP_INVOKE_REGION_WIN); + ui_popover_create_block(C, nullptr, pup, WM_OP_INVOKE_REGION_WIN); if (pup->menu_func) { pup->block->handle = handle; @@ -124,7 +132,12 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v uiBlock *block = pup->block; int width, height; - UI_block_region_set(block, handle->region); + /* in some cases we create the block before the region, + * so we set it delayed here if necessary */ + if (BLI_findindex(&handle->region->uiblocks, block) == -1) { + UI_block_region_set(block, handle->region); + } + UI_block_layout_resolve(block, &width, &height); UI_block_direction_set(block, UI_DIR_DOWN | UI_DIR_CENTER_X); @@ -348,7 +361,7 @@ uiPopover *UI_popover_begin(bContext *C, int ui_menu_width, bool from_active_but pup->butregion = butregion; /* Operator context default same as menus, change if needed. */ - ui_popover_create_block(C, pup, WM_OP_EXEC_REGION_WIN); + ui_popover_create_block(C, nullptr, pup, WM_OP_EXEC_REGION_WIN); /* create in advance so we can let buttons point to retval already */ pup->block->handle = MEM_cnew(__func__);