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
master
Philipp Oeser 4 years ago
parent 8c375113b5
commit 298d5eb669

@ -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);
}
}

@ -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))) {

@ -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;

Loading…
Cancel
Save