diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-07-03 20:50:00 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-07-03 20:55:01 +0300 |
commit | 9e5002adedf4e701a4761c4d7f2754dcdcbb4067 (patch) | |
tree | f4bb9afd1a3943629c8f0d5d3202a6b7c234f99b /source | |
parent | 16878072a499d1b328e8f2eb968e5fd4829d996b (diff) |
UI: optional ui-unit-width for popovers
Some popovers don't fit well with the default width,
allow panels to adjust as needed.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_screen.h | 6 | ||||
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_region_popover.c | 23 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ui.c | 5 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_wm_api.c | 5 |
5 files changed, 32 insertions, 9 deletions
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index 861b47aebc6..5bfa2a8a8fe 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -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; diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 1ab1c5227ea..8a758d01809 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -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); diff --git a/source/blender/editors/interface/interface_region_popover.c b/source/blender/editors/interface/interface_region_popover.c index fb14ca745c6..35856b6c8b2 100644 --- a/source/blender/editors/interface/interface_region_popover.c +++ b/source/blender/editors/interface/interface_region_popover.c @@ -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); diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index bb7af5f327d..9d13cb8f7f0 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -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", ""); diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c index afb12f48e28..f398c4143ae 100644 --- a/source/blender/makesrna/intern/rna_wm_api.c +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -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); |