Thing 2.0: cells text (terminal widths and line breaking behind Measure) #23

Merged
eureka merged 6 commits from hands/thing2-cells-text into main 2026-11-28 09:01:01 +00:00
Showing only changes of commit 441c9dc549 - Show all commits

cells tests: Image extent is rounded up

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Meta Vens 2026-11-28 09:01:13 +01:00

View file

@ -1,10 +1,11 @@
//! The Cells text engine: pinned widths, sanitizing, wrapping, and that `measure` and `text`
//! agree. Vectors were checked against unicode-width 0.2.3 (ambiguous width narrow).
use thing_contract::NodeId;
use thing_contract::{AssetEntry, NodeId};
use thing_core::bind::Bound;
use thing_core::layout::{Avail, Constraint, Leaf, Measure, Run, TextRequest};
use thing_core::text::{CellMeasure, CellText};
use thing_testkit::build::count;
fn widths(s: &str) -> Vec<u8> {
CellText::new(s).clusters().map(|(_, w)| w).collect()
@ -160,6 +161,8 @@ fn controls_have_shipped_sizes() {
assert_eq!(m.measure(&Leaf::Slider { node: &node }, c), (20.0, 1.0));
assert_eq!(m.measure(&Leaf::Select { node: &node, selected: &text }, c), (20.0, 1.0));
assert_eq!(m.measure(&Leaf::Image { node: &node, asset: &Bound::Absent }, c), (0.0, 0.0));
let entry = AssetEntry { id: "a".into(), media_type: "image/png".into(), uri: "asset://a".into(), width: count(17), height: count(33) };
assert_eq!(m.measure(&Leaf::Image { node: &node, asset: &Bound::Asset(entry) }, c), (3.0, 3.0), "extent over (8, 16), rounded up");
}
/// Random strings, every control among them, never panic and never put a control character into