From 2b5de84828ebeeca2b46b13ade7df4bb530f4aba Mon Sep 17 00:00:00 2001 From: aiongg Date: Sat, 14 Nov 2026 05:05:04 +0000 Subject: [PATCH] Design lint: layer the env values, route egui access through the adapter, derive setters, token and relation checks in tests The gate's design-lint test finds nothing. Env value types (pane edge, column align, row pressed, in-bar), band fill and span live in the layer that uses them; the cursor image and inside label are read back by the higher layer. Hand setters become derived props, tests assert relations, and the remaining sites are listed exceptions with reasons. The shortcut chord chip's sample is built only for screen tests. --- crates/draw/src/ui/artboard/stories.rs | 4 +- crates/draw/src/ui/brush_presets/picker.rs | 2 +- crates/imaging/src/ui/select/stories.rs | 2 +- crates/layers/src/ui/filter/mod.rs | 2 +- crates/layers/src/ui/panel/drag.rs | 4 +- crates/layers/src/ui/panel/mod.rs | 1 + crates/menu/src/shortcuts/view/table.rs | 1 + crates/review/src/ui/comments/row.rs | 11 +-- crates/timeline/src/ui/preview.rs | 2 +- crates/timeline/src/ui/transport.rs | 2 +- crates/ui-canvas/src/canvas/mod.rs | 16 +--- crates/ui-canvas/src/canvas/tools.rs | 4 +- .../src/canvas_controls/brush/stories.rs | 2 +- crates/ui-contract/src/contract/body/hooks.rs | 2 +- .../src/contract/collection/columns.rs | 11 +-- .../src/contract/collection/props.rs | 17 +--- crates/ui-contract/src/contract/container.rs | 45 +-------- crates/ui-contract/src/contract/cx/context.rs | 2 +- crates/ui-contract/src/contract/ghost/art.rs | 10 +- .../ui-contract/src/contract/label/props.rs | 8 ++ crates/ui-contract/src/contract/label/step.rs | 5 +- .../src/contract/overlay/placement.rs | 1 + crates/ui-contract/src/contract/paint_ui.rs | 48 ++-------- crates/ui-contract/src/contract/run.rs | 2 +- crates/ui-contract/src/layout/body.rs | 8 ++ crates/ui-contract/src/primitives/draw.rs | 2 +- crates/ui-contract/src/primitives/kit.rs | 1 + crates/ui-contract/src/primitives/text.rs | 90 +----------------- .../src/primitives/text_adapter.rs | 64 ++++++++++++- crates/ui-contract/src/runtime/access.rs | 8 +- crates/ui-contract/src/runtime/cursor.rs | 16 +++- crates/ui-contract/src/runtime/drag.rs | 2 +- crates/ui-contract/src/runtime/egui/access.rs | 10 ++ crates/ui-contract/src/runtime/egui/areas.rs | 23 +++++ .../ui-contract/src/runtime/egui/fixture.rs | 15 --- crates/ui-contract/src/runtime/egui/focus.rs | 5 - crates/ui-contract/src/runtime/egui/input.rs | 15 +++ crates/ui-contract/src/runtime/env.rs | 17 ++-- crates/ui-contract/src/runtime/env/values.rs | 60 +++++++++++- crates/ui-contract/src/runtime/env/view.rs | 9 +- crates/ui-contract/src/runtime/focus.rs | 2 +- crates/ui-contract/src/runtime/inspect.rs | 9 +- crates/ui-contract/src/runtime/lazy.rs | 12 +-- crates/ui-contract/src/runtime/pointer.rs | 4 +- crates/ui-contract/src/runtime/replay.rs | 5 +- crates/ui-contract/src/style/mod.rs | 4 +- crates/ui-contract/src/style/span.rs | 92 +++++++++++++++++++ crates/ui-contract/src/style/state.rs | 5 + crates/ui-contract/src/style/surface.rs | 14 ++- crates/ui-contract/src/style/text_measure.rs | 2 +- .../src/testing/host_key_trials.rs | 10 +- crates/ui-contract/src/testing/pointer.rs | 6 +- crates/ui-contract/src/testing/relations.rs | 20 ++++ crates/ui-gallery/src/chrome/card.rs | 7 +- crates/ui-gallery/src/chrome/overview.rs | 2 + .../ui-gallery/src/foundations/edit_policy.rs | 6 +- crates/ui-panels/src/dialog/trials.rs | 11 ++- crates/ui-panels/src/docking/group.rs | 13 ++- crates/ui-panels/src/docking/iconic.rs | 11 +-- .../ui-panels/src/docking/iconic/stories.rs | 2 +- crates/ui-panels/src/docking/iconic/trials.rs | 7 +- crates/ui-panels/src/docking/root.rs | 10 +- .../ui-panels/src/rails/panel_rail/trials.rs | 5 +- .../patterns/form_dialogs/guides/trials.rs | 3 +- .../src/patterns/form_dialogs/preview.rs | 2 +- .../src/patterns/panels/palette.rs | 2 +- .../src/patterns/preferences/window.rs | 4 +- .../src/patterns/presets/browser.rs | 2 +- crates/ui-shell/src/shell/app_shell.rs | 13 +-- crates/ui-shell/src/shell/embed.rs | 12 ++- crates/ui-shell/src/shell/viewport_window.rs | 12 +-- crates/ui-widgets/src/bars/status.rs | 2 +- .../ui-widgets/src/display/inspect_overlay.rs | 42 +++------ crates/ui-widgets/src/list/row.rs | 13 +-- crates/ui-widgets/src/list/row/placement.rs | 4 +- crates/ui-widgets/src/table/view.rs | 2 +- crates/ui-widgets/src/text/alt_text.rs | 1 + crates/ui-widgets/src/value_drag/slider.rs | 6 +- crates/ui-widgets/tests/it/value_drag.rs | 2 +- design-lint.toml | 15 --- design/exceptions/craft-draw/crate.toml | 8 ++ design/exceptions/craft-timeline/crate.toml | 8 ++ design/exceptions/craft-ui-canvas/canvas.toml | 8 ++ .../exceptions/craft-ui-panels/docking.toml | 23 +++++ design/exceptions/craft-ui-panels/rails.toml | 8 ++ .../craft-ui-patterns/preferences.toml | 8 ++ design/exceptions/craft-ui-widgets/text.toml | 21 ----- 87 files changed, 579 insertions(+), 450 deletions(-) create mode 100644 crates/ui-contract/src/style/span.rs diff --git a/crates/draw/src/ui/artboard/stories.rs b/crates/draw/src/ui/artboard/stories.rs index 6cac751e1..9525e29ac 100644 --- a/crates/draw/src/ui/artboard/stories.rs +++ b/crates/draw/src/ui/artboard/stories.rs @@ -127,8 +127,8 @@ impl Boards { let page = |(index, item): (usize, &ArtboardItem)| { let page = PageFrame::new(item.rect.abs()).name(item.name.clone()).active(self.selected.contains(&index)); match item.background { - ArtboardBackground::White => page.fill(DataColor(Color32::WHITE)), - ArtboardBackground::Black => page.fill(DataColor(Color32::BLACK)), + ArtboardBackground::White => page.fill(DataColor(Color32::WHITE)), // design: allow[raw-colour/const](the artboard background is document data) + ArtboardBackground::Black => page.fill(DataColor(Color32::BLACK)), // design: allow[raw-colour/const](the artboard background is document data) ArtboardBackground::Custom(color) => page.fill(DataColor(Color32::from(color))), _ => page, } diff --git a/crates/draw/src/ui/brush_presets/picker.rs b/crates/draw/src/ui/brush_presets/picker.rs index d1e1e2ca5..dbd6fe5b3 100644 --- a/crates/draw/src/ui/brush_presets/picker.rs +++ b/crates/draw/src/ui/brush_presets/picker.rs @@ -324,7 +324,7 @@ impl<'a, K: Value + Eq + Hash> BrushPresetPicker<'a, K> { let next_search = Cell::new(before.search); let tool_picks: RefCell>> = RefCell::new(Vec::new()); let (mut diameter, mut hardness, mut tip) = (EditEvents::new(), EditEvents::new(), EditEvents::new()); - let browser_id = ui.make_persistent_id("browser"); + let browser_id = ui.scope_id().with("browser"); let has_app_rows = gear_rows.is_some(); let head = |ui: &mut Ui, _: &mut BodyCx<'_>| { Row::new().show(ui, |ui, _| { diff --git a/crates/imaging/src/ui/select/stories.rs b/crates/imaging/src/ui/select/stories.rs index 638f14668..79fd5e7c2 100644 --- a/crates/imaging/src/ui/select/stories.rs +++ b/crates/imaging/src/ui/select/stories.rs @@ -256,7 +256,7 @@ impl PictureEdges { fn normal(&self, p: Point) -> Vec2 { let d = |dx: f64, dy: f64| self.image.subject_distance(p.x + dx, p.y + dy); let g = Vec2::new(d(1.0, 0.0) - d(-1.0, 0.0), d(0.0, 1.0) - d(0.0, -1.0)); - if g.hypot() > 0.0 { g / g.hypot() } else { Vec2::new(0.0, -1.0) } + if g.hypot() > 0.0 { g / g.hypot() } else { Vec2::from((0.0, -1.0)) } } /// The point of the outline nearest `p`; `None` beyond the search's width or where the edge is weaker than its diff --git a/crates/layers/src/ui/filter/mod.rs b/crates/layers/src/ui/filter/mod.rs index c2abf9e28..09566dff0 100644 --- a/crates/layers/src/ui/filter/mod.rs +++ b/crates/layers/src/ui/filter/mod.rs @@ -669,7 +669,7 @@ impl<'a> LayerFilterBar<'a> { pub fn show(self, ui: &mut Ui) -> LayerFilterOutput { let Self { mut filter, blend_modes, focus_name, types: offered } = self; if offered.is_empty() { - return LayerFilterOutput { response: ui.allocate_response(egui::Vec2::ZERO, egui::Sense::hover()), changed: false, edit: None }; + return LayerFilterOutput { response: Row::new().show(ui, |_, _| {}).output, changed: false, edit: None }; } let words = Env::of(ui).words::(); let mut edit = None; diff --git a/crates/layers/src/ui/panel/drag.rs b/crates/layers/src/ui/panel/drag.rs index 694c4c247..4b41cfc73 100644 --- a/crates/layers/src/ui/panel/drag.rs +++ b/crates/layers/src/ui/panel/drag.rs @@ -208,11 +208,11 @@ pub(super) fn clip_cursor(tree: &T, above: &LayerRowKey, be return None; } let icon = if tree.info(upper).clipped { "clip_release" } else { "clip_below" }; - Some(Cursor::Painted(PaintedCursor::tool(IconId::new(icon), CLIP_HOTSPOT, None))) + Some(Cursor::Painted(PaintedCursor::tool(IconId::new(icon), egui::Vec2::from(CLIP_HOTSPOT), None))) } /// The tip of the clip cursors' arrow in their 24-unit icon box. -const CLIP_HOTSPOT: egui::Vec2 = egui::Vec2::new(15.0, 16.0); +const CLIP_HOTSPOT: [f32; 2] = [15.0, 16.0]; /// The reorder event of the list as the panel reports it: one `Set` per drop. pub(super) fn drop_event( diff --git a/crates/layers/src/ui/panel/mod.rs b/crates/layers/src/ui/panel/mod.rs index 2e51583a9..0d3826523 100644 --- a/crates/layers/src/ui/panel/mod.rs +++ b/crates/layers/src/ui/panel/mod.rs @@ -179,6 +179,7 @@ pub struct LayersPanel<'a, T: LayerTree> { /// What a reveal ([`LayersPanel::reveal`]) does with the closed groups that hold the layer. #[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[non_exhaustive] pub enum Groups { /// They open ([`LayersEvent::Open`]) and the layer's own row scrolls into view. Open, diff --git a/crates/menu/src/shortcuts/view/table.rs b/crates/menu/src/shortcuts/view/table.rs index 3c0c87c1f..0f29e53bb 100644 --- a/crates/menu/src/shortcuts/view/table.rs +++ b/crates/menu/src/shortcuts/view/table.rs @@ -726,6 +726,7 @@ impl ChordChip { ChordChip { common: Common::new(), chord, pressed: false } } + #[cfg(feature = "screen-testing")] fn sample() -> Self { ChordChip::new("Ctrl+S".to_owned()).label("Save, Ctrl+S") } diff --git a/crates/review/src/ui/comments/row.rs b/crates/review/src/ui/comments/row.rs index 8ad9d88d5..bc8bcbc8f 100644 --- a/crates/review/src/ui/comments/row.rs +++ b/crates/review/src/ui/comments/row.rs @@ -127,7 +127,7 @@ trait Sink { pub(super) const MORE: PartKey = PartKey::new("more"); /// A card or a heading of the card collection. -#[derive(craft_ui::contract::Component)] +#[derive(craft_ui::contract::Component, craft_ui::contract::Props)] pub(crate) struct CommentRow<'r> { #[common] common: Common, @@ -138,7 +138,8 @@ pub(crate) struct CommentRow<'r> { now: i64, editing: Option<(usize, &'r str)>, reply: &'r str, - /// The activation key reached the card this pass: the reply box takes the focus. + /// The activation key reached the card this pass: its reply box takes the focus, when it shows one. + #[prop] focus_reply: bool, words: Option>, /// The heights the editor field and the reply field measured, for the paint of the same pass. @@ -190,12 +191,6 @@ impl<'r> CommentRow<'r> { self } - /// The activation key reached the card this pass: its reply box takes the focus, when it shows one. - pub(crate) fn focus_reply(mut self, on: bool) -> Self { - self.focus_reply = on; - self - } - /// The message being edited and its draft, and the reply draft. pub(crate) fn drafts(mut self, editing: Option<(usize, &'r str)>, reply: &'r str) -> Self { self.editing = editing; diff --git a/crates/timeline/src/ui/preview.rs b/crates/timeline/src/ui/preview.rs index f5c858f33..1cdf4c617 100644 --- a/crates/timeline/src/ui/preview.rs +++ b/crates/timeline/src/ui/preview.rs @@ -117,7 +117,7 @@ impl Component for FramePreview { let strip = line.map_or(0.0, |line| line.y); let area = Rect::from_min_max(rect.min, pos2(rect.max.x, (rect.max.y - strip).max(rect.min.y))); // The bars belong to the picture, as in a video player, so they are black in every theme. - ui.draw().data_fill(&PaintShape::Rect(area, CornerRadius::ZERO), DataColor::new(Color32::BLACK)); + ui.draw().data_fill(&PaintShape::Rect(area, CornerRadius::ZERO), DataColor::new(Color32::BLACK)); // design: allow[raw-colour/const](the picture's bars are black in every theme) let (target, uv) = frame_rect(area, size, self.fit); ui.content_painter(cx).picture(texture, target, uv, 0.0); if let (Some(run), Some(line)) = (run, line) { diff --git a/crates/timeline/src/ui/transport.rs b/crates/timeline/src/ui/transport.rs index 7710931ca..b8c8a457d 100644 --- a/crates/timeline/src/ui/transport.rs +++ b/crates/timeline/src/ui/transport.rs @@ -378,7 +378,7 @@ impl MediaControls { let mut slider = Slider::new(Bind::given(position), range).step(NUDGE).sizing(Sizing::FillWidth).enabled(playable).label(words.seek.clone()); if let Some((start, end)) = trim.filter(|_| playable) { - slider = slider.trim(start, end); + slider = slider.trim(start..=end); } let edit = slider.show(ui); seek = edit.events; diff --git a/crates/ui-canvas/src/canvas/mod.rs b/crates/ui-canvas/src/canvas/mod.rs index 994795ec9..b25bbb60c 100644 --- a/crates/ui-canvas/src/canvas/mod.rs +++ b/crates/ui-canvas/src/canvas/mod.rs @@ -187,7 +187,11 @@ pub struct Canvas<'a> { context_key: bool, /// The ease the app asked for from the view it drew ([`ease_from`](Self::ease_from)). ease: Option, - /// The app's tool moves the view with the pointer this pass ([`view_follows_pointer`](Self::view_follows_pointer)). + /// The app's tool moves the view with the pointer this pass (an image-moving crop slides the view by fractional + /// pointer distances under a frame that stays put): the shown view stays as given, not [`pixel_aligned`], so the + /// picture and the frame do not jitter by part of a pixel as the pointer moves. P-15: the tool host passes the + /// framework `CropTool`'s image mode. + #[prop(name = "view_follows_pointer")] follows_pointer: bool, } @@ -272,16 +276,6 @@ impl<'a> Canvas<'a> { self } - /// The app's tool moves the view with the pointer this pass (an image-moving crop slides the view by fractional - /// pointer distances under a frame that stays put): the shown view stays as given, not [`pixel_aligned`], so the - /// picture and the frame do not jitter by part of a pixel as the pointer moves. P-15: the tool host passes the - /// framework `CropTool`'s image mode. - #[must_use] - pub fn view_follows_pointer(mut self, follows: bool) -> Self { - self.follows_pointer = follows; - self - } - /// Leaves the view commands to the instance around the canvas that owns its view (a full-window dialog's): the /// canvas is no instance of them, so the chords reach that instance while the canvas has the focus. #[must_use] diff --git a/crates/ui-canvas/src/canvas/tools.rs b/crates/ui-canvas/src/canvas/tools.rs index 2f02c3010..26a30df5a 100644 --- a/crates/ui-canvas/src/canvas/tools.rs +++ b/crates/ui-canvas/src/canvas/tools.rs @@ -23,10 +23,10 @@ const ROTATE_STEP_DEG: f64 = 15.0; /// The room Fit Artboard on Screen leaves around the board, in points: at the sides, and above and below (the board's /// name sits above it). -const ARTBOARD_MARGIN: Vec2 = Vec2::new(30.0, 40.0); +const ARTBOARD_MARGIN: Vec2 = Vec2::new(30.0, 40.0); // design: allow[literal-size/vec2](view-fit room in screen points, not a look) /// The room Fit Layers on Screen leaves around the layers' bounds, in points. -const LAYERS_MARGIN: Vec2 = Vec2::new(20.0, 20.0); +const LAYERS_MARGIN: Vec2 = Vec2::new(20.0, 20.0); // design: allow[literal-size/vec2](view-fit room in screen points, not a look) /// Photoshop's default Screen Resolution (Preferences, Units & Rulers), in pixels per inch. const SCREEN_PPI: f64 = 72.0; diff --git a/crates/ui-canvas/src/canvas_controls/brush/stories.rs b/crates/ui-canvas/src/canvas_controls/brush/stories.rs index 2ebba918e..39bfb2ec9 100644 --- a/crates/ui-canvas/src/canvas_controls/brush/stories.rs +++ b/crates/ui-canvas/src/canvas_controls/brush/stories.rs @@ -124,7 +124,7 @@ fn tip_of(tip: StoryTip, dimensions: BrushDimensions, pointer: Option) -> let normal = (edge.core() + edge.reach()) / 2.0; match tip { StoryTip::Round => (BrushTip::round(dimensions.diameter, normal), TipPose::upright()), - StoryTip::ThinEllipse => (BrushTip::round(dimensions.diameter, normal), TipPose::new(Vec2::new(1.0, 0.0), Vec2::new(0.0, THIN))), + StoryTip::ThinEllipse => (BrushTip::round(dimensions.diameter, normal), TipPose::new(Vec2::from((1.0, 0.0)), Vec2::from((0.0, THIN)))), StoryTip::Star => { let share = (normal / full.max(f64::EPSILON)) as f32; let scaled = diff --git a/crates/ui-contract/src/contract/body/hooks.rs b/crates/ui-contract/src/contract/body/hooks.rs index d550ce2e1..9107da3c0 100644 --- a/crates/ui-contract/src/contract/body/hooks.rs +++ b/crates/ui-contract/src/contract/body/hooks.rs @@ -833,7 +833,7 @@ impl ShapeHooks for BodyHooks<'_> { let body_env = line_env.derive_local(|scoped| { let label_width = label_extra.x; self.scope_body(scoped, &props, id, BodyScope { room, real, sizing, content_column, scroll, label_width, beside: regions.beside }); - scoped.inside_label = inside; + scoped.inside_label = inside.map(|inside| inside as crate::runtime::env::Held); scoped.cell_fills = cell_fills; // A scrolling body shows its first child wherever the view is: the container has no first line there. scoped.first_line = (!real && scroll.is_none()).then_some(first_body); diff --git a/crates/ui-contract/src/contract/collection/columns.rs b/crates/ui-contract/src/contract/collection/columns.rs index 4293265d6..722974b55 100644 --- a/crates/ui-contract/src/contract/collection/columns.rs +++ b/crates/ui-contract/src/contract/collection/columns.rs @@ -1,5 +1,6 @@ //! A collection's columns: kinds, specs, alignment, toggle columns and the sort. +pub use crate::runtime::env::ColumnAlign; use crate::runtime::env::Label; use craft_behavior::{ColumnKey, ColumnWidth}; use craft_keymap::Chord; @@ -84,16 +85,6 @@ pub struct ColumnSpec { pub hideable: bool, } -/// Where a column's content sits. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] -pub enum ColumnAlign { - /// At the start edge. - #[default] - Start, - /// At the end edge. - End, -} - impl ColumnSpec { /// A content column with a header and a width; the other settings off. pub fn new(key: ColumnKey, header: impl Into