UI: support for a popup panel which stays open

This commit is contained in:
Campbell Barton 2018-05-25 12:54:24 +02:00
parent e9908134e8
commit b11a1d5da2
Notes: blender-bot 2023-02-14 07:53:51 +01:00
Referenced by issue #55145, Implement Driver Workflow Changes
4 changed files with 34 additions and 22 deletions

View File

@ -976,17 +976,17 @@ static int edit_driver_button_exec(bContext *C, wmOperator *op)
PropertyRNA *prop = NULL;
int index;
const bool all = 0; // RNA_boolean_get(op->ptr, "all");
/* try to find driver using property retrieved from UI */
UI_context_active_but_prop_get(C, &ptr, &prop, &index);
if (all)
index = -1;
if (ptr.id.data && ptr.data && prop) {
UI_popover_panel_invoke(C, SPACE_IPO, RGN_TYPE_UI, "GRAPH_PT_drivers_popover", op->reports);
UI_popover_panel_invoke(C, SPACE_IPO, RGN_TYPE_UI, "GRAPH_PT_drivers_popover", true, op->reports);
}
return OPERATOR_INTERFACE;
}

View File

@ -431,7 +431,7 @@ typedef struct uiPopover uiPopover;
int UI_popover_panel_invoke(
struct bContext *C, int space_id, int region_id, const char *idname,
struct ReportList *reports);
bool keep_open, struct ReportList *reports);
uiPopover *UI_popover_begin(struct bContext *C) ATTR_NONNULL(1);
void UI_popover_end(struct bContext *C, struct uiPopover *head, struct wmKeyMap *keymap);

View File

@ -189,17 +189,26 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v
UI_block_flag_enable(block, UI_BLOCK_LOOP);
UI_block_direction_set(block, block->direction);
block->minbounds = UI_MENU_WIDTH_MIN;
bool use_place_under_active = false;
uiBut *but = NULL;
for (but = block->buttons.first; but; but = but->next) {
if (but->flag & (UI_SELECT | UI_SELECT_DRAW)) {
break;
}
#ifdef USE_POPOVER_ONCE
if (pup->is_once) {
/* Weak, toolbars act like menus, so position with the cursor under the active button. */
use_place_under_active = true;
}
#endif
if (use_place_under_active) {
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));
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]);
@ -256,11 +265,15 @@ uiPopupBlockHandle *ui_popover_panel_create(
/** \name Standard Popover Panels
* \{ */
static void ui_item_paneltype_func(bContext *C, uiLayout *layout, void *arg_pt)
{
PanelType *pt = (PanelType *)arg_pt;
UI_paneltype_draw(C, pt, layout);
}
int UI_popover_panel_invoke(
bContext *C, int space_id, int region_id, const char *idname,
ReportList *reports)
bool keep_open, ReportList *reports)
{
uiLayout *layout;
PanelType *pt = UI_paneltype_find(space_id, region_id, idname);
@ -277,7 +290,10 @@ int UI_popover_panel_invoke(
return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
}
{
if (keep_open) {
ui_popover_panel_create(C, NULL, NULL, ui_item_paneltype_func, pt);
}
else {
uiPopover *pup = UI_popover_begin(C);
layout = UI_popover_layout(pup);
UI_paneltype_draw(C, pt, layout);
@ -366,7 +382,3 @@ void UI_popover_once_clear(uiPopover *pup)
#endif
/** \} */
/* We may want to support this in future */
/* Similar to UI_popup_menu_invoke */
// int UI_popover_panel_invoke(bContext *C, const char *idname, ReportList *reports);

View File

@ -2248,7 +2248,7 @@ static int wm_call_panel_exec(bContext *C, wmOperator *op)
const int space_type = RNA_enum_get(op->ptr, "space_type");
const int region_type = RNA_enum_get(op->ptr, "region_type");
return UI_popover_panel_invoke(C, space_type, region_type, idname, op->reports);
return UI_popover_panel_invoke(C, space_type, region_type, idname, true, op->reports);
}
static void WM_OT_call_panel(wmOperatorType *ot)