This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/editors/interface/interface_button_group.c
Hans Goudey cb6234fccf Property Search: Set panel expansion when tab changes
This commit makes the panel expansion set based on the search results
when the active tab in the properties editor changes. The multi-tab
search patch (D8859) actually doesn't handle this because it uses a
different code path.

This feature uncovered a subtle but fairly significant issue with the
implementation of property search (More details in T81113). Basically,
the search needed multiple redraws to properly display the expansion of
panels based on the search results. Because there is no animation of
panel expansion when switching tabs, the problem was exposed only now.

With this commit, hiding of "search only" buttons and panel size
calculation happens in a single final step of the panel layout pass.
The "search only" layout root flag is removed. Instead every button
inside a panel header is in a single "uiButtonGroup" marked with a
specific "in header" flag, an idea which could be generalized in the
future.

Differential Revision: https://developer.blender.org/D9006
2020-10-03 11:25:13 -05:00

95 lines
2.8 KiB
C

/*
* 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, short flag)
{
/* Don't create a new group if there is a "lock" on new groups. */
if (!BLI_listbase_is_empty(&block->button_groups)) {
uiButtonGroup *last_button_group = block->button_groups.last;
if (last_button_group->flag & UI_BUTTON_GROUP_LOCK) {
return;
}
}
uiButtonGroup *new_group = MEM_mallocN(sizeof(uiButtonGroup), __func__);
BLI_listbase_clear(&new_group->buttons);
new_group->flag = flag;
BLI_addtail(&block->button_groups, new_group);
}
void ui_button_group_add_but(uiBlock *block, uiBut *but)
{
if (BLI_listbase_is_empty(&block->button_groups)) {
ui_block_new_button_group(block, 0);
}
uiButtonGroup *current_button_group = block->button_groups.last;
/* 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);
}
/** \} */