[Bf-blender-cvs] [21a313eec2b] modifier-panels-ui: Always add recreate list panels in the correct place.

Hans Goudey noreply at git.blender.org
Mon Apr 6 22:07:47 CEST 2020


Commit: 21a313eec2b990548b3e5d700586a6b8bd3410bb
Author: Hans Goudey
Date:   Mon Apr 6 15:07:38 2020 -0500
Branches: modifier-panels-ui
https://developer.blender.org/rB21a313eec2b990548b3e5d700586a6b8bd3410bb

Always add recreate list panels in the correct place.

This requires adding a start type in case we're adding the first
recreate panel.

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/BKE_screen.h
M	source/blender/editors/interface/interface_panel.c
M	source/blender/makesdna/DNA_screen_types.h
M	source/blender/makesrna/intern/rna_ui.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index b37141a4511..bc0efce1652 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -26,7 +26,7 @@ class ModifierButtonsPanel:
     bl_space_type = 'PROPERTIES'
     bl_region_type = 'WINDOW'
     bl_context = "modifier"
-    bl_options = {'HIDE_HEADER'}
+    bl_options = {'HIDE_HEADER', 'RECREATE_LIST_START'}
 
 
 class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 788a9653c9f..cd4c12d836f 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -235,14 +235,14 @@ typedef struct PanelType {
   /**
    * Set the panel and subpanel's expansion state from the corresponding expansion flag. Called
    * on draw updates.
-   * NOTE: Subpanels are indexed in depth first order, the visual order you would see if all panels
+   * \note Subpanels are indexed in depth first order, the visual order you would see if all panels
    * were expanded.
    */
   void (*set_expand_from_flag)(const struct bContext *C, struct Panel *pa);
   /**
    * Set the expand bitfield from the closed / open state of this panel and its subpanels. Called
    * when the expansion state of the panel changes by user input.
-   * NOTE: Subpanels are indexed in depth first order, the visual order you would see if all panels
+   * \note Subpanels are indexed in depth first order, the visual order you would see if all panels
    * were expanded.
    */
   void (*set_expand_flag_from_panel)(const struct bContext *C, struct Panel *pa);
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index b0c96dc191f..c88a6d83b42 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -39,6 +39,7 @@
 
 #include "BLT_translation.h"
 
+#include "DNA_screen_types.h"
 #include "DNA_userdef_types.h"
 
 #include "BKE_context.h"
@@ -479,11 +480,11 @@ static void ui_offset_panel_block(uiBlock *block)
 }
 
 /**
- * Called in situations where panels need to be added dynamically rather than only having one panel
+ * Called in situations where panels need to be added dynamically rather than having only one panel
  * corresponding to each PanelType.
  */
 Panel *UI_panel_add_recreate(
-    ScrArea *sa, ARegion *region, ListBase *panels, PanelType *panel_type, int modifier_index)
+    ScrArea *sa, ARegion *region, ListBase *panels, PanelType *panel_type, int list_index)
 {
   Panel *panel = MEM_callocN(sizeof(Panel), "new panel");
   panel->type = panel_type;
@@ -495,23 +496,54 @@ Panel *UI_panel_add_recreate(
   panel->sizey = 0;
   panel->blocksizex = 0;
   panel->blocksizey = 0;
-  panel->runtime_flag |= PNL_NEW_ADDED;
 
-  panel->runtime.list_index = modifier_index;
+  panel->runtime.list_index = list_index;
 
-  /* Add the panel's children too. */
+  /* Add the panel's children too. Although they aren't recreate panels, we can still use this
+   * function to creat them, as UI_panel_begin does other things we don't need to do. */
   for (LinkData *link = panel_type->children.first; link; link = link->next) {
     PanelType *child = link->data;
-    UI_panel_add_recreate(sa, region, &panel->children, child, modifier_index);
+    UI_panel_add_recreate(sa, region, &panel->children, child, list_index);
   }
 
-  BLI_addtail(panels, panel);
+  /* If we're adding a recreate list panel, make sure it's added to the end of the list. Check the
+   * context string to make sure we add to the right list.
+   *
+   * We can the panel list is also the display order because the recreate panel list is rebuild
+   * when the order changes. */
+  if (panel_type->flag & PANELTYPE_RECREATE) {
+    Panel *last_list_panel = NULL;
+
+    for (Panel *list_panel = panels->first; list_panel; list_panel = list_panel->next) {
+      if (list_panel->type == NULL) {
+        continue;
+      }
+      if (list_panel->type->flag & (PANELTYPE_RECREATE_LIST_START | PANELTYPE_RECREATE)) {
+        last_list_panel = list_panel;
+      }
+    }
+
+    /* There should always be a list panel or a list panel start before this panel. */
+    BLI_assert(last_list_panel);
+
+    panel->sortorder = last_list_panel->sortorder + 1;
+
+    BLI_insertlinkafter(panels, last_list_panel, panel);
+  }
+  else {
+    BLI_addtail(panels, panel);
+  }
 
   return panel;
 }
 
 void UI_panel_set_list_index(Panel *panel, int i)
 {
+  BLI_assert(panel->type != NULL);
+  if (panel->type->parent == NULL) {
+    BLI_assert(panel->type->flag & PANELTYPE_RECREATE);
+  }
+
   panel->runtime.list_index = i;
 
   Panel *child = panel->children.first;
diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h
index 31d32fb962a..37094af0e8a 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -545,11 +545,15 @@ enum {
 /* #define PNL_SNAP_DIST        9.0 */
 
 /* paneltype flag */
-#define PNL_DEFAULT_CLOSED 1
-#define PNL_NO_HEADER 2
-#define PNL_LAYOUT_VERT_BAR 4
-/** Delete panel after drawing, don't search for panel by type. */
-#define PANELTYPE_RECREATE 8
+#define PNL_DEFAULT_CLOSED (1 << 0)
+#define PNL_NO_HEADER (1 << 1)
+#define PNL_LAYOUT_VERT_BAR (1 << 2)
+enum {
+  /** Delete panel after drawing, don't search for panel by type. */
+  PANELTYPE_RECREATE = (1 << 3),
+  /** This panel marks the start of a recreate panel list. Not recreated on list change. */
+  PANELTYPE_RECREATE_LIST_START = (1 << 4),
+};
 
 /* Fallback panel category (only for old scripts which need updating) */
 #define PNL_CATEGORY_FALLBACK "Misc"
diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c
index ca466ce2821..bbc4ffff732 100644
--- a/source/blender/makesrna/intern/rna_ui.c
+++ b/source/blender/makesrna/intern/rna_ui.c
@@ -1285,6 +1285,17 @@ static void rna_def_panel(BlenderRNA *brna)
        "Hide Header",
        "If set to False, the panel shows a header, which contains a clickable "
        "arrow to collapse the panel and the label (see bl_label)"},
+      {PANELTYPE_RECREATE,
+       "RECREATE",
+       0,
+       "Recreate Panel",
+       "Multiple panels with this type can be used as part of a list depending on data external "
+       "to the UI, used to create panels for the modifier stack and other stacks."},
+      {PANELTYPE_RECREATE_LIST_START,
+       "RECREATE_LIST_START",
+       0,
+       "Recreate List Start",
+       "The panel with this type marks the start of a recreate panel list"},
       {0, NULL, 0, NULL, NULL},
   };



More information about the Bf-blender-cvs mailing list