diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2017-07-31 16:40:26 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2017-07-31 16:43:14 +0300 |
commit | b6cb7b2c92bfa3fa111e4e363f723baadc56ed3c (patch) | |
tree | 1e65eb9ee25dd09193edb004c00ac12eddde4a4e /source/blender/editors/interface/interface.c | |
parent | 09eac0159db81a07268a1246ed88fd9257a7a04f (diff) |
Fix two issues with recent changes to number display while editing them.
* Numbers with units (especially, angles) where not handled correctly
regarding number of significant digits (spotted by @brecht in T52222
comment, thanks).
* Zero value has no valid log, need to take that into account!
Diffstat (limited to 'source/blender/editors/interface/interface.c')
-rw-r--r-- | source/blender/editors/interface/interface.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index 0dc7c6ccbec..a013f75f9e8 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2226,9 +2226,9 @@ void ui_but_string_get_ex(uiBut *but, char *str, const size_t maxlen, const int ui_get_but_string_unit(but, str, maxlen, value, false, float_precision); } else { - const int prec = (float_precision == -1) ? ui_but_calc_float_precision(but, value) : float_precision; + int prec = (float_precision == -1) ? ui_but_calc_float_precision(but, value) : float_precision; if (use_exp_float) { - const int l10 = (int)log10(fabs(value)); + const int l10 = (value == 0.0f) ? 0 : (int)log10(fabs(value)); if (l10 < -6 || l10 > 12) { BLI_snprintf(str, maxlen, "%.*g", prec, value); if (r_use_exp_float) { @@ -2236,7 +2236,9 @@ void ui_but_string_get_ex(uiBut *but, char *str, const size_t maxlen, const int } } else { - BLI_snprintf(str, maxlen, "%.*f", prec - l10 + (int)(l10 < 0), value); + prec -= l10 + (int)(l10 < 0); + CLAMP(prec, 0, UI_PRECISION_FLOAT_MAX); + BLI_snprintf(str, maxlen, "%.*f", prec, value); } } else { |