diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-04-27 14:50:26 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-06-13 16:22:34 +0300 |
commit | 7a10cfe7fe01bbeb7588239a9fd743ecc6af6c39 (patch) | |
tree | 05b5b281f0aef36fc27bcaf4b8b9aa9e14d193e3 /source/blender | |
parent | 1664ccb6752adf1bcf326b72d1230aa9b667a1fb (diff) |
UI: preset popover buttons in panel headers.
Moves the preset into a menu for the panel header, so it can be changed
without opening the panel and takes up less space. Two remaining issues:
* For long lists the add new preset button can be scrolled off screen.
* We should support showing the name of the chosen preset in the panel
header, but the current preset system does not support detecting which
preset is used.
Differential Revision: https://developer.blender.org/D3366
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/BKE_screen.h | 2 | ||||
-rw-r--r-- | source/blender/editors/include/UI_icons.h | 4 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_region_popover.c | 12 | ||||
-rw-r--r-- | source/blender/editors/screen/area.c | 15 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_ui.c | 27 |
5 files changed, 53 insertions, 7 deletions
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h index 4270e6eb1b4..1b42ce97940 100644 --- a/source/blender/blenkernel/BKE_screen.h +++ b/source/blender/blenkernel/BKE_screen.h @@ -216,6 +216,8 @@ typedef struct PanelType { int (*poll)(const struct bContext *C, struct PanelType *pt); /* draw header (optional) */ void (*draw_header)(const struct bContext *C, struct Panel *pa); + /* draw header preset (optional) */ + void (*draw_header_preset)(const struct bContext *C, struct Panel *pa); /* draw entirely, view changes should be handled here */ void (*draw)(const struct bContext *C, struct Panel *pa); diff --git a/source/blender/editors/include/UI_icons.h b/source/blender/editors/include/UI_icons.h index 3bc1255d23f..659f6c97696 100644 --- a/source/blender/editors/include/UI_icons.h +++ b/source/blender/editors/include/UI_icons.h @@ -113,9 +113,7 @@ DEF_ICON(FILE_TICK) DEF_ICON(QUIT) DEF_ICON(URL) DEF_ICON(RECOVER_LAST) -#ifndef DEF_ICON_BLANK_SKIP - DEF_ICON(BLANK038) -#endif +DEF_ICON(PRESET) DEF_ICON(FULLSCREEN_ENTER) DEF_ICON(FULLSCREEN_EXIT) DEF_ICON(BLANK1) // Not actually blank - this is used all over the place diff --git a/source/blender/editors/interface/interface_region_popover.c b/source/blender/editors/interface/interface_region_popover.c index e769d367b45..fb14ca745c6 100644 --- a/source/blender/editors/interface/interface_region_popover.c +++ b/source/blender/editors/interface/interface_region_popover.c @@ -168,11 +168,17 @@ static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, v block->my = handle->prev_my; } - /* Prefer popover from header to be positioned into the editor. */ if (!slideout) { ScrArea *sa = CTX_wm_area(C); - if (sa && ED_area_header_alignment(sa) == RGN_ALIGN_BOTTOM) { - ARegion *ar = CTX_wm_region(C); + ARegion *ar = CTX_wm_region(C); + + if (ar && ar->panels.first) { + /* For regions with panels, prefer to open to top so we can + * see the values of the buttons below changing. */ + UI_block_direction_set(block, UI_DIR_UP | UI_DIR_CENTER_X); + } + else if (sa && ED_area_header_alignment(sa) == RGN_ALIGN_BOTTOM) { + /* Prefer popover from header to be positioned into the editor. */ if (ar && ar->regiontype == RGN_TYPE_HEADER) { UI_block_direction_set(block, UI_DIR_UP | UI_DIR_CENTER_X); } diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 478afa64939..02ce64bc915 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -1861,6 +1861,21 @@ static void ed_panel_draw(const bContext *C, /* bad fixed values */ int xco, yco, h = 0; + if (pt->draw_header_preset && !(pt->flag & PNL_NO_HEADER) && (open || vertical)) { + /* for preset menu */ + panel->layout = UI_block_layout( + block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, + 0, (UI_UNIT_Y * 1.1f) + style->panelspace, UI_UNIT_Y, 1, 0, style); + + pt->draw_header_preset(C, panel); + + int headerend = w - UI_UNIT_X; + + UI_block_layout_resolve(block, &xco, &yco); + UI_block_translate(block, headerend - xco, 0); + panel->layout = NULL; + } + if (pt->draw_header && !(pt->flag & PNL_NO_HEADER) && (open || vertical)) { int labelx, labely; UI_panel_label_offset(block, &labelx, &labely); diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index ebee502515f..8083ae35dc1 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -166,6 +166,24 @@ static void panel_draw_header(const bContext *C, Panel *pnl) RNA_parameter_list_free(&list); } +static void panel_draw_header_preset(const bContext *C, Panel *pnl) +{ + extern FunctionRNA rna_Panel_draw_header_preset_func; + + PointerRNA ptr; + ParameterList list; + FunctionRNA *func; + + RNA_pointer_create(&CTX_wm_screen(C)->id, pnl->type->ext.srna, pnl, &ptr); + func = &rna_Panel_draw_header_preset_func; + + RNA_parameter_list_create(&list, &ptr, func); + RNA_parameter_set_lookup(&list, "context", &C); + pnl->type->ext.call((bContext *)C, &ptr, func, &list); + + RNA_parameter_list_free(&list); +} + static void rna_Panel_unregister(Main *UNUSED(bmain), StructRNA *type) { ARegionType *art; @@ -199,7 +217,7 @@ static StructRNA *rna_Panel_register( PanelType *pt, *parent = NULL, dummypt = {NULL}; Panel dummypanel = {NULL}; PointerRNA dummyptr; - int have_function[3]; + int have_function[4]; /* setup dummy panel & panel type to store static properties in */ dummypanel.type = &dummypt; @@ -267,6 +285,7 @@ static StructRNA *rna_Panel_register( pt->poll = (have_function[0]) ? panel_poll : NULL; pt->draw = (have_function[1]) ? panel_draw : NULL; pt->draw_header = (have_function[2]) ? panel_draw_header : NULL; + pt->draw_header_preset = (have_function[3]) ? panel_draw_header_preset : NULL; /* XXX use "no header" flag for some ordering of panels until we have real panel ordering */ if (pt->flag & PNL_NO_HEADER) { @@ -1058,6 +1077,12 @@ static void rna_def_panel(BlenderRNA *brna) parm = RNA_def_pointer(func, "context", "Context", "", ""); RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); + func = RNA_def_function(srna, "draw_header_preset", NULL); + RNA_def_function_ui_description(func, "Draw UI elements for presets in the panel's header"); + RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL); + parm = RNA_def_pointer(func, "context", "Context", "", ""); + RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); + prop = RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "UILayout"); RNA_def_property_ui_text(prop, "Layout", "Defines the structure of the panel in the UI"); |