Blender  V3.3
interface_button_group.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BLI_listbase.h"
8 
9 #include "MEM_guardedalloc.h"
10 
11 #include "interface_intern.h"
12 
13 /* -------------------------------------------------------------------- */
18 {
19  /* Don't create a new group if there is a "lock" on new groups. */
20  if (!BLI_listbase_is_empty(&block->button_groups)) {
21  uiButtonGroup *last_button_group = block->button_groups.last;
22  if (last_button_group->flag & UI_BUTTON_GROUP_LOCK) {
23  return;
24  }
25  }
26 
27  uiButtonGroup *new_group = MEM_mallocN(sizeof(uiButtonGroup), __func__);
28  BLI_listbase_clear(&new_group->buttons);
29  new_group->flag = flag;
30  BLI_addtail(&block->button_groups, new_group);
31 }
32 
34 {
35  if (BLI_listbase_is_empty(&block->button_groups)) {
36  ui_block_new_button_group(block, 0);
37  }
38 
39  uiButtonGroup *current_button_group = block->button_groups.last;
40 
41  /* We can't use the button directly because adding it to
42  * this list would mess with its `prev` and `next` pointers. */
43  LinkData *button_link = BLI_genericNodeN(but);
44  BLI_addtail(&current_button_group->buttons, button_link);
45 }
46 
47 static void button_group_free(uiButtonGroup *button_group)
48 {
49  BLI_freelistN(&button_group->buttons);
50  MEM_freeN(button_group);
51 }
52 
54 {
55  LISTBASE_FOREACH_MUTABLE (uiButtonGroup *, button_group, &block->button_groups) {
56  button_group_free(button_group);
57  }
58 }
59 
60 void ui_button_group_replace_but_ptr(uiBlock *block, const void *old_but_ptr, uiBut *new_but)
61 {
62  LISTBASE_FOREACH (uiButtonGroup *, button_group, &block->button_groups) {
63  LISTBASE_FOREACH (LinkData *, link, &button_group->buttons) {
64  if (link->data == old_but_ptr) {
65  link->data = new_but;
66  return;
67  }
68  }
69  }
70 }
71 
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:269
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
Definition: BLI_listbase.h:354
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
Definition: BLI_listbase.h:273
struct LinkData * BLI_genericNodeN(void *data)
Definition: listbase.c:842
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:466
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:80
Read Guarded memory(de)allocation.
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)
void ui_block_new_button_group(uiBlock *block, uiButtonGroupFlag flag)
void ui_button_group_add_but(uiBlock *block, uiBut *but)
static void button_group_free(uiButtonGroup *button_group)
uiButtonGroupFlag
@ UI_BUTTON_GROUP_LOCK
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
void * last
Definition: DNA_listBase.h:31
ListBase button_groups