diff options
Diffstat (limited to 'source/blender/blenkernel/intern/unit.c')
-rw-r--r-- | source/blender/blenkernel/intern/unit.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c index 02134623a31..b31632f0234 100644 --- a/source/blender/blenkernel/intern/unit.c +++ b/source/blender/blenkernel/intern/unit.c @@ -268,7 +268,7 @@ static struct bUnitCollection buImperialAclCollection = {buImperialAclDef, 0, 0, /* Time. */ static struct bUnitDef buNaturalTimeDef[] = { /* Weeks? - probably not needed for Blender. */ - {"day", "days", "d", NULL, "Days", "DAYS", 90000.0, 0.0, B_UNIT_DEF_NONE}, + {"day", "days", "d", NULL, "Days", "DAYS", 86400.0, 0.0, B_UNIT_DEF_NONE}, {"hour", "hours", "hr", "h", "Hours", "HOURS", 3600.0, 0.0, B_UNIT_DEF_NONE}, {"minute", "minutes", "min", "m", "Minutes", "MINUTES", 60.0, 0.0, B_UNIT_DEF_NONE}, {"second", "seconds", "sec", "s", "Seconds", "SECONDS", 1.0, 0.0, B_UNIT_DEF_NONE}, /* Base unit. */ @@ -460,11 +460,20 @@ static size_t unit_as_string(char *str, } double value_conv = (value / unit->scalar) - unit->bias; + bool strip_skip = false; + + /* Negative precision is used to disable stripping of zeroes. + * This reduces text jumping when changing values. */ + if (prec < 0) { + strip_skip = true; + prec *= -1; + } /* Adjust precision to expected number of significant digits. * Note that here, we shall not have to worry about very big/small numbers, units are expected * to replace 'scientific notation' in those cases. */ prec -= integer_digits_d(value_conv); + CLAMP(prec, 0, 6); /* Convert to a string. */ @@ -478,12 +487,14 @@ static size_t unit_as_string(char *str, size_t i = len - 1; if (prec > 0) { - while (i > 0 && str[i] == '0') { /* 4.300 -> 4.3 */ - str[i--] = pad; - } + if (!strip_skip) { + while (i > 0 && str[i] == '0') { /* 4.300 -> 4.3 */ + str[i--] = pad; + } - if (i > 0 && str[i] == '.') { /* 10. -> 10 */ - str[i--] = pad; + if (i > 0 && str[i] == '.') { /* 10. -> 10 */ + str[i--] = pad; + } } } |