UI: Reduce text jumping for dynamic length values

Operators that use BKE_unit_value_as_string results in numbers with a
changing fractional part which frequently jumps around.

The issue became more noticeable with centrally aligned status text,
see !139507.

Address this by disabling stripping of trailing zeros for:

- `translate_dist_to_str`
  (used by object translation, extrude, rip region).
- Mesh bevel
- Inset faces
- Shrink/fatten
- Eyedropper depth sampling (e.g. in camera DOF)

Ref !140790
This commit is contained in:
John Kiril Swenson
2025-06-21 19:26:22 -05:00
committed by Campbell Barton
parent 8b05fb62f0
commit 8e934e7af0
5 changed files with 6 additions and 6 deletions

View File

@@ -281,7 +281,7 @@ static void depthdropper_depth_sample_pt(bContext *C,
BKE_unit_value_as_string(ddr->name,
sizeof(ddr->name),
double(*r_depth),
4,
-4,
B_UNIT_LENGTH,
scene->unit,
false);

View File

@@ -138,7 +138,7 @@ static void edbm_bevel_update_status_text(bContext *C, wmOperator *op)
else {
double offset_val = double(RNA_float_get(op->ptr, "offset"));
BKE_unit_value_as_string_scaled(
offset_str, NUM_STR_REP_LEN, offset_val, 3, B_UNIT_LENGTH, sce->unit, true);
offset_str, NUM_STR_REP_LEN, offset_val, -3, B_UNIT_LENGTH, sce->unit, true);
}
PropertyRNA *prop;

View File

@@ -86,14 +86,14 @@ static void edbm_inset_update_header(wmOperator *op, bContext *C)
BKE_unit_value_as_string(flts_str,
NUM_STR_REP_LEN,
RNA_float_get(op->ptr, "thickness"),
4,
-4,
B_UNIT_LENGTH,
sce->unit,
true);
BKE_unit_value_as_string(flts_str + NUM_STR_REP_LEN,
NUM_STR_REP_LEN,
RNA_float_get(op->ptr, "depth"),
4,
-4,
B_UNIT_LENGTH,
sce->unit,
true);

View File

@@ -120,7 +120,7 @@ static void applyShrinkFatten(TransInfo *t)
if (unit.system != USER_UNIT_NONE) {
char unit_str[64];
BKE_unit_value_as_string_scaled(
unit_str, sizeof(unit_str), distance, 4, B_UNIT_LENGTH, unit, true);
unit_str, sizeof(unit_str), distance, -4, B_UNIT_LENGTH, unit, true);
fmt::format_to(fmt::appender(str), "{}", unit_str);
}
else {

View File

@@ -164,7 +164,7 @@ static void translate_dist_to_str(char *r_str,
const UnitSettings *unit)
{
if (unit && (unit->system != USER_UNIT_NONE)) {
BKE_unit_value_as_string_scaled(r_str, r_str_maxncpy, val, 4, B_UNIT_LENGTH, *unit, false);
BKE_unit_value_as_string_scaled(r_str, r_str_maxncpy, val, -4, B_UNIT_LENGTH, *unit, false);
}
else {
/* Check range to prevent string buffer overflow. */