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/blender/editors | |
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/blender/editors')
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 2 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_region_popover.c | 23 |
2 files changed, 20 insertions, 5 deletions
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); |