From 2c855e2858f65ce55a5201cbe632a09637e5d026 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 30 Nov 2026 02:15:03 +0000 Subject: [PATCH 1/5] TransformBox: a disabled document box fills its handles with their rim's ink A locked shape's handles looked the same as an unlocked one's, light with a grey rim. The document looks now fill a disabled box's handles with the frame ink, and the box paints with BoxLook::handle_look, so a host's own points (a line's ends) take the same look. Co-Authored-By: Claude Opus 5.5 --- crates/draw/src/ui/transform/transform_box.rs | 17 +++++++---- crates/draw/tests/it/transform_box.rs | 29 ++++++++++++++++++- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/crates/draw/src/ui/transform/transform_box.rs b/crates/draw/src/ui/transform/transform_box.rs index 1139c2b18e..0940efabb8 100644 --- a/crates/draw/src/ui/transform/transform_box.rs +++ b/crates/draw/src/ui/transform/transform_box.rs @@ -151,11 +151,13 @@ pub enum BoxLook { impl BoxLook { /// The handle look of this box look, for the points a host draws beside the box in the same look (a line's ends, - /// a connector's sites, edit points): the document looks rim them as their frame. + /// a connector's sites, edit points): the document looks rim them as their frame, and fill them with it while the + /// box is disabled (a locked shape), so the lock shows on the handles and not only in the missing rotate handle. pub fn handle_look(self, cx: &StyleCx<'_>) -> HandleLook { let mut look = cx.handle(); if self != BoxLook::Standard { look.stroke = document_ink(cx); + look.fill.off.disabled = document_ink(cx); } look } @@ -347,6 +349,8 @@ pub struct TransformBoxStyle { #[style(metrics)] metrics: Metrics, handle: HandleLook, + /// The handle of the document looks ([`BoxLook::handle_look`]). + document_handle: HandleLook, line: StyleColor, halo: StyleColor, /// The frame, the handle rims and the rotate handle of the document look. @@ -1228,18 +1232,18 @@ impl TransformBox<'_> { /// A handle's `square` (a circle with round handles), filled as the state of `part` shows, or at rest without one. fn paint_handle_shape(&self, draw: &Draw<'_>, cx: &Cx<'_, Self>, square: PaintShape, part: Option) { - let look = &cx.style.handle; + let look = self.handle_look(cx.style); let fill = match part { Some(part) => cx.resolve_part(part, &look.fill), None => cx.resolve(&look.fill), }; draw.fill(&square, fill); - draw.stroke(&square, StrokeWidth::Thin, self.ink(self.rim(cx.style))); + draw.stroke(&square, StrokeWidth::Thin, self.ink(look.stroke)); } - /// The colour of a handle's rim in this look. - fn rim(&self, style: &TransformBoxStyle) -> StyleColor { - if self.look == BoxLook::Standard { style.handle.stroke } else { style.neutral } + /// The handle of this look. + fn handle_look<'s>(&self, style: &'s TransformBoxStyle) -> &'s HandleLook { + if self.look == BoxLook::Standard { &style.handle } else { &style.document_handle } } /// The frame of the box whose corners are `corners` on the screen, as the look draws it. @@ -1399,6 +1403,7 @@ fn transform_style(cx: &StyleCx<'_>) -> TransformBoxStyle { TransformBoxStyle { metrics: Metrics::new(), handle: cx.handle(), + document_handle: BoxLook::Document.handle_look(cx), line: cx.color(overlay.line), halo: cx.color(overlay.halo), neutral: document_ink(cx), diff --git a/crates/draw/tests/it/transform_box.rs b/crates/draw/tests/it/transform_box.rs index 508f79bf94..051608a110 100644 --- a/crates/draw/tests/it/transform_box.rs +++ b/crates/draw/tests/it/transform_box.rs @@ -73,6 +73,7 @@ struct Config { reach: TransformReach, /// Whether Enter and Escape from the canvas session are the box's. session_commit: bool, + enabled: bool, } /// What the host keeps of the box and what the passes reported. @@ -128,6 +129,7 @@ fn defaults() -> Config { twice: false, reach: TransformReach::Box, session_commit: true, + enabled: true, } } @@ -224,7 +226,7 @@ fn harness(state: BoxState, setup: impl FnOnce(&mut Config)) -> Harness { if let Some(side) = config.handle_side { control = control.handle_side(side); } - control = control.reach(config.reach).session_commit(config.session_commit); + control = control.reach(config.reach).session_commit(config.session_commit).enabled(config.enabled); if config.hover_frame { control = control.id(frame_id); } @@ -1719,6 +1721,31 @@ fn a_host_point_in_the_document_look_takes_the_box_handles_rim() { assert!(painted.contains(&document), "the box's own handles take the same rim: {document:?} in {painted:?}"); } +/// A disabled box in the document look (a locked shape) fills its handles with their rim's ink, where an enabled one +/// fills them light: the lock shows on the handles. +#[trial] +fn a_disabled_document_box_fills_its_handles_with_their_rim() { + let fills = |enabled: bool| { + let mut h = harness(BoxState::from_rect(RECT), |config| { + config.look = BoxLook::Document; + config.enabled = enabled; + }); + let shapes = h.fixture.frame_shapes(); + let fills: Vec = shapes + .iter() + .filter_map(|shape| match shape { + Shape::Circle(circle) if circle.fill.a() > 0 => Some(circle.fill), + _ => None, + }) + .collect(); + (fills, stroke_colors(&shapes)) + }; + let ((enabled, enabled_rims), (locked, locked_rims)) = (fills(true), fills(false)); + assert!(!enabled.is_empty() && !locked.is_empty(), "both boxes paint filled handles"); + assert!(enabled.iter().all(|fill| !enabled_rims.contains(fill)), "an enabled box's handles are light: {enabled:?} {enabled_rims:?}"); + assert!(locked.iter().all(|fill| locked_rims.contains(fill)), "a locked box's handles take their rim's ink: {locked:?} {locked_rims:?}"); +} + /// A host's handle side draws the corner and side handles at that side: a larger side draws a larger square. #[trial] fn a_host_handle_side_sets_the_drawn_handle_square() { From 6e3591ca68f46330437260d47b844f103ea398c9 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 30 Nov 2026 02:19:57 +0000 Subject: [PATCH 2/5] Pasteboard: a plain page's line edge lies under the document The line border painted over the pictures, so a shape hanging off a slide was crossed by the slide's edge. It now paints with the page's shadow and fill, under the pictures; artboard edges and names still mark the boards over them. Co-Authored-By: Claude Opus 5.5 --- crates/ui-canvas/src/canvas/pasteboard/mod.rs | 11 ++++---- crates/ui-canvas/tests/it/canvas/raster.rs | 28 ++++++++++++++----- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/crates/ui-canvas/src/canvas/pasteboard/mod.rs b/crates/ui-canvas/src/canvas/pasteboard/mod.rs index 07ca5269c5..9a908fcab5 100644 --- a/crates/ui-canvas/src/canvas/pasteboard/mod.rs +++ b/crates/ui-canvas/src/canvas/pasteboard/mod.rs @@ -474,11 +474,11 @@ impl Component for Pasteboard<'_> { let (view, style) = (space.view, cx.style); let draw = ui.draw(); let edges = ui.content_painter(cx); - // What lies under the pages (their shadows and fills) marks where it starts; it moves into the canvas's picture + // What lies under the pages (their shadows, fills and line edges) marks where it starts; it moves into the canvas's picture // slot, in show order before the pictures, so every picture lies over it. The surround of plain pages goes // with it, so a picture reaching past the page (copies around it, pixels past the canvas) shows over it; the // surround between artboards paints over the pictures and hides the document there, except where `uncovered` - // leaves it open. The page edges and names, which mark the pages, paint in place over the pictures. Outside a + // leaves it open. The artboard edges and names, which mark the boards, paint in place over the pictures. Outside a // canvas, or in a space with no slot, everything paints in place. let under = space.picture_slot().map(|_| PaintSlot::reserve(&edges.painter)); let artboards = self.pages.iter().any(|page| page.active.is_some()) && !self.shows_outside; @@ -529,6 +529,10 @@ impl Component for Pasteboard<'_> { } None => {} } + // A plain page's edge is part of the page, under what the document draws past it. + if self.border == PageBorder::Line { + edge(&quad, style.outline.egui(), style.outline.into(), false); + } } if let Some(under) = under { let ctx = edges.painter.ctx().clone(); @@ -540,9 +544,6 @@ impl Component for Pasteboard<'_> { } for (at, page) in self.pages.iter().enumerate().filter(|(_, page)| shown(page)) { let quad = view.quad(page.rect); - if self.border == PageBorder::Line { - edge(&quad, style.outline.egui(), style.outline.into(), false); - } if let Some(active) = page.active { match self.artboard_edge { ArtboardEdge::Accent => { diff --git a/crates/ui-canvas/tests/it/canvas/raster.rs b/crates/ui-canvas/tests/it/canvas/raster.rs index de3051289d..4e7a013939 100644 --- a/crates/ui-canvas/tests/it/canvas/raster.rs +++ b/crates/ui-canvas/tests/it/canvas/raster.rs @@ -3,7 +3,7 @@ use craft_behavior::geometry::quad::Homography; use craft_behavior::kurbo::{Point, Rect as Rect64}; use craft_behavior::{CanvasView, PixelSize}; -use craft_ui::canvas::{AppPaint, Canvas, Extent, PageFrame, Pasteboard, PixelRect, RasterDisplay, RasterSource}; +use craft_ui::canvas::{AppPaint, Canvas, Extent, PageBorder, PageFrame, Pasteboard, PixelRect, RasterDisplay, RasterSource}; use craft_ui::canvas_controls::PixelGrid; use craft_ui::contract::{Show as _, ShowContainer as _}; use craft_ui::primitives::{Checker, Revision}; @@ -590,30 +590,44 @@ fn a_picture_in_the_canvas_slot_shows_its_own_colour_over_the_pasteboard() { let page = Rect64::new(0.0, 0.0, 400.0, 300.0); let view = CanvasView::new(Rect::from_min_size(Pos2::ZERO, CANVAS), page.center(), 1.0); let at = |x: f64, y: f64| view.to_screen(Point::new(x, y)); - let plain = slot_canvas(view, vec![PageFrame::new(page).fill(DataColor::new(Color32::WHITE))], Vec::new()); + let plain = slot_canvas(view, vec![PageFrame::new(page).fill(DataColor::new(Color32::WHITE))], Vec::new(), PageBorder::DropShadow); assert!(shows_picture(&plain, at(200.0, 150.0)), "the plain page's centre shows {:?}", colour_at(&plain, at(200.0, 150.0))); let boards = vec![ PageFrame::new(Rect64::new(20.0, 20.0, 180.0, 280.0)).name("One").active(true), PageFrame::new(Rect64::new(220.0, 20.0, 380.0, 280.0)).name("Two").active(false), ]; let loose = vec![Rect64::new(185.0, 20.0, 215.0, 60.0)]; - let artboards = slot_canvas(view, boards, loose); + let artboards = slot_canvas(view, boards, loose, PageBorder::DropShadow); for (x, y, what) in [(100.0, 150.0, "the first board"), (300.0, 150.0, "the second board"), (200.0, 40.0, "the loose layer")] { assert!(shows_picture(&artboards, at(x, y)), "{what} shows {:?}", colour_at(&artboards, at(x, y))); } assert!(!shows_picture(&artboards, at(200.0, 150.0)), "the pasteboard covers the document between the boards"); } +/// A plain page's line edge lies under the picture, as its fill does: content that hangs off the page (a shape on a +/// slide's pasteboard) covers the page's edge instead of being crossed by it. +#[trial] +fn a_picture_over_a_plain_pages_edge_covers_its_line() { + let page = Rect64::new(0.0, 0.0, 400.0, 300.0); + let view = CanvasView::new(Rect::from_min_size(Pos2::ZERO, CANVAS), page.center(), 1.0); + let shapes = slot_canvas(view, vec![PageFrame::new(page)], Vec::new(), PageBorder::Line); + let picture = shapes.iter().position(|shape| matches!(shape, Shape::Rect(rect) if rect.fill == PICTURE)); + let edges: Vec = shapes.iter().enumerate().filter(|(_, shape)| matches!(shape, Shape::LineSegment { .. })).map(|(at, _)| at).collect(); + let picture = picture.expect("the picture paints"); + assert!(!edges.is_empty(), "the page's edge paints"); + assert!(edges.iter().all(|edge| *edge < picture), "the edge {edges:?} paints before the picture at {picture}"); +} + /// The picture's own colour. const PICTURE: Color32 = Color32::from_rgb(204, 128, 77); -/// The shapes of a frame of a canvas whose body shows a pasteboard with `pages` and `uncovered`, then a picture in -/// the canvas's slot that fills the canvas with [`PICTURE`]. -fn slot_canvas(view: CanvasView, pages: Vec, uncovered: Vec) -> Vec { +/// The shapes of a frame of a canvas whose body shows a pasteboard with `pages`, `uncovered` and `border`, then a +/// picture in the canvas's slot that fills the canvas with [`PICTURE`]. +fn slot_canvas(view: CanvasView, pages: Vec, uncovered: Vec, border: PageBorder) -> Vec { let size = PixelSize::new(400, 300); let mut fixture = Fixture::new(move |ui| { Canvas::new("Document").view(view).show(ui, |ui, body| { - let _ = Pasteboard::new("Pasteboard", &pages).uncovered(&uncovered).show_at(ui, body.rect); + let _ = Pasteboard::new("Pasteboard", &pages).uncovered(&uncovered).border(border).show_at(ui, body.rect); let paint = AppPaint::new(|painter, view: CanvasView| { painter.painter.add(Shape::rect_filled(view.rect, 0.0, PICTURE)); }); From 37c3959c5bc27d6b6b3ea6d92ffb371750ea5b84 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 30 Nov 2026 02:34:43 +0000 Subject: [PATCH 3/5] Rulers: leave out a stacked vertical number a tick would cut On a centimetre ruler the half-unit tick reached into the vertical strip's stacked two-digit numbers, so 10 read as a 1 and a 0 on either side of a tick. The edge face now leaves out a vertical number whose column a tick runs into. Where a tick lies comes from Tick::span, which the tick painter now uses too. Co-Authored-By: Claude Opus 5.5 --- crates/ui-canvas/src/canvas/rulers/mod.rs | 15 ++++-- crates/ui-canvas/tests/it/canvas/rulers.rs | 46 +++++++++++++++++ crates/ui-contract/src/primitives/kit.rs | 60 ++++++++++++---------- 3 files changed, 90 insertions(+), 31 deletions(-) diff --git a/crates/ui-canvas/src/canvas/rulers/mod.rs b/crates/ui-canvas/src/canvas/rulers/mod.rs index 1f654188ed..ef284de29a 100644 --- a/crates/ui-canvas/src/canvas/rulers/mod.rs +++ b/crates/ui-canvas/src/canvas/rulers/mod.rs @@ -634,7 +634,18 @@ impl Component for Rulers<'_> { // A label as long along the strip as the room between labelled ticks would run into the next one. let majors: Vec = ticks.iter().filter(|(tick, _)| tick.rank == TickRank::Major).map(|(_, at)| *at).collect(); let room = majors.windows(2).map(|pair| (pair[1] - pair[0]).abs()).fold(f32::INFINITY, f32::min); + let origin = if vertical { bar.top() } else { bar.left() }; + let marks: Vec = ticks.iter().map(|(tick, at)| Tick::new(*at - origin, tick.rank)).collect(); let fits = |label: Rect| (if vertical { label.height() } else { label.width() }) + style.pad < room; + // The edge face keeps every tick, so a stacked vertical number is also left out where a shorter tick runs + // into its column (a half-unit tick between the "1" and the "0" of 10), which would cut it in two. + let crossed = |column: Rect| { + face == RulerFace::Edge + && marks.iter().any(|mark| { + let (from, to) = mark.span(bar, edge, face); + Rect::from_two_pos(from, to).intersects(column) + }) + }; let mut galleys = Vec::new(); for (tick, at) in ticks.iter().filter(|(tick, _)| tick.rank == TickRank::Major) { let text = text_of(part).tick_label(&numbers, tick.value, tick.step); @@ -659,7 +670,7 @@ impl Component for Rulers<'_> { }) .collect(); let column = placed.iter().fold(Rect::NOTHING, |all, (at, layout)| all.union(Rect::from_min_size(*at, layout.size()))); - if !fits(column) { + if !fits(column) || crossed(column) { continue; } if face == RulerFace::Centred && (!shows(strip, column) || bands.iter().any(|band| band.intersects(column))) { @@ -682,8 +693,6 @@ impl Component for Rulers<'_> { } } } - let origin = if vertical { bar.top() } else { bar.left() }; - let marks: Vec = ticks.iter().map(|(tick, at)| Tick::new(*at - origin, tick.rank)).collect(); let boxes: Vec = galleys.iter().map(|(at, layout)| Rect::from_min_size(*at, layout.size())).collect(); let marks = face.beside_numbers(edge, origin, marks, &boxes, style.pad); painter.ticks(bar, edge, face, &marks); diff --git a/crates/ui-canvas/tests/it/canvas/rulers.rs b/crates/ui-canvas/tests/it/canvas/rulers.rs index 56cea90d40..5396c61047 100644 --- a/crates/ui-canvas/tests/it/canvas/rulers.rs +++ b/crates/ui-canvas/tests/it/canvas/rulers.rs @@ -208,6 +208,52 @@ fn labels_that_do_not_fit_between_labelled_ticks_are_left_out() { } } +/// A host table that labels every unit and ticks its halves. +fn every_unit_halved(_: f64) -> (f64, u32) { + (1.0, 2) +} + +/// A two-digit number stacked down the vertical strip reaches the half-unit tick, which would cut it in two. The +/// rulers leave out a stacked number a tick runs into; the level two-digit labels across the top stay. +#[trial] +fn no_tick_cuts_a_stacked_vertical_label() { + let room = Vec2::new(800.0, 900.0); + let view = CanvasView::new(Rect::from_min_size(Pos2::ZERO, room), Point::new(0.0, 0.0), 1.0); + let text = RulerText::new(RulerUnits::new(2.54 / 72.0, Ticks::Custom(every_unit_halved)), UnitKind::Centimetres); + let content = Rc::new(Cell::new(Rect::NOTHING)); + let seen = Rc::clone(&content); + let mut zero = Point::ZERO; + let mut fixture = Fixture::new(move |ui| { + let strips = Rulers::new("Rulers", Bind::bound(&mut zero)); + let shown = Canvas::new("Document").view(view).with_rulers(Some(strips)).rulers(text, text).show(ui, |_, _| {}); + if let Some(rulers) = shown.output.rulers { + seen.set(rulers.content_rect()); + } + }); + fixture.room(room); + fixture.settle(); + let content = content.get(); + let (top, left) = (|rect: &Rect| rect.max.y <= content.min.y + 0.5, |rect: &Rect| rect.max.x <= content.min.x + 0.5); + let runs: Vec<(Rect, String)> = + fixture.texts().iter().filter(|run| top(&run.rect) || left(&run.rect)).map(|run| (run.rect, run.text.clone())).collect(); + let ticks: Vec = fixture + .frame_shapes() + .iter() + .filter_map(|shape| match shape { + Shape::LineSegment { points, .. } => Some(Rect::from_two_pos(points[0], points[1])), + _ => None, + }) + // The painter clips the strip's ticks to it, off the corner box. + .filter(|tick| left(tick) && tick.height() < 0.5 && tick.min.y >= content.min.y) + .collect(); + assert!(!ticks.is_empty(), "the vertical strip paints ticks"); + for (run, label) in runs.iter().filter(|(run, _)| left(run) && run.min.y >= content.min.y) { + let crossing: Vec<&Rect> = ticks.iter().filter(|tick| tick.intersects(run.shrink(0.5))).collect(); + assert!(crossing.is_empty(), "the label {label:?} at {run:?} is crossed by {crossing:?}"); + } + assert!(runs.iter().any(|(run, label)| top(run) && label.len() == 2), "two-digit labels stay across the top: {runs:?}"); +} + /// How far past the canvas the tool's fill and the marquee reach. const PAST: f32 = 60.0; diff --git a/crates/ui-contract/src/primitives/kit.rs b/crates/ui-contract/src/primitives/kit.rs index 57f5d9a1c9..726858c21d 100644 --- a/crates/ui-contract/src/primitives/kit.rs +++ b/crates/ui-contract/src/primitives/kit.rs @@ -139,6 +139,35 @@ impl Tick { pub const fn new(at: f32, rank: TickRank) -> Self { Tick { at, rank } } + + /// The ends of this tick's line along `edge` of `rect` in `face`, where [`ticks`] paints it: a minor tick + /// `TICK_MINOR` long, a mid one `TICK_MID`, a major one across the whole depth of `rect`. The edge face hangs it + /// from `edge`; the centred face centres it on `rect`'s middle line. + pub fn span(&self, rect: Rect, edge: TickEdge, face: RulerFace) -> (Pos2, Pos2) { + let depth = match edge { + TickEdge::Bottom | TickEdge::Top => rect.height(), + TickEdge::Left | TickEdge::Right => rect.width(), + }; + let length = match self.rank { + TickRank::Minor => TICK_MINOR, + TickRank::Mid => TICK_MID, + TickRank::Major => depth, + }; + match (face, edge) { + (RulerFace::Edge, TickEdge::Bottom) => (pos2(rect.left() + self.at, rect.bottom()), pos2(rect.left() + self.at, rect.bottom() - length)), + (RulerFace::Edge, TickEdge::Top) => (pos2(rect.left() + self.at, rect.top()), pos2(rect.left() + self.at, rect.top() + length)), + (RulerFace::Edge, TickEdge::Left) => (pos2(rect.left(), rect.top() + self.at), pos2(rect.left() + length, rect.top() + self.at)), + (RulerFace::Edge, TickEdge::Right) => (pos2(rect.right(), rect.top() + self.at), pos2(rect.right() - length, rect.top() + self.at)), + (RulerFace::Centred, TickEdge::Bottom | TickEdge::Top) => { + let (x, y) = (rect.left() + self.at, rect.center().y); + (pos2(x, y - length / 2.0), pos2(x, y + length / 2.0)) + } + (RulerFace::Centred, TickEdge::Left | TickEdge::Right) => { + let (x, y) = (rect.center().x, rect.top() + self.at); + (pos2(x - length / 2.0, y), pos2(x + length / 2.0, y)) + } + } + } } /// The cells of the transparency checkerboard: their side and the two colours. A field left unset takes the @@ -714,39 +743,14 @@ pub fn grid_lines_with(look: &GridLook, grid: &GridLines, ink: &GridInk, pixels_ shapes } -/// The tick marks of `ticks` along `edge` of `rect` that `clip` shows, `stroke.thin` lines of `text.faint`: minor ones -/// `TICK_MINOR` long, mid ones `TICK_MID`, major ones across the whole depth of `rect`. The edge -/// face hangs them from `edge`; the centred face centres them on `rect`'s middle line (`rect` is then the face's bar). +/// The tick marks of `ticks` along `edge` of `rect` that `clip` shows, `stroke.thin` lines of `text.faint`, each where +/// [`Tick::span`] puts it (`rect` is the centred face's bar). pub fn ticks(tokens: &UiTokens, rect: Rect, edge: TickEdge, face: RulerFace, ticks: &[Tick], clip: Rect, pixels_per_point: f32) -> Vec { let look = RuleLook { color: rgba_color(tokens.color.text.faint), width: RuleWidth::Points(tokens.stroke.thin) }; - let depth = match edge { - TickEdge::Bottom | TickEdge::Top => rect.height(), - TickEdge::Left | TickEdge::Right => rect.width(), - }; ticks .iter() .filter_map(|tick| { - let length = match tick.rank { - TickRank::Minor => TICK_MINOR, - TickRank::Mid => TICK_MID, - TickRank::Major => depth, - }; - let (from, to) = match (face, edge) { - (RulerFace::Edge, TickEdge::Bottom) => { - (pos2(rect.left() + tick.at, rect.bottom()), pos2(rect.left() + tick.at, rect.bottom() - length)) - } - (RulerFace::Edge, TickEdge::Top) => (pos2(rect.left() + tick.at, rect.top()), pos2(rect.left() + tick.at, rect.top() + length)), - (RulerFace::Edge, TickEdge::Left) => (pos2(rect.left(), rect.top() + tick.at), pos2(rect.left() + length, rect.top() + tick.at)), - (RulerFace::Edge, TickEdge::Right) => (pos2(rect.right(), rect.top() + tick.at), pos2(rect.right() - length, rect.top() + tick.at)), - (RulerFace::Centred, TickEdge::Bottom | TickEdge::Top) => { - let (x, y) = (rect.left() + tick.at, rect.center().y); - (pos2(x, y - length / 2.0), pos2(x, y + length / 2.0)) - } - (RulerFace::Centred, TickEdge::Left | TickEdge::Right) => { - let (x, y) = (rect.center().x, rect.top() + tick.at); - (pos2(x - length / 2.0, y), pos2(x + length / 2.0, y)) - } - }; + let (from, to) = tick.span(rect, edge, face); clip.intersects(Rect::from_two_pos(from, to)).then(|| Rule::shapes(&look, from, to, pixels_per_point)) }) .flatten() From b802c4dbd407946d21bd0d10cb193f3075fa3b50 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 30 Nov 2026 03:23:41 +0000 Subject: [PATCH 4/5] List: a dimmed row's toggles dim with its name The children of a hidden group drew their eye and padlock in the ordinary toggle ink, so only their names showed the hidden state. A dimmed row's on toggles now take the row's dimmed ink. Co-Authored-By: Claude Opus 5.5 --- crates/ui-widgets/src/list/row/show.rs | 3 +- crates/ui-widgets/tests/it/list.rs | 42 ++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/crates/ui-widgets/src/list/row/show.rs b/crates/ui-widgets/src/list/row/show.rs index c061be4696..1afa86a789 100644 --- a/crates/ui-widgets/src/list/row/show.rs +++ b/crates/ui-widgets/src/list/row/show.rs @@ -112,7 +112,8 @@ impl Component for ListRow<'_> { tone => row_ink_of(cx, cx.tone(tone), form), }, ), - toggle: IconLook::new(sizes.icon, quiet_row_ink(cx, form, text.muted)), + // A dimmed row's toggles dim with its name: the children of a hidden group read hidden all along the row. + toggle: IconLook::new(sizes.icon, quiet_row_ink(cx, form, muted)), toggle_off: IconLook::new(sizes.icon, quiet_row_ink(cx, form, text.faint)), detail: TextLook::new(TypeRole::Caption, ink(text.faint)), cell: TextLook::new(role, ink(base)), diff --git a/crates/ui-widgets/tests/it/list.rs b/crates/ui-widgets/tests/it/list.rs index d2c9d86711..7f828fcde4 100644 --- a/crates/ui-widgets/tests/it/list.rs +++ b/crates/ui-widgets/tests/it/list.rs @@ -1356,6 +1356,48 @@ fn a_toggle_glyph_rests_muted_and_reads_normal_under_the_pointer() { ); } +/// A dimmed row (a shape inside a hidden group) rests its on toggle in `text.faint` with its name, not in the +/// `text.muted` of an ordinary row's toggle. +#[trial] +fn a_dimmed_rows_toggle_glyph_rests_faint() { + use craft_behavior::{ColumnKey, ColumnWidth}; + use craft_ui::contract::{ColumnSpec, ToggleColumn}; + use craft_ui::list::{RowInk, ToggleCell}; + use craft_ui::runtime::env::Env; + use egui::Color32; + use std::cell::Cell; + const EYE: ColumnKey = ColumnKey::new("eye"); + const NAME: ColumnKey = ColumnKey::new("name"); + let seen = Rc::new(Cell::new((egui::Rect::NOTHING, Color32::TRANSPARENT))); + let held = seen.clone(); + let mut fixture = Fixture::new(move |ui| { + let text = Env::of(ui).tokens.tokens().color.text; + let [r, g, b, a] = text.faint.0; + let columns = vec![ColumnSpec::toggle(EYE, "", ToggleColumn::sweepable()), ColumnSpec::new(NAME, "", ColumnWidth::fill(1.0))]; + let keys = [0_usize]; + let source = keyed(&keys, |key: &usize| *key); + let _ = List::new("Layers").columns(columns).show_items(ui, &source, &mut |key, icx| { + held.set((icx.cell(&EYE).unwrap_or(egui::Rect::NOTHING), Color32::from_rgba_unmultiplied(r, g, b, a))); + ListRow::new(NAMES[*key]).cells(icx.cells()).toggle(ToggleCell::eye(EYE, true)).ink(RowInk::Dimmed) + }); + }); + fixture.room(Vec2::new(300.0, 200.0)); + fixture.settle(); + let (cell, faint) = seen.get(); + let mut tints: Vec = fixture + .frame_shapes() + .iter() + .filter_map(|shape| match shape { + egui::Shape::Mesh(mesh) if cell.contains(mesh.calc_bounds().center()) => Some(mesh.vertices.iter().map(|vertex| vertex.color)), + _ => None, + }) + .flatten() + .filter(|color| color.a() > 0) + .collect(); + tints.dedup(); + assert!(!tints.is_empty() && tints.iter().all(|tint| *tint == faint), "the dimmed row's eye rests in text.faint {faint:?}: {tints:?}"); +} + /// Two rows whose eye cell is on and whose lock cell is off; the source does not flip the first row's cells. struct LockedFirst; From bbfbcda742cb1a7c0592d76e154a3ce9ed4c2801 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 30 Nov 2026 03:23:44 +0000 Subject: [PATCH 5/5] BarItems: a checked command's item shows on A bar item whose command is checked got the toggle face, but its part carried no checked state, so the face painted off and the node did not read on (DeckCraft's Home in the Quick Access Toolbar while Home is open). The item's part now takes the checked flag. Co-Authored-By: Claude Opus 5.5 --- crates/ui-widgets/src/bars/items.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/ui-widgets/src/bars/items.rs b/crates/ui-widgets/src/bars/items.rs index c7852e12bb..b1b7953cf3 100644 --- a/crates/ui-widgets/src/bars/items.rs +++ b/crates/ui-widgets/src/bars/items.rs @@ -14,7 +14,7 @@ use crate::runtime::env::Label; use crate::style::{ComponentStyle, FocusLook, GlyphRole, StyleCx}; use craft_behavior::fit::{FitItem, FitKeep, fit_items}; use craft_behavior::{Axis, IconId, Metrics, NavShape, PartKey, PartRef, Proposal, Roving, Sense}; -use craft_theme::Variant; +use craft_theme::{Flags, Variant}; use egui::{Rect, Response, Vec2, pos2}; const ITEM: PartKey = PartKey::new("item"); @@ -439,7 +439,11 @@ impl Component for BarItems { } else { None }; - let part = cx.part(ITEM.at(index as u64), cell).sense(sense).focusable(); + let mut part = cx.part(ITEM.at(index as u64), cell).sense(sense).focusable(); + // A toggle item's face paints on, and its node reads on, from the part's state. + if present[index].resolved.checked == Some(true) { + part = part.flags(Flags::CHECKED); + } if let Some(tooltip) = tooltip { part.tooltip(tooltip); }