Fix UI views not refreshing properly in popovers
No UI views are used inside popups in the main branch yet, #104831 does this so this issue became apparent. For example tree-view items would not change their collapsed state. UI views require the block to be attached to a region when drawing, so that the matching to previous versions of the tree works. Before this commit the block was attached just after. The `BLI_findindex()` check before attaching the block was already done for other kinds of popups, so this is more in sync now.
This commit is contained in:
@@ -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<uiPopupBlockHandle>(__func__);
|
||||
|
||||
Reference in New Issue
Block a user