[1/4] UI Experiment: Hover Increment/Decrement More Button Types
This is loosely related to #136285, which allows changing numerical values while in text entry mode. Outside of that, just hovering over numerical inputs we are currently able to increment and decrement by Ctrl + Mouse Wheel. This works for integers, floats, sliders. Current code also allows cycling through expanded enums. This PR extends that so Ctrl + Mouse Wheel also changes toggles and checkboxes and also changes values inside of strings. --- [2/4] Don't increment string if blank --- [3/4] Use dynamic strings. --- [4/4] Use ui_but_string_get_ex and ui_but_string_get_dynamic Ref: !138344
This commit is contained in:
committed by
Campbell Barton
parent
a1efa167aa
commit
5b2fe07f64
@@ -4908,6 +4908,48 @@ static int ui_do_but_TEX(
|
||||
return WM_UI_HANDLER_BREAK;
|
||||
}
|
||||
}
|
||||
else if (ELEM(event->type, WHEELUPMOUSE, WHEELDOWNMOUSE) && (event->modifier & KM_CTRL) &&
|
||||
!but->drawstr.empty())
|
||||
{
|
||||
/* Retrieve the string. */
|
||||
char *but_string;
|
||||
int str_len = ui_but_string_get_maxncpy(but);
|
||||
bool no_zero_strip = false;
|
||||
if (str_len != 0) {
|
||||
but_string = MEM_calloc_arrayN<char>(str_len, __func__);
|
||||
ui_but_string_get_ex(
|
||||
but, but_string, str_len, UI_PRECISION_FLOAT_MAX, true, &no_zero_strip);
|
||||
}
|
||||
else {
|
||||
but_string = ui_but_string_get_dynamic(but, &str_len);
|
||||
}
|
||||
|
||||
/* More space for an added digit. */
|
||||
str_len += 2;
|
||||
char *head = (char *)MEM_callocN(sizeof(char) * str_len, __func__);
|
||||
char *tail = (char *)MEM_callocN(sizeof(char) * str_len, __func__);
|
||||
ushort digits;
|
||||
|
||||
/* Decode the string, parsing head, digits, tail. */
|
||||
int num = BLI_path_sequence_decode(but_string, head, str_len, tail, str_len, &digits);
|
||||
MEM_freeN(but_string);
|
||||
if (num == 0 && digits == 0) {
|
||||
BLI_str_rstrip_digits(head);
|
||||
}
|
||||
|
||||
/* Increase or decrease the value. */
|
||||
num += (event->type == WHEELUPMOUSE) ? 1 : -1;
|
||||
|
||||
/* Encode the new string with the changed value. */
|
||||
char *string = (char *)MEM_callocN(sizeof(char) * str_len, __func__);
|
||||
BLI_path_sequence_encode(string, str_len, head, tail, digits, num);
|
||||
ui_but_set_string_interactive(C, but, string);
|
||||
MEM_freeN(string);
|
||||
MEM_freeN(head);
|
||||
MEM_freeN(tail);
|
||||
|
||||
return WM_UI_HANDLER_BREAK;
|
||||
}
|
||||
}
|
||||
else if (data->state == BUTTON_STATE_TEXT_EDITING) {
|
||||
return ui_do_but_textedit(C, block, but, data, event);
|
||||
@@ -4966,8 +5008,21 @@ static int ui_do_but_TOG(bContext *C, uiBut *but, uiHandleButtonData *data, cons
|
||||
return WM_UI_HANDLER_BREAK;
|
||||
}
|
||||
if (ELEM(event->type, MOUSEPAN, WHEELDOWNMOUSE, WHEELUPMOUSE) && (event->modifier & KM_CTRL)) {
|
||||
/* Support Ctrl-Wheel to cycle values on expanded enum rows. */
|
||||
if (but->type == UI_BTYPE_ROW) {
|
||||
if (ELEM(but->type,
|
||||
UI_BTYPE_TOGGLE,
|
||||
UI_BTYPE_TOGGLE_N,
|
||||
UI_BTYPE_ICON_TOGGLE,
|
||||
UI_BTYPE_ICON_TOGGLE_N,
|
||||
UI_BTYPE_BUT_TOGGLE,
|
||||
UI_BTYPE_CHECKBOX,
|
||||
UI_BTYPE_CHECKBOX_N))
|
||||
{
|
||||
/* Support Ctrl-Wheel to cycle toggles and checkboxes. */
|
||||
button_activate_state(C, but, BUTTON_STATE_EXIT);
|
||||
return WM_UI_HANDLER_BREAK;
|
||||
}
|
||||
else if (but->type == UI_BTYPE_ROW) {
|
||||
/* Support Ctrl-Wheel to cycle values on expanded enum rows. */
|
||||
int type = event->type;
|
||||
int val = event->val;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user