WIP: UI: dont run update functions if button values did not change #115831

Draft
Philipp Oeser wants to merge 2 commits from lichtwerk/blender:40009_b into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
3 changed files with 27 additions and 12 deletions

View File

@ -2610,8 +2610,13 @@ double ui_but_value_get(uiBut *but)
return value;
}
void ui_but_value_set(uiBut *but, double value)
bool ui_but_value_set(uiBut *but, double value)
{
if (ui_but_value_get(but) == value) {
/* Value did not change. */
return false;
}
/* Value is a HSV value: convert to RGB. */
if (but->rnaprop) {
PropertyRNA *prop = but->rnaprop;
@ -2704,6 +2709,8 @@ void ui_but_value_set(uiBut *but, double value)
}
ui_but_update_select_flag(but, &value);
return true;
}
int ui_but_string_get_maxncpy(uiBut *but)

View File

@ -497,6 +497,8 @@ struct uiAfterFunc {
PointerRNA rnapoin;
PropertyRNA *rnaprop;
/* If the value did not change we can skip the update. */
bool rna_skip_update;
void *search_arg;
uiFreeArgFunc search_arg_free_fn;
@ -826,7 +828,7 @@ static bool ui_afterfunc_check(const uiBlock *block, const uiBut *but)
* handling is done, i.e. menus are closed, in order to avoid conflicts
* with these functions removing the buttons we are working with.
*/
static void ui_apply_but_func(bContext *C, uiBut *but)
static void ui_apply_but_func(bContext *C, uiBut *but, const bool rna_skip_update = false)
{
uiBlock *block = but->block;
if (!ui_afterfunc_check(block, but)) {
@ -875,6 +877,7 @@ static void ui_apply_but_func(bContext *C, uiBut *but)
after->rnapoin = but->rnapoin;
after->rnaprop = but->rnaprop;
after->rna_skip_update = rna_skip_update;
if (but->type == UI_BTYPE_SEARCH_MENU) {
uiButSearch *search_but = (uiButSearch *)but;
@ -1048,7 +1051,7 @@ static void ui_apply_but_funcs_after(bContext *C)
WM_operator_properties_free(&opptr);
}
if (after.rnapoin.data) {
if (after.rnapoin.data && !after.rna_skip_update) {
RNA_property_update(C, &after.rnapoin, after.rnaprop);
}
@ -1117,8 +1120,8 @@ static void ui_apply_but_BUT(bContext *C, uiBut *but, uiHandleButtonData *data)
static void ui_apply_but_BUTM(bContext *C, uiBut *but, uiHandleButtonData *data)
{
ui_but_value_set(but, but->hardmin);
ui_apply_but_func(C, but);
const bool changed = ui_but_value_set(but, but->hardmin);
ui_apply_but_func(C, but, !changed);
data->retval = but->retval;
data->applied = true;
@ -1160,9 +1163,9 @@ static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data)
static void ui_apply_but_ROW(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data)
{
ui_but_value_set(but, but->hardmax);
const bool changed = ui_but_value_set(but, but->hardmax);
ui_apply_but_func(C, but);
ui_apply_but_func(C, but, !changed);
/* states of other row buttons */
LISTBASE_FOREACH (uiBut *, bt, &block->buttons) {
@ -1273,8 +1276,8 @@ static void ui_apply_but_TAB(bContext *C, uiBut *but, uiHandleButtonData *data)
ui_but_update_edited(but);
}
else {
ui_but_value_set(but, but->hardmax);
ui_apply_but_func(C, but);
const bool changed = ui_but_value_set(but, but->hardmax);
ui_apply_but_func(C, but, !changed);
}
data->retval = but->retval;
@ -1283,6 +1286,8 @@ static void ui_apply_but_TAB(bContext *C, uiBut *but, uiHandleButtonData *data)
static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data)
{
bool changed = true;
if (data->str) {
/* This is intended to avoid unnecessary updates when the value stays the same, however there
* are issues with the current implementation. It does not work with multi-button editing
@ -1310,11 +1315,11 @@ static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data)
}
}
else {
ui_but_value_set(but, data->value);
changed = ui_but_value_set(but, data->value);
}
ui_but_update_edited(but);
ui_apply_but_func(C, but);
ui_apply_but_func(C, but, !changed);
data->retval = but->retval;
data->applied = true;

View File

@ -690,7 +690,10 @@ void ui_block_add_dynamic_listener(uiBlock *block,
uiBut *ui_but_change_type(uiBut *but, eButType new_type);
double ui_but_value_get(uiBut *but);
void ui_but_value_set(uiBut *but, double value);
/**
* Returns false if the value did not change.
*/
bool ui_but_value_set(uiBut *but, double value);
/**
* For picker, while editing HSV.
*/