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/makesrna | |
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/makesrna')
-rw-r--r-- | source/blender/makesrna/intern/rna_ui.c | 27 |
1 files changed, 26 insertions, 1 deletions
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"); |