[Bf-blender-cvs] [3eab2248c34] master: UI: Move button groups from layout to block level

Hans Goudey noreply at git.blender.org
Sat Oct 3 00:02:08 CEST 2020


Commit: 3eab2248c346081b76c8379656aeff2a473a3da4
Author: Hans Goudey
Date:   Fri Oct 2 17:00:41 2020 -0500
Branches: master
https://developer.blender.org/rB3eab2248c346081b76c8379656aeff2a473a3da4

UI: Move button groups from layout to block level

For a future patch (D9006) we need these groups for longer than just the
the layout process, in order to differentiate buttons in panel headers.
It may also be helpful in the future to have a way to access related
buttons added in the same uiLayout.prop call. With this commit, the
groups are stored in and destructed with the uiBlock.

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

M	source/blender/editors/interface/CMakeLists.txt
M	source/blender/editors/interface/interface.c
A	source/blender/editors/interface/interface_button_group.c
M	source/blender/editors/interface/interface_intern.h
M	source/blender/editors/interface/interface_layout.c

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

diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt
index 680cf3ea01a..e7b4402d1f1 100644
--- a/source/blender/editors/interface/CMakeLists.txt
+++ b/source/blender/editors/interface/CMakeLists.txt
@@ -38,6 +38,7 @@ set(SRC
   interface.c
   interface_align.c
   interface_anim.c
+  interface_button_group.c
   interface_context_menu.c
   interface_draw.c
   interface_eyedropper.c
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 85097a80b53..d06e3fd718d 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -3392,6 +3392,8 @@ void UI_block_free(const bContext *C, uiBlock *block)
   BLI_freelistN(&block->saferct);
   BLI_freelistN(&block->color_pickers.list);
 
+  ui_block_free_button_groups(block);
+
   MEM_freeN(block);
 }
 
