UI: locate popover w/ active item under cursor

Use when popover has no parent, useful for accessing the toolbar.
This commit is contained in:
2018-05-20 09:53:01 +02:00
parent 7959617fb6
commit 8cb6ede2bf

View File

@@ -178,10 +178,23 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v
}
else {
/* Not attached to a button. */
int offset[2] = {0, 0}; /* Dummy. */
int offset[2] = {0, 0};
UI_block_flag_enable(block, UI_BLOCK_LOOP);
UI_block_direction_set(block, block->direction);
block->minbounds = UI_MENU_WIDTH_MIN;
uiBut *but = NULL;
for (but = block->buttons.first; but; but = but->next) {
if (but->flag & (UI_SELECT | UI_SELECT_DRAW)) {
break;
}
}
if (but) {
offset[0] = -(but->rect.xmin + 0.8f * BLI_rctf_size_x(&but->rect));
offset[1] = -(but->rect.ymin + 0.5f * BLI_rctf_size_y(&but->rect));
}
UI_block_bounds_set_popup(block, block_margin, offset[0], offset[1]);
}