From 434acfd904a0b817e7b8f7648c0d6ae2d38cf3bb Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sun, 19 May 2019 11:23:43 +0200 Subject: UI: add Panel.bl_order property to control order of panels for add-ons This fixes poor Cycles panel ordering, with Freestyle and Custom Properties appearing at the top. For most cases order of registration is still the easiest way to control order and it's recommended to keep using that. This is mainly to solve a few cases where we want a few built-in panels to appear below add-on panels. --- source/blender/makesrna/intern/rna_ui.c | 34 +++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'source/blender/makesrna/intern/rna_ui.c') diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index faa16f4f146..0dbafbde71c 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -317,19 +317,21 @@ static StructRNA *rna_Panel_register(Main *bmain, 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) { - PanelType *pth = art->paneltypes.first; - while (pth && pth->flag & PNL_NO_HEADER) - pth = pth->next; - - if (pth) - BLI_insertlinkbefore(&art->paneltypes, pth, pt); - else - BLI_addtail(&art->paneltypes, pt); + /* Find position to insert panel based on order. */ + PanelType *pt_iter = art->paneltypes.last; + + for (; pt_iter; pt_iter = pt_iter->prev) { + /* No header has priority. */ + if ((pt->flag & PNL_NO_HEADER) && !(pt_iter->flag & PNL_NO_HEADER)) { + continue; + } + if (pt_iter->order <= pt->order) { + break; + } } - else - BLI_addtail(&art->paneltypes, pt); + + /* Insert into list. */ + BLI_insertlinkafter(&art->paneltypes, pt_iter, pt); if (parent) { pt->parent = parent; @@ -1347,6 +1349,14 @@ static void rna_def_panel(BlenderRNA *brna) 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, "bl_order", PROP_INT, PROP_UNSIGNED); + RNA_def_property_int_sdna(prop, NULL, "type->order"); + RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL); + RNA_def_property_ui_text( + prop, + "Order", + "Panels with lower numbers are default ordered before panels with higher numbers"); + 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", ""); -- cgit v1.2.3