From daba894b2db05fadbe51a12d1e0a72b9717288e6 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 28 Nov 2026 07:46:27 +0100 Subject: [PATCH] Thing 2.0 cut 6a: render tests for the padding-box clip and scrollbar thickness Co-Authored-By: Claude Sonnet 5.5 --- crates/thing-core/tests/render.rs | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/crates/thing-core/tests/render.rs b/crates/thing-core/tests/render.rs index f29ced1..fc641c9 100644 --- a/crates/thing-core/tests/render.rs +++ b/crates/thing-core/tests/render.rs @@ -645,3 +645,41 @@ fn random_documents_render_without_panic_balanced_and_equal() { assert_eq!(first.placed.len(), laid.nodes.len()); } } + +#[test] +fn a_clip_is_the_padding_box_and_its_radius_the_radius_less_the_border() { + let paint = Paint { background: None, border: Some(Border { color: ColorRef::Rgba(Rgba { r: 9, g: 8, b: 7, a: 6 }), width: 3.0 }), radius: 10.0 }; + let root = flat("root", plain(), vec![bx("pane", BoxStyle { overflow: Overflow::Clip, ..sized(100.0, 50.0) }, paint.clone(), vec![embed("e", 5.0, 5.0)])]); + let (_, rendered) = inline(root.clone(), &pixels(2.0), &ScrollOffsets::default()); + let pane = placed(&rendered, "pane").rect; + let stroke = RenderCommand::StrokeRect { rect: pane, radius: 10.0, width: 3.0, color: paint.border.as_ref().unwrap().color_literal() }; + let clip = RenderCommand::ClipPush { rect: thing_core::layout::Rect { x: pane.x + 3.0, y: pane.y + 3.0, w: pane.w - 6.0, h: pane.h - 6.0 }, radius: 7.0 }; + assert_eq!(&rendered.commands[..2], [stroke, clip]); + // A radius the border swallows leaves a square clip. + let mut square = paint; + square.radius = 2.0; + let (_, rendered) = inline(flat("root", plain(), vec![bx("pane", BoxStyle { overflow: Overflow::Clip, ..sized(100.0, 50.0) }, square, vec![])]), &pixels(1.0), &ScrollOffsets::default()); + assert!(matches!(rendered.commands[1], RenderCommand::ClipPush { radius, .. } if radius == 0.0)); +} + +trait Literal { + fn color_literal(&self) -> Rgba; +} + +impl Literal for Border { + fn color_literal(&self) -> Rgba { + match &self.color { + ColorRef::Rgba(rgba) => rgba.clone(), + ColorRef::Token(_) => unreachable!(), + } + } +} + +#[test] +fn a_scrollbar_is_one_cell_thick_in_cells_and_the_theme_thickness_in_pixels() { + let pane = || flat("root", BoxStyle { overflow: Overflow::Scroll, ..sized(10.0, 5.0) }, vec![embed("e", 5.0, 20.0)]); + let (_, cells) = inline(pane(), &frame(20.0, 10.0, 1.0, Metrics::Cells), &ScrollOffsets::default()); + assert_eq!(fills(&cells).iter().map(|f| f.2).collect::>(), [1.0]); + let (_, device) = inline(pane(), &pixels(2.0), &ScrollOffsets::default()); + assert_eq!(fills(&device).iter().map(|f| f.2).collect::>(), [Theme::std().scrollbar]); +}