From 3f9adf355dc768fd2466c22775df6ae35068fec3 Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 20 Nov 2026 17:04:18 +0000 Subject: [PATCH] Rulers: an edge and a centred face, picked by the component set `RulerFace { Edge, Centred }` sits beside `TickEdge`, and `RulerFace::of(set)` maps the creative set to Edge and the office set to Centred. The shared tick painter takes the face. Centred draws a bar inset in the strip by `space.gap.tight`, centres the marks on it, and puts a number in place of each whole-unit mark. No mark runs under a number (`RulerFace::beside_numbers`), so a whole-unit tick shows only where its number is dropped. TextRuler, VerticalRuler and canvas Rulers take an optional `face` prop in their style key. Unset, the style resolves it from the scope's set. PageRulers passes its face to both of its rulers, and the timeline ruler keeps the edge face. Under Centred: - the strip is on the chrome surface and the bar carries the margin shade and the text column on the well; - numbers show only over the text area and are dropped where a marker stands; - canvas Rulers shade their margin bands as the text ruler does. Edge is the look the rulers had before. Each ruler gets an edge and a centred story. --- crates/design-lint/src/workspace.rs | 1 + crates/pages/src/ui/page_rulers.rs | 98 +++++++++---- crates/pages/src/ui/page_rulers/stories.rs | 46 ++++++- crates/text/src/ui/ruler.rs | 18 ++- crates/text/src/ui/ruler/paint.rs | 69 ++++++---- crates/text/src/ui/ruler/stories.rs | 29 +++- crates/text/tests/it/ruler.rs | 130 ++++++++++++++++++ crates/timeline/src/ui/ruler.rs | 4 +- crates/ui-canvas/src/canvas/rulers/mod.rs | 130 +++++++++++++----- crates/ui-canvas/src/canvas/rulers/stories.rs | 35 ++++- crates/ui-contract/src/primitives/kit.rs | 116 ++++++++++++++-- crates/ui-contract/src/primitives/mod.rs | 4 +- 12 files changed, 567 insertions(+), 113 deletions(-) diff --git a/crates/design-lint/src/workspace.rs b/crates/design-lint/src/workspace.rs index 2475ff7b7..5e6a187c9 100644 --- a/crates/design-lint/src/workspace.rs +++ b/crates/design-lint/src/workspace.rs @@ -58,6 +58,7 @@ const CLOSED: &[&str] = &[ "ReorderMove", // built or matched in craft-ui-patterns "RowState", // built or matched in craft-ui-widgets "RuleLook", // built or matched in craft-ui-canvas + "RulerFace", // matched by every ruler (craft-text, craft-pages, craft-ui-canvas): a new face must be drawn by each "ShellRegions", // built or matched in craft-ui-shell "SizeLimits", // built or matched in craft-ui-panels "StoryOutput", // built or matched in craft-ui-widgets diff --git a/crates/pages/src/ui/page_rulers.rs b/crates/pages/src/ui/page_rulers.rs index e19df84a0..ea8be6eb3 100644 --- a/crates/pages/src/ui/page_rulers.rs +++ b/crates/pages/src/ui/page_rulers.rs @@ -17,7 +17,7 @@ use craft_ui::contract::{ Access, Bind, Common, Component, Cx, Focus as _, IdSource, Input, MeasureCx, Name, NoValue, Numeric, Outcome, PaintUi, PartsCx, Pointer as _, Props as _, Remember as _, Role, Show as _, Styled as _, WordSetCx as _, }; -use craft_ui::primitives::{PaintShape, StrokeWidth, TextRun, Tick, TickEdge, TickRank}; +use craft_ui::primitives::{PaintShape, RulerFace, StrokeWidth, TextRun, Tick, TickEdge, TickRank}; use craft_ui::runtime::env::{Env, Label}; use craft_ui::runtime::focus::{ActivateKeys, FocusShape, KeyUse}; use craft_ui::style::{ComponentStyle, FocusLook, StyleColor, StyleCx, TextLook, TypeRole}; @@ -80,6 +80,10 @@ pub struct VerticalRulerStyle { metrics: Metrics, #[style(focus)] focus: FocusLook, + /// The face: the prop's, else the component set's. + face: RulerFace, + /// The strip round the centred face's bar. + strip: StyleColor, /// The text range. fill: StyleColor, /// The margins above and below it. @@ -113,6 +117,9 @@ struct Held(Option<(usize, f32)>); /// shaded as margin and the text range filled, and a drag of a grip is one gesture. /// /// - Ticks and numbers count from the page's top in the unit, through the canvas rulers' tick rule. +/// - The face ([`RulerFace`]) is the prop's, else the component set's: the edge face hangs the ticks from the strip's +/// inner edge with each number below its whole-unit tick; the centred face (Word's) draws a bar inset in the strip +/// with the ticks centred on it and the numbers in place of the whole-unit ticks, over the text range only. /// - A grip drag reports a [`RowDrag`]: Begin, Update per move, Commit on release, Cancel on Escape. It snaps to the /// ruler's step; Alt reports in `mods` that the drag is free of the snap and the position is not snapped. /// - The grips are one Tab stop: Page Down and Page Up pick the next or previous grip, the arrows nudge the focused one @@ -133,13 +140,17 @@ pub struct VerticalRuler<'a> { /// The table row bottoms, points from the page's top, each a grip. #[prop] rows: &'a [f32], + /// The face; unset, the scope's component set picks it ([`RulerFace::of`]). + #[style_key] + #[prop] + face: Option, report: Option, } impl<'a> VerticalRuler<'a> { /// The ruler named `label` along `page`. pub fn new(label: impl Into