[Bf-blender-cvs] [5bf61c9d74b] modifier-panels-ui: Refactor saving and setting list panel expansion

Hans Goudey noreply at git.blender.org
Fri Apr 10 19:58:38 CEST 2020


Commit: 5bf61c9d74b611a187849a1a148f2115f61e2d09
Author: Hans Goudey
Date:   Fri Apr 10 12:57:18 2020 -0500
Branches: modifier-panels-ui
https://developer.blender.org/rB5bf61c9d74b611a187849a1a148f2115f61e2d09

Refactor  saving and setting list panel expansion

The public functions are named more sanely and their requirements are
much simpler, with more of the logic handled internally by interface_panel.c.

Also solves a bug saving and loading sub-subpanel expansion.

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

M	source/blender/blenkernel/BKE_screen.h
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_panel.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/modifiers/intern/MOD_ui_common.c

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

diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index cc5999ca51f..5f88061d5a9 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -238,14 +238,14 @@ typedef struct PanelType {
    * \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);
+  short (*get_list_data_expand_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
    * were expanded.
    */
-  void (*set_expand_flag_from_panel)(const struct bContext *C, struct Panel *pa);
+  void (*set_list_data_expand_flag)(const struct bContext *C, struct Panel *pa, short expand_flag);
 
   /* sub panels */
   struct PanelType *parent;
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 491e9a1cdce..4bc626ff4b3 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1664,17 +1664,6 @@ void UI_panel_end(const struct ScrArea *area,
                   int height,
                   bool open);
 
-struct Panel *UI_panel_add_recreate(struct ScrArea *sa,
-                                    struct ARegion *region,
-                                    struct ListBase *panels,
-                                    struct PanelType *panel_type,
-                                    int modifier_index);
-void UI_panel_set_list_index(struct Panel *panel, int i);
-void UI_panel_delete(struct ARegion *region, struct ListBase *panels, struct Panel *panel);
-void UI_panels_free_recreate(struct ARegion *region);
-#define LIST_PANEL_UNIQUE_STR_LEN 4
-void UI_list_panel_unique_str(struct Panel *panel, char *r_name);
-
 void UI_panels_scale(struct ARegion *region, float new_width);
 void UI_panel_label_offset(struct uiBlock *block, int *r_x, int *r_y);
 int UI_panel_size_y(const struct Panel *panel);
@@ -1697,6 +1686,19 @@ void UI_panel_category_draw_all(struct ARegion *region, const char *category_id_
 
 struct PanelType *UI_paneltype_find(int space_id, int region_id, const char *idname);
 
+/* Recreate list panels for representing a list. */
+struct Panel *UI_panel_add_recreate(struct ScrArea *sa,
+                                    struct ARegion *region,
+                                    struct ListBase *panels,
+                                    struct PanelType *panel_type,
+                                    int modifier_index);
+void UI_panel_set_list_index(struct Panel *panel, int i);
+void UI_panel_delete(struct ARegion *region, struct ListBase *panels, struct Panel *panel);
+void UI_panels_free_recreate(struct ARegion *region);
+#define LIST_PANEL_UNIQUE_STR_LEN 4
+void UI_list_panel_unique_str(struct Panel *panel, char *r_name);
+void UI_panel_set_expand_from_list_data(const struct bContext *C, struct Panel *panel);
+
 /* Handlers
  *
  * Handlers that can be registered in regions, areas and windows for
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index 0580f552238..80d506a9104 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -238,15 +238,66 @@ static bool panels_need_realign(ScrArea *area, ARegion *region, Panel **r_panel_
 
 /****************************** panels ******************************/
 
+/**
+ * Recursive implementation for #UI_panel_set_expand_from_list_data.
+ */
+static void panel_set_expand_from_list_data_recursive(Panel *panel, short flag, short *flag_index)
+{
+  bool open = (flag & (1 << *flag_index));
+  if (open) {
+    panel->flag &= ~PNL_CLOSEDY;
+  }
+  else {
+    panel->flag |= PNL_CLOSEDY;
+  }
+  LISTBASE_FOREACH (Panel *, child, &panel->children) {
+    *flag_index = *flag_index + 1;
+    panel_set_expand_from_list_data_recursive(child, flag, flag_index);
+  }
+}
+
+/**
+ * Set the expansion of the panel and its subpanels from the flag stored by the list data
+ * corresponding to this panel. The flag has expansion stored in each bit in depth first
+ * order.
+ */
+void UI_panel_set_expand_from_list_data(const bContext *C, Panel *panel)
+{
+  BLI_assert(panel->type != NULL);
+  BLI_assert(panel->type->flag & PANELTYPE_RECREATE);
+
+  short expand_flag = panel->type->get_list_data_expand_flag(C, panel);
+  short flag_index = 0;
+  panel_set_expand_from_list_data_recursive(panel, expand_flag, &flag_index);
+}
+
+/**
+ * Recursive implementation for #set_panels_list_data_expand_flag.
+ */
+static void get_panel_expand_flag(Panel *panel, short *flag, short *flag_index)
+{
+  bool open = !(panel->flag & PNL_CLOSEDY);
+  if (open) {
+    *flag |= (1 << *flag_index);
+  }
+  else {
+    *flag &= ~(1 << *flag_index);
+  }
+  LISTBASE_FOREACH (Panel *, child, &panel->children) {
+    *flag_index = *flag_index + 1;
+    get_panel_expand_flag(child, flag, flag_index);
+  }
+}
+
 /**
  * Call the callback to store the panel and subpanel expansion settings in the list item that
  * corresponds to this panel.
  *
- * \note This needs to iterate through all of the regions panels because that panel with changed
- * expansion could have been the subpanel of a recreate panel and might not know about its
- * corresponding list item.
+ * \note This needs to iterate through all of the regions panels because the panel with changed
+ * expansion could have been the subpanel of a recreate panel, meaning it might not know which
+ * list item it corresponds to.
  */
-static void set_list_panel_item_expansion_flag(const bContext *C, ARegion *region)
+static void set_panels_list_data_expand_flag(const bContext *C, ARegion *region)
 {
   LISTBASE_FOREACH (Panel *, panel, &region->panels) {
     PanelType *panel_type = panel->type;
@@ -255,7 +306,10 @@ static void set_list_panel_item_expansion_flag(const bContext *C, ARegion *regio
     }
 
     if (panel->type->flag & PANELTYPE_RECREATE) {
-      panel->type->set_expand_flag_from_panel(C, panel);
+      short expand_flag;
+      short flag_index = 0;
+      get_panel_expand_flag(panel, &expand_flag, &flag_index);
+      panel->type->set_list_data_expand_flag(C, panel, expand_flag);
     }
   }
 }
@@ -285,7 +339,7 @@ static void panels_collapse_all(const bContext *C,
       }
     }
   }
