From 636289b755f6cea1167440602a06aedf5cc2e1d5 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 1 Aug 2017 16:35:07 +0200 Subject: Fix multi-units drawing re precision handling. This is still far from prefect, but yet much better than what we had so far (more consistent with inheritent precision available in floats). Note that this fixes some (currently commented out) units unittests, and requires adjusting some others, will be done in next commit. --- source/blender/editors/interface/interface.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source/blender/editors/interface/interface.c') diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index a013f75f9e8..7ab4e1d9c35 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -2228,20 +2228,24 @@ void ui_but_string_get_ex(uiBut *but, char *str, const size_t maxlen, const int else { int prec = (float_precision == -1) ? ui_but_calc_float_precision(but, value) : float_precision; if (use_exp_float) { - const int l10 = (value == 0.0f) ? 0 : (int)log10(fabs(value)); - if (l10 < -6 || l10 > 12) { + const int int_digits_num = integer_digits_f(value); + if (int_digits_num < -6 || int_digits_num > 12) { BLI_snprintf(str, maxlen, "%.*g", prec, value); if (r_use_exp_float) { *r_use_exp_float = true; } } else { - prec -= l10 + (int)(l10 < 0); + prec -= int_digits_num; CLAMP(prec, 0, UI_PRECISION_FLOAT_MAX); BLI_snprintf(str, maxlen, "%.*f", prec, value); } } else { +#if 0 /* TODO, but will likely break some stuff, so better after 2.79 release. */ + prec -= int_digits_num; + CLAMP(prec, 0, UI_PRECISION_FLOAT_MAX); +#endif BLI_snprintf(str, maxlen, "%.*f", prec, value); } } -- cgit v1.2.3