This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/editors/interface/interface_button_group.cc
Hans Goudey 1eb90ee519 UI: Use vector instead of linked list for block button groups
This simplifies some memory management, ammortizes some of the many
small allocations when building UI layouts, and simplifies the code
that deals with the groups. `uiBlock` is no longer a trivial type.
In my testing this saved a few ms when drawing a large node tree.
2022-12-18 21:45:32 -06:00

53 lines
1.3 KiB
C++

/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup edinterface
*/
#include "BLI_listbase.h"
#include "MEM_guardedalloc.h"
#include "interface_intern.hh"
/* -------------------------------------------------------------------- */
/** \name Button Groups
* \{ */
void ui_block_new_button_group(uiBlock *block, uiButtonGroupFlag flag)
{
/* Don't create a new group if there is a "lock" on new groups. */
if (!block->button_groups.is_empty()) {
uiButtonGroup &last_group = block->button_groups.last();
if (last_group.flag & UI_BUTTON_GROUP_LOCK) {
return;
}
}
block->button_groups.append({});
block->button_groups.last().flag = flag;
}
void ui_button_group_add_but(uiBlock *block, uiBut *but)
{
if (block->button_groups.is_empty()) {
ui_block_new_button_group(block, uiButtonGroupFlag(0));
}
uiButtonGroup &current_group = block->button_groups.last();
current_group.buttons.append(but);
}
void ui_button_group_replace_but_ptr(uiBlock *block, const uiBut *old_but_ptr, uiBut *new_but)
{
for (uiButtonGroup &group : block->button_groups) {
std::replace_if(
group.buttons.begin(),
group.buttons.end(),
[&](const uiBut *ptr) { return ptr == old_but_ptr; },
new_but);
}
}
/** \} */