From 0ba9cb07cf5e298c0ff47983f0e0655365e3634f Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 22 Nov 2026 07:55:59 -0500 Subject: [PATCH] PageView::pasteboard: the colour round the pages (L-309 full-screen black; trial seen failing) --- crates/pages/src/ui/view.rs | 14 ++++++++++++-- crates/pages/tests/it/views.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/crates/pages/src/ui/view.rs b/crates/pages/src/ui/view.rs index 5d5069efc8..62d4a6b851 100644 --- a/crates/pages/src/ui/view.rs +++ b/crates/pages/src/ui/view.rs @@ -26,7 +26,7 @@ use craft_behavior::kurbo::{Point, Rect as DocRect, Size}; use craft_behavior::{CanvasView, NavMove, PressPhase, ZoomLadder}; use craft_keymap::Mods; use craft_ui::canvas::{ - BodyKeys, Canvas, CanvasOutput, CanvasScrollbars, CanvasSpace, NavigationOptions, PageBorder, PageFrame, Pasteboard, PasteboardOutput, ToolPass, + BodyKeys, Canvas, CanvasOutput, CanvasScrollbars, CanvasSpace, NavigationOptions, PageBorder, PageFrame, Pasteboard, PasteboardColor, PasteboardOutput, ToolPass, canvas_space, tool_pass, with_canvas_space, }; use craft_ui::contract::{Bind, BodyCx, Held, Props as _, Show as _, ShowContainer as _}; @@ -346,6 +346,7 @@ pub struct PageView<'a> { describer: Option<&'a dyn AccessDescriber>, paper: DataColor, border: PageBorder, + pasteboard: PasteboardColor, keep: &'a [usize], } @@ -363,10 +364,18 @@ impl<'a> PageView<'a> { describer: None, paper, border: PageBorder::DropShadow, + pasteboard: PasteboardColor::Default, keep: &[], } } + /// The colour round the pages: the theme's by default; production's full screen view is black. + #[must_use] + pub fn pasteboard(mut self, colour: PasteboardColor) -> Self { + self.pasteboard = colour; + self + } + /// The border round each page; a drop shadow by default, and none with the page gaps off. #[must_use] pub fn border(mut self, border: PageBorder) -> Self { @@ -458,7 +467,7 @@ impl<'a> PageView<'a> { mut before: impl FnMut(&mut Ui, &PageBody<'_>, &mut T) -> Option, mut body: impl FnMut(&mut Ui, &PageBody<'_>, &mut T), ) -> PageViewOutput { - let PageView { label, source, state, options, navigation, bodies, describer, paper, border, keep } = self; + let PageView { label, source, state, options, navigation, bodies, describer, paper, border, pasteboard, keep } = self; let spacing = PageMetrics::new().show_at(ui, Rect::from_min_size(rect.min, Vec2::ZERO)).spacing; let count = source.page_count(); let sizes: Vec = (0..count).map(|page| source.page_size(page)).collect(); @@ -479,6 +488,7 @@ impl<'a> PageView<'a> { .navigation(navigation) .keys_to_body(true) .body_nudges(KeyMoves::NUDGES) + .pasteboard(pasteboard) .document(frame.document(&geo)); let mut held = Held::new(Bind::bound(state)); let mut seen: Option = None; diff --git a/crates/pages/tests/it/views.rs b/crates/pages/tests/it/views.rs index caf42abaf5..cf8e3ba242 100644 --- a/crates/pages/tests/it/views.rs +++ b/crates/pages/tests/it/views.rs @@ -1638,3 +1638,29 @@ fn a_page_fitted_to_the_width_keeps_the_theme_side_margin() { assert!((left - side).abs() < 1.0 && (right - side).abs() < 1.0, "side margins {left} and {right}, not the theme's {side}"); assert!((page.y0 - out.offset.1 - margin).abs() < 1.0, "the first page's margin: {} not {margin}", page.y0 - out.offset.1); } + +/// L-309: the page view's surround takes the colour the app sets: full screen shows the pages on black, as production. +#[trial] +fn the_pasteboard_colour_of_a_page_view_paints_the_surround() { + use craft_ui::canvas::PasteboardColor; + let paints_black = |colour: Option| { + let source = DemoPages::new(2); + let mut state = state_with(|s| s.fit = Fit::Width); + let mut fixture = Fixture::new(move |ui| { + let mut view = PageView::new("Pages", &source, &mut state, PAPER); + if let Some(colour) = colour { + view = view.pasteboard(colour); + } + view.show(ui, |_, _| ()); + }); + fixture.idle(3); + fixture.frame_shapes().iter().any(|shape| match shape { + egui::Shape::Rect(r) => r.fill == egui::Color32::BLACK, + egui::Shape::Path(p) => p.fill == egui::Color32::BLACK, + egui::Shape::Mesh(m) => m.vertices.iter().any(|v| v.color == egui::Color32::BLACK), + _ => false, + }) + }; + assert!(!paints_black(None), "the default surround is the theme's"); + assert!(paints_black(Some(PasteboardColor::Black)), "a black pasteboard paints black round the pages"); +}