From 728957f94b5b8d1c47fb4f42f493cdcae712f27a Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 28 Nov 2026 16:01:50 +0100 Subject: [PATCH] thing-core: the Use placeholder and Plot defaults go through the Px metric Finding literal-defaults-bypass-metric. Device::placeholder and Device::plot stated cell literals (1, 38x10) beside the one adapter. They now state 16 px and 300x150 px and convert at Device::length, per axis: a Use placeholder is 2x1 cells and a Plot 38x9 (37.5x9.375 rounded). Re-blessed: screen-f07-plot-cells (the default plot is one row shorter; style runs only, no glyph moves). Co-Authored-By: Claude Opus 5.5 --- crates/thing-core/src/layout/measure.rs | 12 +++---- crates/thing-core/src/layout/tree.rs | 5 +-- crates/thing-core/tests/render.rs | 20 ++++++++++- .../tests/goldens/screen-f07-plot-cells.txt | 36 +++++++++---------- 4 files changed, 44 insertions(+), 29 deletions(-) diff --git a/crates/thing-core/src/layout/measure.rs b/crates/thing-core/src/layout/measure.rs index 72e9fe5..bba1af7 100644 --- a/crates/thing-core/src/layout/measure.rs +++ b/crates/thing-core/src/layout/measure.rs @@ -135,9 +135,9 @@ impl Device { Self { k, cells } } - /// The least a Use placeholder takes, so its error is visible: 16 logical px, one cell. - pub(super) fn placeholder(self) -> f32 { - if self.cells { 1.0 } else { self.px(16.0) } + /// The least a Use placeholder takes, so its error is visible: 16 logical px each way. + pub(super) fn placeholder(self) -> (f32, f32) { + (self.length(16.0, Axis::X), self.length(16.0, Axis::Y)) } /// Whether this is a cell grid. @@ -145,10 +145,10 @@ impl Device { self.cells } - /// A Plot's size: the CSS default object size, 300x150 logical px, or 38x10 cells. A plot is - /// sized by layout, never measured. + /// A Plot's size: the CSS default object size, 300x150 logical px. A plot is sized by layout, + /// never measured. pub(super) fn plot(self) -> (f32, f32) { - if self.cells { (38.0, 10.0) } else { (self.px(300.0), self.px(150.0)) } + (self.length(300.0, Axis::X), self.length(150.0, Axis::Y)) } /// A viewport side or a measured size in device units: logical px times the scale, or cells diff --git a/crates/thing-core/src/layout/tree.rs b/crates/thing-core/src/layout/tree.rs index e19cc81..f25cfec 100644 --- a/crates/thing-core/src/layout/tree.rs +++ b/crates/thing-core/src/layout/tree.rs @@ -268,8 +268,9 @@ impl<'a> Builder<'a, '_> { Node::Use(u) => { if !self.hidden(&u.common.id) { let index = self.entry(&u.common.id, parent, &Overflow::Visible); - let least = taffy::LengthPercentageAuto::length(self.dev.placeholder()); - let style = Style { min_size: taffy::Size { width: least, height: least }, ..Style::default() }; + let (width, height) = self.dev.placeholder(); + let least = taffy::Size { width: taffy::LengthPercentageAuto::length(width), height: taffy::LengthPercentageAuto::length(height) }; + let style = Style { min_size: least, ..Style::default() }; let id = self.taffy.new_leaf(style).expect("taffy: insert"); self.entries[index].node = id; out.push(id); diff --git a/crates/thing-core/tests/render.rs b/crates/thing-core/tests/render.rs index 82ba6f4..9ccaaae 100644 --- a/crates/thing-core/tests/render.rs +++ b/crates/thing-core/tests/render.rs @@ -1022,7 +1022,7 @@ fn a_plot_is_sized_by_layout_to_the_default_object_size() { let scaled = with_state(&mut MemState::new(), plot(), &pixels(2.0)); assert_eq!(placed(&scaled, "p").rect, rect(0.0, 0.0, 300.0, 150.0), "logical, whatever the scale"); let cells = with_state(&mut MemState::new(), plot(), &frame(80.0, 30.0, 1.0, Metrics::Cells)); - assert_eq!(placed(&cells, "p").rect, rect(0.0, 0.0, 38.0, 10.0)); + assert_eq!(placed(&cells, "p").rect, rect(0.0, 0.0, 38.0, 9.0), "300x150 px at 8x16 is 37.5x9.375 cells, rounded"); } fn knob(rendered: &Rendered) -> Rect { @@ -1306,3 +1306,21 @@ fn a_compact_controls_text_stands_one_cell_in_on_its_first_row() { assert_eq!(input(2.0), [(1.0, 0.0)]); assert_eq!(input(3.0), [(1.0, 1.0)]); } + +#[test] +fn a_use_placeholder_is_16_px_at_the_cell_metric_in_cells() { + // The least a Use placeholder takes is 16 logical px: 2 cells across and 1 down at 8x16, the + // same Px length a Box states, not a cell count of its own. + let use_node = || { + Node::Use(UseNode { + common: common("u"), + composition: CompositionRef { publisher: "nobody".into(), name: seg("missing"), version: ver(1) }, + args: vec![], + }) + }; + let (_, cells) = inline(flat("root", BoxStyle { direction: Direction::Column, align_items: ItemAlign::Start, ..plain() }, vec![use_node()]), &frame(40.0, 10.0, 1.0, Metrics::Cells), &ScrollOffsets::default()); + assert_eq!(placed(&cells, "u").rect, rect(0.0, 0.0, 2.0, 1.0)); + let twin = flat("root", BoxStyle { direction: Direction::Column, align_items: ItemAlign::Start, ..plain() }, vec![flat("twin", sized(16.0, 16.0), vec![])]); + let (_, boxed) = inline(twin, &frame(40.0, 10.0, 1.0, Metrics::Cells), &ScrollOffsets::default()); + assert_eq!(placed(&boxed, "twin").rect, placed(&cells, "u").rect, "a 16 px Box and a Use placeholder are the same cells"); +} diff --git a/crates/thing-tui/tests/goldens/screen-f07-plot-cells.txt b/crates/thing-tui/tests/goldens/screen-f07-plot-cells.txt index 63a6f2e..606fb16 100644 --- a/crates/thing-tui/tests/goldens/screen-f07-plot-cells.txt +++ b/crates/thing-tui/tests/goldens/screen-f07-plot-cells.txt @@ -77,47 +77,43 @@ style 8 2 3 #7c9cff - - style 8 5 95 - - - style 9 0 3 #7c9cff - - style 9 3 97 - - - -style 10 0 100 - - - +style 10 0 23 - - - +style 10 23 7 - #7c9cff - +style 10 30 70 - - - style 11 0 23 - - - style 11 23 7 - #7c9cff - style 11 30 70 - - - style 12 0 23 - - - -style 12 23 7 - #7c9cff - -style 12 30 70 - - - -style 13 0 23 - - - +style 12 23 15 - #7c9cff - +style 12 38 62 - - - +style 13 0 8 - - - +style 13 8 7 - #7c9cff - +style 13 15 8 - - - style 13 23 15 - #7c9cff - style 13 38 62 - - - style 14 0 8 - - - -style 14 8 7 - #7c9cff - -style 14 15 8 - - - -style 14 23 15 - #7c9cff - +style 14 8 30 - #7c9cff - style 14 38 62 - - - style 15 0 8 - - - -style 15 8 7 - #7c9cff - -style 15 15 8 - - - -style 15 23 15 - #7c9cff - +style 15 8 30 - #7c9cff - style 15 38 62 - - - -style 16 0 8 - - - -style 16 8 30 - #7c9cff - +style 16 0 38 - #7c9cff - style 16 38 62 - - - style 17 0 38 - #7c9cff - style 17 38 62 - - - style 18 0 38 - #7c9cff - style 18 38 62 - - - -style 19 0 38 - #7c9cff - -style 19 38 62 - - - -style 20 0 38 - #7c9cff - -style 20 38 62 - - - +style 19 0 100 - - - +style 20 0 2 - #7c9cff - +style 20 2 98 - - - style 21 0 2 - #7c9cff - style 21 2 98 - - - style 22 0 2 - #7c9cff - style 22 2 98 - - - style 23 0 2 - #7c9cff - style 23 2 98 - - - -style 24 0 2 - #7c9cff - -style 24 2 98 - - - -style 25 0 2 - #7c9cff - -style 25 2 98 - - - +style 24 0 100 - - - +style 25 0 100 - - - style 26 0 100 - - - style 27 0 100 - - - style 28 0 100 - - -