From d8a6478210b98a146a92511b286e162200cbcee0 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 04:11:45 +0000 Subject: [PATCH] The checkerboard's light cell sits at the picture's top-left corner on screen, wherever the view puts it --- crates/ui-canvas/src/canvas/raster/mod.rs | 4 +++- crates/ui-canvas/tests/it/canvas/raster.rs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/ui-canvas/src/canvas/raster/mod.rs b/crates/ui-canvas/src/canvas/raster/mod.rs index 5fc64edce..8aa376bbd 100644 --- a/crates/ui-canvas/src/canvas/raster/mod.rs +++ b/crates/ui-canvas/src/canvas/raster/mod.rs @@ -534,8 +534,10 @@ impl Component for RasterDisplay<'_> { [areas.next(), areas.next()] } }; + // A light cell sits at the picture's top-left corner on screen, wherever the view puts the picture. + let origin = corners.map_or(shown.view.rect.min, |corners| corners[0]); for area in areas.into_iter().flatten() { - painter.painter.add(checker.shape(painter.painter.ctx(), &ui.env.tokens, CheckerArea::Quad(area), shown.view.rect.min)); + painter.painter.add(checker.shape(painter.painter.ctx(), &ui.env.tokens, CheckerArea::Quad(area), origin)); } } match (&mut self.picture, &shown.textures, &self.mapping) { diff --git a/crates/ui-canvas/tests/it/canvas/raster.rs b/crates/ui-canvas/tests/it/canvas/raster.rs index 08f84ef20..60ba2e63c 100644 --- a/crates/ui-canvas/tests/it/canvas/raster.rs +++ b/crates/ui-canvas/tests/it/canvas/raster.rs @@ -129,6 +129,24 @@ fn the_checkerboard_paints_the_same_shapes_at_any_area() { assert_eq!(small, large, "a checkerboard over the whole canvas paints as many shapes as one over a corner of it"); } +// The checkerboard's light cell sits at the document's top-left corner on screen, wherever the view puts the document, +// not at a corner of the canvas. +#[trial] +fn the_checkerboard_starts_with_a_light_cell_at_the_document_corner() { + for (width, height, zoom) in [(100, 70, 1.0), (64, 64, 0.5), (90, 30, 1.5)] { + let document = Document::new(width, height); + let center = Point::new(f64::from(width) / 2.0, f64::from(height) / 2.0); + let corner = CanvasView::new(Rect::from_min_size(Pos2::ZERO, CANVAS), center, zoom).to_screen(Point::ZERO); + let mut rig = rig(document, zoom); + let shapes = rig.fixture.frame_shapes(); + let checker = *textured(&shapes).first().expect("the checkerboard"); + let at_corner = checker.vertices.iter().find(|vertex| vertex.pos.distance(corner) < 0.5).expect("a checkerboard corner at the document's"); + let whole = |v: f32| (v - v.round()).abs() < 1e-3; + // The texture repeats every two cells, light first: a whole texture coordinate is a light cell's top-left. + assert!(whole(at_corner.uv.x) && whole(at_corner.uv.y), "{width} x {height} at {zoom}: a light cell starts at the document's corner: {:?}", at_corner.uv); + } +} + /// A canvas at 800 percent whose body shows, as a document canvas does, the pasteboard with the document's page and /// its shadow, a display of `document` with the checkerboard and the edge, and the pixel grid over it. While `painted` /// is set the display is a painted one: the app's paint adds a GPU paint callback, as an app with its own compositor