Fix button display clamping values

Displaying a button would clamp the value if the button was outside the range.
This could be OK in some cases,
however it's problematic with object dimensions which would re-scale objects on showing the panel.

Add `ui_but_update_edited` when its OK to modify the value.
This commit is contained in:
Campbell Barton 2016-02-23 09:55:16 +11:00
parent adab35ba02
commit e4e21480d6
Notes: blender-bot 2023-02-14 19:37:42 +01:00
Referenced by issue #47676, Blender 2.77 RC - Particle Hair Mode Issue
Referenced by issue #47649, Point light not working properly inside a volume while rendering with GPU
Referenced by issue blender/blender-addons#51930, Rigify FK to IK is broken (2.78 Pitchipoy and 2.79)
3 changed files with 48 additions and 19 deletions

View File

@ -2787,7 +2787,12 @@ void UI_block_emboss_set(uiBlock *block, char dt)
block->dt = dt;
}
void ui_but_update(uiBut *but)
/**
* \param but: Button to update.
* \param validate: When set, this function may change the button value.
* Otherwise treat the button value as read-only.
*/
void ui_but_update_ex(uiBut *but, const bool validate)
{
/* if something changed in the button */
double value = UI_BUT_VALUE_UNSET;
@ -2809,13 +2814,19 @@ void ui_but_update(uiBut *but)
case UI_BTYPE_NUM:
case UI_BTYPE_SCROLL:
case UI_BTYPE_NUM_SLIDER:
UI_GET_BUT_VALUE_INIT(but, value);
if (value < (double)but->hardmin) ui_but_value_set(but, but->hardmin);
else if (value > (double)but->hardmax) ui_but_value_set(but, but->hardmax);
if (validate) {
UI_GET_BUT_VALUE_INIT(but, value);
if (value < (double)but->hardmin) {
ui_but_value_set(but, but->hardmin);
}
else if (value > (double)but->hardmax) {
ui_but_value_set(but, but->hardmax);
}
/* max must never be smaller than min! Both being equal is allowed though */
BLI_assert(but->softmin <= but->softmax &&
but->hardmin <= but->hardmax);
/* max must never be smaller than min! Both being equal is allowed though */
BLI_assert(but->softmin <= but->softmax &&
but->hardmin <= but->hardmax);
}
break;
case UI_BTYPE_ICON_TOGGLE:
@ -2989,6 +3000,15 @@ void ui_but_update(uiBut *but)
/* text clipping moved to widget drawing code itself */
}
void ui_but_update(uiBut *but)
{
ui_but_update_ex(but, false);
}
void ui_but_update_edited(uiBut *but)
{
ui_but_update_ex(but, true);
}
void UI_block_align_begin(uiBlock *block)
{

View File

@ -822,7 +822,7 @@ static void ui_apply_but_BLOCK(bContext *C, uiBut *but, uiHandleButtonData *data
if (but->type == UI_BTYPE_MENU)
ui_but_value_set(but, data->value);
ui_but_update(but);
ui_but_update_edited(but);
ui_apply_but_func(C, but);
data->retval = but->retval;
data->applied = true;
@ -842,7 +842,9 @@ static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data)
else lvalue = UI_BITBUT_SET(lvalue, but->bitnr);
ui_but_value_set(but, (double)lvalue);
if (but->type == UI_BTYPE_ICON_TOGGLE || but->type == UI_BTYPE_ICON_TOGGLE_N) ui_but_update(but);
if (but->type == UI_BTYPE_ICON_TOGGLE || but->type == UI_BTYPE_ICON_TOGGLE_N) {
ui_but_update_edited(but);
}
}
else {
@ -851,7 +853,9 @@ static void ui_apply_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data)
if (ELEM(but->type, UI_BTYPE_TOGGLE_N, UI_BTYPE_ICON_TOGGLE_N, UI_BTYPE_CHECKBOX_N)) push = !push;
ui_but_value_set(but, (double)push);
if (but->type == UI_BTYPE_ICON_TOGGLE || but->type == UI_BTYPE_ICON_TOGGLE_N) ui_but_update(but);
if (but->type == UI_BTYPE_ICON_TOGGLE || but->type == UI_BTYPE_ICON_TOGGLE_N) {
ui_but_update_edited(but);
}
}
ui_apply_but_func(C, but);
@ -869,9 +873,11 @@ static void ui_apply_but_ROW(bContext *C, uiBlock *block, uiBut *but, uiHandleBu
ui_apply_but_func(C, but);
/* states of other row buttons */
for (bt = block->buttons.first; bt; bt = bt->next)
if (bt != but && bt->poin == but->poin && ELEM(bt->type, UI_BTYPE_ROW, UI_BTYPE_LISTROW))
ui_but_update(bt);
for (bt = block->buttons.first; bt; bt = bt->next) {
if (bt != but && bt->poin == but->poin && ELEM(bt->type, UI_BTYPE_ROW, UI_BTYPE_LISTROW)) {
ui_but_update_edited(bt);
}
}
data->retval = but->retval;
data->applied = true;
@ -883,7 +889,7 @@ static void ui_apply_but_TEX(bContext *C, uiBut *but, uiHandleButtonData *data)
return;
ui_but_string_set(C, but, data->str);
ui_but_update(but);
ui_but_update_edited(but);
/* give butfunc a copy of the original text too.
* feature used for bone renaming, channels, etc.
@ -914,10 +920,11 @@ static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data)
return;
}
}
else
else {
ui_but_value_set(but, data->value);
}
ui_but_update(but);
ui_but_update_edited(but);
ui_apply_but_func(C, but);
data->retval = but->retval;
@ -927,7 +934,7 @@ static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data)
static void ui_apply_but_VEC(bContext *C, uiBut *but, uiHandleButtonData *data)
{
ui_but_v3_set(but, data->vec);
ui_but_update(but);
ui_but_update_edited(but);
ui_apply_but_func(C, but);
data->retval = but->retval;
@ -1238,7 +1245,7 @@ static bool ui_drag_toggle_set_xy_xy(
if (is_set_but != is_set) {
UI_but_execute(C, but);
if (do_check) {
ui_but_update(but);
ui_but_update_edited(but);
}
changed = true;
}
@ -3462,7 +3469,7 @@ static void ui_do_but_textedit(bContext *C, uiBlock *block, uiBut *but, uiHandle
ui_apply_but(C, block, but, data, true);
}
else {
ui_but_update(but);
ui_but_update_edited(but);
}
but->changed = true;

View File

@ -484,7 +484,9 @@ extern uiButExtraIconType ui_but_icon_extra_get(uiBut *but);
extern void ui_but_default_set(struct bContext *C, const bool all, const bool use_afterfunc);
extern void ui_but_update_ex(uiBut *but, const bool validate);
extern void ui_but_update(uiBut *but);
extern void ui_but_update_edited(uiBut *but);
extern bool ui_but_is_float(const uiBut *but) ATTR_WARN_UNUSED_RESULT;
extern bool ui_but_is_bool(const uiBut *but) ATTR_WARN_UNUSED_RESULT;
extern bool ui_but_is_unit(const uiBut *but) ATTR_WARN_UNUSED_RESULT;