[Bf-blender-cvs] [434acfd904a] master: UI: add Panel.bl_order property to control order of panels for add-ons

Brecht Van Lommel noreply at git.blender.org
Sun May 19 11:34:23 CEST 2019


Commit: 434acfd904a0b817e7b8f7648c0d6ae2d38cf3bb
Author: Brecht Van Lommel
Date:   Sun May 19 11:23:43 2019 +0200
Branches: master
https://developer.blender.org/rB434acfd904a0b817e7b8f7648c0d6ae2d38cf3bb

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.

===================================================================

M	release/scripts/modules/rna_prop_ui.py
M	release/scripts/startup/bl_ui/properties_freestyle.py
M	release/scripts/startup/bl_ui/properties_material.py
M	release/scripts/startup/bl_ui/properties_object.py
M	release/scripts/startup/bl_ui/properties_render.py
M	release/scripts/startup/bl_ui/properties_world.py
M	source/blender/blenkernel/BKE_screen.h
M	source/blender/makesrna/intern/rna_ui.c

===================================================================

diff --git a/release/scripts/modules/rna_prop_ui.py b/release/scripts/modules/rna_prop_ui.py
index 12b423d637b..9660a2d29be 100644
--- a/release/scripts/modules/rna_prop_ui.py
+++ b/release/scripts/modules/rna_prop_ui.py
@@ -280,6 +280,7 @@ class PropertyPanel:
     """
     bl_label = "Custom Properties"
     bl_options = {'DEFAULT_CLOSED'}
+    bl_order = 1000 # Order panel after all others
 
     @classmethod
     def poll(cls, context):
diff --git a/release/scripts/startup/bl_ui/properties_freestyle.py b/release/scripts/startup/bl_ui/properties_freestyle.py
index 095bd182ad4..7ddfb298a1b 100644
--- a/release/scripts/startup/bl_ui/properties_freestyle.py
+++ b/release/scripts/startup/bl_ui/properties_freestyle.py
@@ -39,6 +39,7 @@ class RenderFreestyleButtonsPanel:
 class RENDER_PT_freestyle(RenderFreestyleButtonsPanel, Panel):
     bl_label = "Freestyle"
     bl_options = {'DEFAULT_CLOSED'}
+    bl_order = 10
     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE'}
 
     def draw_header(self, context):
@@ -66,6 +67,7 @@ class ViewLayerFreestyleButtonsPanel:
     bl_space_type = 'PROPERTIES'
     bl_region_type = 'WINDOW'
     bl_context = "view_layer"
+    bl_order = 10
     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
 
     @classmethod
diff --git a/release/scripts/startup/bl_ui/properties_material.py b/release/scripts/startup/bl_ui/properties_material.py
index dde67e27f37..4eb33efd151 100644
--- a/release/scripts/startup/bl_ui/properties_material.py
+++ b/release/scripts/startup/bl_ui/properties_material.py
@@ -233,6 +233,7 @@ class MATERIAL_PT_viewport(MaterialButtonsPanel, Panel):
     bl_label = "Viewport Display"
     bl_context = "material"
     bl_options = {'DEFAULT_CLOSED'}
+    bl_order = 10
 
     @classmethod
     def poll(cls, context):
diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py
index 3265366a2f9..6a938b40c2e 100644
--- a/release/scripts/startup/bl_ui/properties_object.py
+++ b/release/scripts/startup/bl_ui/properties_object.py
@@ -212,6 +212,7 @@ class OBJECT_PT_collections(ObjectButtonsPanel, Panel):
 class OBJECT_PT_display(ObjectButtonsPanel, Panel):
     bl_label = "Viewport Display"
     bl_options = {'DEFAULT_CLOSED'}
+    bl_order = 10
 
     def draw(self, context):
         layout = self.layout
diff --git a/release/scripts/startup/bl_ui/properties_render.py b/release/scripts/startup/bl_ui/properties_render.py
index 45a492c0ff7..db017ddfdc5 100644
--- a/release/scripts/startup/bl_ui/properties_render.py
+++ b/release/scripts/startup/bl_ui/properties_render.py
@@ -63,6 +63,7 @@ class RENDER_PT_context(Panel):
 class RENDER_PT_color_management(RenderButtonsPanel, Panel):
     bl_label = "Color Management"
     bl_options = {'DEFAULT_CLOSED'}
+    bl_order = 100
     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
 
     def draw(self, context):
diff --git a/release/scripts/startup/bl_ui/properties_world.py b/release/scripts/startup/bl_ui/properties_world.py
index d059c2d2e4d..705be66ecc1 100644
--- a/release/scripts/startup/bl_ui/properties_world.py
+++ b/release/scripts/startup/bl_ui/properties_world.py
@@ -152,6 +152,7 @@ class EEVEE_WORLD_PT_volume(WorldButtonsPanel, Panel):
 class WORLD_PT_viewport_display(WorldButtonsPanel, Panel):
     bl_label = "Viewport Display"
     bl_options = {'DEFAULT_CLOSED'}
+    bl_order = 10
 
     @classmethod
     def poll(cls, context):
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 167fce4406c..dcf6d6c3907 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -208,6 +208,7 @@ typedef struct PanelType {
   short region_type;
   /* For popovers, 0 for default. */
   int ui_units_x;
+  int order;
 
   int flag;
 
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", "");



More information about the Bf-blender-cvs mailing list