Fix T88058: Hover+return doesn't accept 0 as input

When the user hovered over a number input field, pressed Enter and then
typed in '0', confirming the input would always cancel the action. This
is because in this particular case `ui_textedit_begin` is called
instead of `ui_numedit_begin`. This function will not set
`data->startvalue` (leaving it at `0`) which will then trigger the
cancel in `ui_apply_but_NUM` which checks if the input changed (by
comparing the entered value with `data->startvalue`).

The fix makes sure that when `ui_textedit_begin` is called on a number
button, the `data->startvalue` is set correctly like in
`ui_numedit_begin`.

Breaking commit: rBSeb06ccc32462beaacbb114d6d0e450b6fc911047

Note: This also affects pressing tab to move to a new number field and
entering '0'. The fix will also cover this case.

Reviewed By: Severin, #user_interface

Maniphest Tasks: T88058

Differential Revision: https://developer.blender.org/D11168
This commit is contained in:
Falk David 2021-05-06 12:14:12 +02:00
parent 3e77f747c0
commit ec30cf0b74
Notes: blender-bot 2023-02-14 04:46:12 +01:00
Referenced by commit 071799d4fc, Fix T89265: Crash when tabbing through num inputs
Referenced by issue #89265, Use-after-free when tabbing through numeric inputs
Referenced by issue #88058, Editing a value with hover+return does not accept 0 as input
1 changed files with 16 additions and 10 deletions

View File

@ -477,6 +477,7 @@ static bool ui_do_but_extra_operator_icon(bContext *C,
static void ui_do_but_extra_operator_icons_mousemove(uiBut *but,
uiHandleButtonData *data,
const wmEvent *event);
static void ui_numedit_begin_set_values(uiBut *but, uiHandleButtonData *data);
#ifdef USE_DRAG_MULTINUM
static void ui_multibut_restore(bContext *C, uiHandleButtonData *data, uiBlock *block);
@ -3361,6 +3362,8 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data)
if (is_num_but) {
BLI_assert(data->is_str_dynamic == false);
ui_but_convert_to_unit_alt_name(but, data->str, data->maxlen);
ui_numedit_begin_set_values(but, data);
}
/* won't change from now on */
@ -3897,6 +3900,14 @@ static void ui_do_but_textedit_select(
/** \name Button Number Editing (various types)
* \{ */
static void ui_numedit_begin_set_values(uiBut *but, uiHandleButtonData *data)
{
data->startvalue = ui_but_value_get(but);
data->origvalue = data->startvalue;
data->value = data->origvalue;
but->editval = &data->value;
}
static void ui_numedit_begin(uiBut *but, uiHandleButtonData *data)
{
if (but->type == UI_BTYPE_CURVE) {
@ -3922,16 +3933,11 @@ static void ui_numedit_begin(uiBut *but, uiHandleButtonData *data)
but->editvec = data->vec;
}
else {
float softrange, softmin, softmax;
data->startvalue = ui_but_value_get(but);
data->origvalue = data->startvalue;
data->value = data->origvalue;
but->editval = &data->value;
softmin = but->softmin;
softmax = but->softmax;
softrange = softmax - softmin;
ui_numedit_begin_set_values(but, data);
float softmin = but->softmin;
float softmax = but->softmax;
float softrange = softmax - softmin;
if ((but->type == UI_BTYPE_NUM) && (ui_but_is_cursor_warp(but) == false)) {
uiButNumber *number_but = (uiButNumber *)but;