@@ -3473,6 +3475,9 @@ uiBlock *UI_block_begin(const bContext *C, ARegion *region, const char *name, ch
   block->emboss = emboss;
   block->evil_C = (void *)C; /* XXX */
 
+  BLI_listbase_clear(&block->button_groups);
+  ui_block_new_button_group(block);
+
   if (scene) {
     /* store display device name, don't lookup for transformations yet
      * block could be used for non-color displays where looking up for transformation
@@ -3944,7 +3949,7 @@ uiBut *ui_but_change_type(uiBut *but, eButType new_type)
       const bool found_layout = ui_layout_replace_but_ptr(but->layout, old_but_ptr, but);
       BLI_assert(found_layout);
       UNUSED_VARS_NDEBUG(found_layout);
-      ui_button_group_replace_but_ptr(but->layout, old_but_ptr, but);
+      ui_button_group_replace_but_ptr(uiLayoutGetBlock(but->layout), old_but_ptr, but);
     }
   }
 
diff --git a/source/blender/editors/interface/interface_button_group.c b/source/blender/editors/interface/interface_button_group.c
new file mode 100644
index 00000000000..e890d0136cb
--- /dev/null
+++ b/source/blender/editors/interface/interface_button_group.c
@@ -0,0 +1,84 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup edinterface
+ */
+
+#include "BLI_listbase.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "interface_intern.h"
+
+/* -------------------------------------------------------------------- */
+/** \name Button Groups
+ * \{ */
+
+/**
+ * Every function that adds a set of buttons must create another group,
+ * then #ui_def_but adds buttons to the current group (the last).
+ */
+void ui_block_new_button_group(uiBlock *block)
+{
+  uiButtonGroup *new_group = MEM_mallocN(sizeof(uiButtonGroup), __func__);
+  BLI_listbase_clear(&new_group->buttons);
+  BLI_addtail(&block->button_groups, new_group);
+}
+
+void ui_button_group_add_but(uiBlock *block, uiBut *but)
+{
+  BLI_assert(block != NULL);
+
+  uiButtonGroup *current_button_group = block->button_groups.last;
+  BLI_assert(current_button_group != NULL);
+
+  /* We can't use the button directly because adding it to
+   * this list would mess with its prev and next pointers. */
+  LinkData *button_link = BLI_genericNodeN(but);
+  BLI_addtail(&current_button_group->buttons, button_link);
+}
+
+static void button_group_free(uiButtonGroup *button_group)
+{
+  BLI_freelistN(&button_group->buttons);
+  MEM_freeN(button_group);
+}
+
+void ui_block_free_button_groups(uiBlock *block)
+{
+  LISTBASE_FOREACH_MUTABLE (uiButtonGroup *, button_group, &block->button_groups) {
+    button_group_free(button_group);
+  }
+}
+
+/* This function should be removed whenever #ui_layout_replace_but_ptr is removed. */
+void ui_button_group_replace_but_ptr(uiBlock *block, const void *old_but_ptr, uiBut *new_but)
+{
+  LISTBASE_FOREACH (uiButtonGroup *, button_group, &block->button_groups) {
+    LISTBASE_FOREACH (LinkData *, link, &button_group->buttons) {
+      if (link->data == old_but_ptr) {
+        link->data = new_but;
+        return;
+      }
+    }
+  }
+
+  /* The button should be in a group. */
+  BLI_assert(false);
+}
+
+/** \} */
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index 194726b1347..5a5e962e2bc 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -417,6 +417,17 @@ enum eBlockContentHints {
   UI_BLOCK_CONTAINS_SUBMENU_BUT = (1 << 0),
 };
 
+/**
+ * A group of button references, used by property search to keep track of sets of buttons that
+ * should be searched together. For example, in property split layouts number buttons and their
+ * labels (and even their decorators) are separate buttons, but they must be searched and
+ * highlighted together.
+ */
+typedef struct uiButtonGroup {
+  void *next, *prev;
+  ListBase buttons; /* #LinkData with #uiBut data field. */
+} uiButtonGroup;
+
 struct uiBlock {
   uiBlock *next, *prev;
 
@@ -426,6 +437,8 @@ struct uiBlock {
 
   ListBase butstore; /* UI_butstore_* runtime function */
 
+  ListBase button_groups; /* #uiButtonGroup. */
+
   ListBase layouts;
   struct uiLayout *curlayout;
 
@@ -999,7 +1012,6 @@ void ui_resources_free(void);
 /* interface_layout.c */
 void ui_layout_add_but(uiLayout *layout, uiBut *but);
 bool ui_layout_replace_but_ptr(uiLayout *layout, const void *old_but_ptr, uiBut *new_but);
-void ui_button_group_replace_but_ptr(uiLayout *layout, const void *old_but_ptr, uiBut *new_but);
 uiBut *ui_but_add_search(uiBut *but,
                          PointerRNA *ptr,
                          PropertyRNA *prop,
@@ -1010,6 +1022,12 @@ void ui_layout_list_set_labels_active(uiLayout *layout);
 void ui_item_menutype_func(struct bContext *C, struct uiLayout *layout, void *arg_mt);
 void ui_item_paneltype_func(struct bContext *C, struct uiLayout *layout, void *arg_pt);
 
+/* interface_button_group.c */
+void ui_block_new_button_group(uiBlock *block);
+void ui_button_group_add_but(uiBlock *block, uiBut *but);
+void ui_button_group_replace_but_ptr(uiBlock *block, const void *old_but_ptr, uiBut *new_but);
+void ui_block_free_button_groups(uiBlock *block);
+
 /* interface_align.c */
 bool ui_but_can_align(const uiBut *but) ATTR_WARN_UNUSED_RESULT;
 int ui_but_align_opposite_to_area_align_get(const struct ARegion *region) ATTR_WARN_UNUSED_RESULT;
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index ab641dc74fe..a4b6004687f 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -79,17 +79,6 @@
 
 /* uiLayoutRoot */
 
-/**
- * A group of button references, used by property search to keep track of sets of buttons that
- * should be searched together. For example, in property split layouts number buttons and their
- * labels (and even their decorators) are separate buttons, but they must be searched and
- * highlighted together.
- */
-typedef struct uiButtonGroup {
-  void *next, *prev;
-  ListBase buttons; /* #LinkData with #uiBut data field. */
-} uiButtonGroup;
-
 typedef struct uiLayoutRoot {
   struct uiLayoutRoot *next, *prev;
 
@@ -103,8 +92,6 @@ typedef struct uiLayoutRoot {
    */
   bool search_only;
 
-  ListBase button_groups; /* #uiButtonGroup. */
-
   int emw, emh;
   int padding;
 
@@ -430,58 +417,6 @@ static void ui_item_move(uiItem *item, int delta_xmin, int delta_xmax)
 
 /** \} */
 
-/* -------------------------------------------------------------------- */
-/** \name Button Groups
- * \{ */
-
-/**
- * Every function that adds a set of buttons must create another group,
- * then #ui_def_but adds buttons to the current group (the last).
- */
-static void layout_root_new_button_group(uiLayoutRoot *root)
-{
-  uiButtonGroup *new_group = MEM_mallocN(sizeof(uiButtonGroup), __func__);
-  BLI_listbase_clear(&new_group->buttons);
-  BLI_addtail(&root->button_groups, new_group);
-}
-
-static void button_group_add_but(uiLayoutRoot *root, uiBut *but)
-{
-  BLI_assert(root != NULL);
-
-  uiButtonGroup *current_button_group = root->button_groups.last;
-  BLI_assert(current_button_group != NULL);
-
-  /* We can't use the button directly because adding it to
-   * this list would mess with its prev and next pointers. */
-  LinkData *button_link = BLI_genericNodeN(but);
-  BLI_addtail(&current_button_group->buttons, button_link);
-}
-
-static void button_group_free(uiButtonGroup *button_group)
-{
-  BLI_freelistN(&button_group->buttons);
-  MEM_freeN(button_group);
-}
-
-/* This function should be removed whenever #ui_layout_replace_but_ptr is removed. */
-void ui_button_group_replace_but_ptr(uiLayout *layout, const void *old_but_ptr, uiBut *new_but)
-{
-  LISTBASE_FOREACH (uiButtonGroup *, button_group, &layout->root->button_groups) {
-    LISTBASE_FOREACH (LinkData *, link, &button_group->buttons) {
-      if (link->data == old_but_ptr) {
-        link->data = new_but;
-        return;
-      }
-    }
-  }
-
-  /* The button should be in a group. */
-  BLI_assert(false);
-}
-
-/** \} */
-
 /* -------------------------------------------------------------------- */
 /** \name Special RNA Items
  * \{ */
@@ -2051,7 +1986,7 @@ void uiItemFullR(uiLayout *layout,
 #endif /* UI_PROP_DECORATE */
 
   UI_block_layout_set_current(block, layout);
-  layout_root_new_button_group(layout->root);
+  ui_block_new_button_group(block);
 
   /* retrieve info */
   const PropertyType type = RNA_property_type(prop);
@@ -2789,7 +2724,7 @@ void uiItemPointerR_prop(uiLayout *layout,
 {
   const bool use_prop_sep = ((layout->item.flag & UI_ITE

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list