diff options
author | Philipp Oeser <info@graphics-engineer.com> | 2020-07-09 16:38:31 +0300 |
---|---|---|
committer | Philipp Oeser <info@graphics-engineer.com> | 2020-07-31 11:47:52 +0300 |
commit | 298d5eb66916c6379f2a4203dd7502dae7db8939 (patch) | |
tree | d7c9488f56e6db7a5936c49029a8ea4dec3f6bae /source | |
parent | 8c375113b5c317e6cf77889714b9fd248dc9c871 (diff) |
UI: fix buttons ranges not properly updated when tabbing to next/previous
button
This was reported for the FCurve modifier restrict ranges, but might fail
elsewhere, too. Reason is that the post_but has its range (hardmin/
hardmax etc) set before the updates to the active button take place, so
changes here dont end up on the post_but (even though the RNA range
function is properly called for a new defined button - new one is not the
same as the post_but though).
Now update the ranges on the post_but when that gets active.
Fixes T78763
Maniphest Tasks: T78763
Differential Revision: https://developer.blender.org/D8265
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/interface/interface.c | 34 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 5 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_intern.h | 3 |
3 files changed, 40 insertions, 2 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 12ff147b0a1..adb2e0e3b23 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -3079,8 +3079,38 @@ static double soft_range_round_down(double value, double max) return newmax; } +void ui_but_range_set_hard(uiBut *but) +{ + if (but->rnaprop) { + const PropertyType type = RNA_property_type(but->rnaprop); + double hardmin, hardmax; + + /* clamp button range to something reasonable in case + * we get -inf/inf from RNA properties */ + if (type == PROP_INT) { + int imin, imax; + + RNA_property_int_range(&but->rnapoin, but->rnaprop, &imin, &imax); + hardmin = (imin == INT_MIN) ? -1e4 : imin; + hardmax = (imin == INT_MAX) ? 1e4 : imax; + } + else if (type == PROP_FLOAT) { + float fmin, fmax; + + RNA_property_float_range(&but->rnapoin, but->rnaprop, &fmin, &fmax); + hardmin = (fmin == -FLT_MAX) ? (float)-1e4 : fmin; + hardmax = (fmax == FLT_MAX) ? (float)1e4 : fmax; + } + else { + return; + } + but->hardmin = hardmin; + but->hardmax = hardmax; + } +} + /* note: this could be split up into functions which handle arrays and not */ -static void ui_set_but_soft_range(uiBut *but) +void ui_but_range_set_soft(uiBut *but) { /* ideally we would not limit this but practically, its more than * enough worst case is very long vectors wont use a smart soft-range @@ -3484,7 +3514,7 @@ static void ui_but_update_ex(uiBut *but, const bool validate) /* only update soft range while not editing */ if (!ui_but_is_editing(but)) { if ((but->rnaprop != NULL) || (but->poin && (but->pointype & UI_BUT_POIN_TYPES))) { - ui_set_but_soft_range(but); + ui_but_range_set_soft(but); } } diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 88ad5d8fec1..b94224f3604 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -8900,6 +8900,11 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but) /* for jumping to the next button with tab while text editing */ if (post_but) { + /* The post_but still has previous ranges (without the changes in active button considered), + * needs refreshing the ranges. */ + ui_but_range_set_soft(post_but); + ui_but_range_set_hard(post_but); + button_activate_init(C, region, post_but, post_type); } else if (!((event->type == EVT_BUT_CANCEL) && (event->val == 1))) { diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index 249134c6abf..3b39e7d2161 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -537,6 +537,9 @@ extern void ui_but_rna_menu_convert_to_panel_type(struct uiBut *but, const char extern void ui_but_rna_menu_convert_to_menu_type(struct uiBut *but, const char *menu_type); extern bool ui_but_menu_draw_as_popover(const uiBut *but); +void ui_but_range_set_hard(uiBut *but); +void ui_but_range_set_soft(uiBut *but); + 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; |