Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2020-10-03 01:00:41 +0300
committerHans Goudey <h.goudey@me.com>2020-10-03 01:00:56 +0300
commit3eab2248c346081b76c8379656aeff2a473a3da4 (patch)
treebfcc3cb07bf66a6a4ad3916baabea18157480048 /source/blender/editors/interface/interface_button_group.c
parent28a2c84948cc2296dd86c5ddfc208035328a7b67 (diff)
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.
Diffstat (limited to 'source/blender/editors/interface/interface_button_group.c')
-rw-r--r--source/blender/editors/interface/interface_button_group.c84
1 files changed, 84 insertions, 0 deletions
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);
+}
+
+/** \} */