GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
feat(treelist): show unit-suffixed lengths as lengths
A leaf whose string value parses as `units::Len` ("2mm", what
`(mm)2.0` reads as through kdl_to_json) renders as `2 mm` with its
unit as the type column, instead of a quoted string — so cce-data-editor's
tree reads lengths the way the file spells them.
Co-Authored-By: Claude Fable 5.1 <[email protected]>
src/widget/container/treelist.rs | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/widget/container/treelist.rs b/src/widget/container/treelist.rs
index 373493c..9e92fd8 100644
--- a/src/widget/container/treelist.rs
+++ b/src/widget/container/treelist.rs
@@ -1718,7 +1718,14 @@ impl TreeList {
}
}
TreeElement::Leaf { name, indent, val, original_idx, .. } => {
- let val_str = serde_json::to_string(val).unwrap_or_default();
+ // A unit-suffixed string (`"2mm"`, what `(mm)2.0` reads
+ // as) shows as the length it is — `2 mm` — not a quoted
+ // string; its unit is its type below.
+ let len = val.as_str().and_then(crate::units::Len::parse);
+ let val_str = match len {
+ Some(l) => format!("{} {}", crate::units::fmt_num(l.value), l.unit.suffix()),
+ None => serde_json::to_string(val).unwrap_or_default(),
+ };
// Generous shaping cap only — the column bounds clip the
// visible text at the list edge. (char-based: the old
// byte slice could panic on multibyte text.)
@@ -1766,6 +1773,8 @@ impl TreeList {
Some("keybind")
} else if name == "font" || name.ends_with("_font") || name.ends_with(".font") {
Some("font")
+ } else if let Some(l) = len {
+ Some(l.unit.suffix())
} else {
None
}