-  set_list_panel_item_expansion_flag(C, region);
+  set_panels_list_data_expand_flag(C, region);
 }
 
 Panel *UI_panel_find_by_type(ListBase *lb, PanelType *pt)
@@ -1679,7 +1733,7 @@ static void ui_panel_drag_collapse(bContext *C,
       /* force panel to close */
       if (dragcol_data->was_first_open == true) {
         panel->flag |= (is_horizontal ? PNL_CLOSEDX : PNL_CLOSEDY);
-        set_list_panel_item_expansion_flag(C, region);
+        set_panels_list_data_expand_flag(C, region);
       }
       /* force panel to open */
       else {
@@ -1857,7 +1911,7 @@ static void ui_handle_panel_header(
         }
       }
 
-      set_list_panel_item_expansion_flag(C, region);
+      set_panels_list_data_expand_flag(C, region);
     }
 
     if (align) {
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 786ae002dc0..85614b2c8c4 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -1884,7 +1884,7 @@ void uiTemplateModifiers(uiLayout *UNUSED(layout), bContext *C)
         BLI_assert(panel_type != NULL);
 
         Panel *new_panel = UI_panel_add_recreate(sa, region, &region->panels, panel_type, i);
-        new_panel->type->set_expand_from_flag(C, new_panel);
+        UI_panel_set_expand_from_list_data(C, new_panel);
       }
     }
   }
diff --git a/source/blender/modifiers/intern/MOD_ui_common.c b/source/blender/modifiers/intern/MOD_ui_common.c
index d28ee8cfcf1..2af9f2065cd 100644
--- a/source/blender/modifiers/intern/MOD_ui_common.c
+++ b/source/blender/modifiers/intern/MOD_ui_common.c
@@ -78,59 +78,18 @@ static void modifier_reorder(bContext *C, Panel *panel, int new_index)
   WM_operator_properties_free(&props_ptr);
 }
 
-/* HANS-TODO: It looks like sub-subpanels don't remember their closed / open state. */
-static void panel_set_expand_from_flag_recursive(Panel *panel, short flag, short flag_index)
+static short get_modifier_expand_flag(const bContext *C, Panel *panel)
 {
-  bool open = (flag & (1 << flag_index));
-  if (open) {
-    panel->flag &= ~PNL_CLOSEDY;
-  }
-  else {
-    panel->flag |= PNL_CLOSEDY;
-  }
-  LISTBASE_FOREACH (Panel *, child, &panel->children) {
-    flag_index++;
-    panel_set_expand_from_flag_recursive(child, flag, flag_index);
-  }
-}
-
-static void panel_set_expand_from_flag(const bContext *C, Panel *panel)
-{
-  BLI_assert(panel->type != NULL);
-  BLI_assert(panel->type->flag & PANELTYPE_RECREATE);
-
   Object *ob = CTX_data_active_object(C);
   ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime.list_index);
-  short expand_flag = md->ui_expand_flag;
-
-  panel_set_expand_from_flag_recursive(panel, expand_flag, 0);
+  return md->ui_expand_flag;
 }
 
-static void modifier_expand_flag_set_recursive(Panel *panel, short *flag, short flag_index)
+static void set_modifier_expand_flag(const bContext *C, Panel *panel, short expand_flag)
 {
-  bool open = !(panel->flag & PNL_CLOSEDY);
-  if (open) {
-    *flag |= (1 << flag_index);
-  }
-  else {
-    *flag &= ~(1 << flag_index);
-  }
-  LISTBASE_FOREACH (Panel *, child, &panel->children) {
-    flag_index++;
-    modifier_expand_flag_set_recursive(child, flag, flag_index);
-  }
-}
-
-static void modifier_expand_flag_set_from_panel(const bContext *C, Panel *panel)
-{
-  BLI_assert(panel->type != NULL);
-  BLI_assert(panel->type->flag & PANELTYPE_RECREATE);
-
   Object *ob = CTX_data_active_object(C);
   ModifierData *md = BLI_findlink(&ob->modifiers, panel->runtime

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list