thing-core test: pin a compact toggle's glyph row and a Pixels control's content box at scale

cargo-mutants survivors of the control-form cut: the compact toggle's glyph height (a
2-row compact toggle drew a 2-cell knob) and the device-to-logical conversion of the
content box layout states (only scale 1 was tested, where it is the identity).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-28 17:42:04 +01:00
commit baa358ccff

View file

@ -1324,3 +1324,33 @@ fn a_use_placeholder_is_16_px_at_the_cell_metric_in_cells() {
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");
}
#[test]
fn a_compact_toggles_glyph_is_one_cell_on_its_first_row_whatever_its_declared_height() {
for rows in [1.0_f64, 2.0] {
for checked in [false, true] {
let mut style = plain();
style.size = size2(px(20.0 * 8.0), px(rows * 16.0));
let toggle = Node::Toggle(ToggleNode { common: common("t"), checked: lit_bool(checked), on_change: command("dismiss") });
let (_, out) = inline(flat("root", style, vec![toggle]), &frame(30.0, 12.0, 1.0, Metrics::Cells), &ScrollOffsets::default());
let whole = placed(&out, "t").rect;
let x = if checked { whole.x + whole.w - 2.0 } else { whole.x + 1.0 };
assert_eq!(knob(&out), rect(x, 0.0, 1.0, 1.0), "{rows} rows, checked {checked}: one cell, one cell in from its side");
}
}
}
#[test]
fn a_pixels_control_draws_its_content_in_logical_px_at_any_scale() {
// The content box layout states is device px; render divides it by the scale: 2 logical px in.
let input = Node::TextInput(TextInputNode {
common: common("i"),
multiline: false,
input_kind: InputKind::Text,
placeholder: lit_text("type"),
initial: lit_text("hi"),
submit: command("dismiss"),
});
let out = with_state(&mut MemState::new(), flat("root", plain(), vec![input]), &pixels(2.0));
assert!(matches!(out.commands.last(), Some(RenderCommand::Text { origin, .. }) if origin.0 == 2.0), "{:?}", out.commands.last());
}