UI: optional ui-unit-width for popovers
Some popovers don't fit well with the default width, allow panels to adjust as needed.
This commit is contained in:
parent
16878072a4
commit
9e5002aded
@ -144,9 +144,15 @@ class WindowManager(bpy_types.ID):
|
||||
finally:
|
||||
self.popmenu_end__internal(popup)
|
||||
|
||||
def popover(self, draw_func, keymap=None):
|
||||
def popover(
|
||||
self, draw_func, *,
|
||||
ui_units_x=0,
|
||||
keymap=None,
|
||||
):
|
||||
import bpy
|
||||
popup = self.popover_begin__internal()
|
||||
popup = self.popover_begin__internal(
|
||||
ui_units_x=ui_units_x,
|
||||
)
|
||||
|
||||
try:
|
||||
draw_func(popup, bpy.context)
|
||||
|
@ -204,8 +204,10 @@ typedef struct PanelType {
|
||||
char category[BKE_ST_MAXNAME]; /* for category tabs */
|
||||
char owner_id[BKE_ST_MAXNAME]; /* for work-spaces to selectively show. */
|
||||
char parent_id[BKE_ST_MAXNAME]; /* parent idname for subpanels */
|
||||
int space_type;
|
||||
int region_type;
|
||||
short space_type;
|
||||
short region_type;
|
||||
/* For popovers, 0 for default. */
|
||||
int ui_units_x;
|
||||
|
||||
int flag;
|
||||
|
||||
|
@ -446,7 +446,7 @@ int UI_popover_panel_invoke(
|
||||
struct bContext *C, int space_id, int region_id, const char *idname,
|
||||
bool keep_open, struct ReportList *reports);
|
||||
|
||||
uiPopover *UI_popover_begin(struct bContext *C) ATTR_NONNULL(1);
|
||||
uiPopover *UI_popover_begin(struct bContext *C, int menu_width) 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);
|
||||
|
@ -87,6 +87,9 @@ struct uiPopover {
|
||||
uiMenuCreateFunc menu_func;
|
||||
void *menu_arg;
|
||||
|
||||
/* Size in pixels (ui scale applied). */
|
||||
int ui_size_x;
|
||||
|
||||
#ifdef USE_UI_POPOVER_ONCE
|
||||
bool is_once;
|
||||
#endif
|
||||
@ -94,12 +97,13 @@ struct uiPopover {
|
||||
|
||||
static void ui_popover_create_block(bContext *C, uiPopover *pup, int opcontext)
|
||||
{
|
||||
uiStyle *style = UI_style_get_dpi();
|
||||
BLI_assert(pup->ui_size_x != 0);
|
||||
|
||||
uiStyle *style = UI_style_get_dpi();
|
||||
pup->block = UI_block_begin(C, NULL, __func__, UI_EMBOSS);
|
||||
pup->layout = UI_block_layout(
|
||||
pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0,
|
||||
U.widget_unit * UI_POPOVER_WIDTH_UNITS, 0, MENU_PADDING, style);
|
||||
pup->ui_size_x, 0, MENU_PADDING, style);
|
||||
|
||||
uiLayoutSetOperatorContext(pup->layout, opcontext);
|
||||
|
||||
@ -234,6 +238,13 @@ uiPopupBlockHandle *ui_popover_panel_create(
|
||||
/* Create popover, buttons are created from callback. */
|
||||
uiPopover *pup = MEM_callocN(sizeof(uiPopover), __func__);
|
||||
pup->but = but;
|
||||
|
||||
/* FIXME: maybe one day we want non panel popovers? */
|
||||
{
|
||||
int ui_units_x = ((PanelType *)arg)->ui_units_x;
|
||||
pup->ui_size_x = U.widget_unit * (ui_units_x ? ui_units_x : UI_POPOVER_WIDTH_UNITS);
|
||||
}
|
||||
|
||||
pup->menu_func = menu_func;
|
||||
pup->menu_arg = arg;
|
||||
|
||||
@ -288,7 +299,7 @@ int UI_popover_panel_invoke(
|
||||
ui_popover_panel_create(C, NULL, NULL, ui_item_paneltype_func, pt);
|
||||
}
|
||||
else {
|
||||
uiPopover *pup = UI_popover_begin(C);
|
||||
uiPopover *pup = UI_popover_begin(C, U.widget_unit * pt->ui_units_x);
|
||||
layout = UI_popover_layout(pup);
|
||||
UI_paneltype_draw(C, pt, layout);
|
||||
UI_popover_end(C, pup, NULL);
|
||||
@ -306,9 +317,13 @@ int UI_popover_panel_invoke(
|
||||
/**
|
||||
* Only return handler, and set optional title.
|
||||
*/
|
||||
uiPopover *UI_popover_begin(bContext *C)
|
||||
uiPopover *UI_popover_begin(bContext *C, int ui_size_x)
|
||||
{
|
||||
uiPopover *pup = MEM_callocN(sizeof(uiPopover), "popover menu");
|
||||
if (ui_size_x == 0) {
|
||||
ui_size_x = U.widget_unit * UI_POPOVER_WIDTH_UNITS;
|
||||
}
|
||||
pup->ui_size_x = ui_size_x;
|
||||
|
||||
/* Opertor context default same as menus, change if needed. */
|
||||
ui_popover_create_block(C, pup, WM_OP_EXEC_REGION_WIN);
|
||||
|
@ -1165,6 +1165,11 @@ static void rna_def_panel(BlenderRNA *brna)
|
||||
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
|
||||
RNA_def_property_ui_text(prop, "Parent ID Name", "If this is set, the panel becomes a subpanel");
|
||||
|
||||
prop = RNA_def_property(srna, "bl_ui_units_x", PROP_INT, PROP_UNSIGNED);
|
||||
RNA_def_property_int_sdna(prop, NULL, "type->ui_units_x");
|
||||
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
|
||||
RNA_def_property_ui_text(prop, "Units X", "When set, defines popup panel width");
|
||||
|
||||
prop = RNA_def_property(srna, "use_pin", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", PNL_PIN);
|
||||
RNA_def_property_ui_text(prop, "Pin", "");
|
||||
|
@ -376,12 +376,12 @@ static void rna_PopMenuEnd(bContext *C, PointerRNA *handle)
|
||||
}
|
||||
|
||||
/* popover wrapper */
|
||||
static PointerRNA rna_PopoverBegin(bContext *C)
|
||||
static PointerRNA rna_PopoverBegin(bContext *C, int ui_units_x)
|
||||
{
|
||||
PointerRNA r_ptr;
|
||||
void *data;
|
||||
|
||||
data = (void *)UI_popover_begin(C);
|
||||
data = (void *)UI_popover_begin(C, U.widget_unit * ui_units_x);
|
||||
|
||||
RNA_pointer_create(NULL, &RNA_UIPopover, data, &r_ptr);
|
||||
|
||||
@ -602,6 +602,7 @@ void RNA_api_wm(StructRNA *srna)
|
||||
/* wrap UI_popover_begin */
|
||||
func = RNA_def_function(srna, "popover_begin__internal", "rna_PopoverBegin");
|
||||
RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT);
|
||||
RNA_def_property(func, "ui_units_x", PROP_INT, PROP_UNSIGNED);
|
||||
/* return */
|
||||
parm = RNA_def_pointer(func, "menu", "UIPopover", "", "");
|
||||
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_RNAPTR);
|
||||
|
Loading…
Reference in New Issue
Block a user