From ab09b3fc286c2c8b88f08d13abc91adbf0c16fce Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 07:04:50 +0000 Subject: [PATCH] Design lint: rail trials compare within a point, story strip sizes from IconicSizes, dead rail exemptions removed --- crates/ui-panels/src/docking/floating/stories.rs | 15 ++++++++++++--- crates/ui-panels/src/rails/tool/stories.rs | 1 + crates/ui-panels/src/rails/tool/trials.rs | 15 ++++++++------- design-lint.toml | 5 ----- design/exceptions/craft-ui-panels/rails.toml | 9 --------- 5 files changed, 21 insertions(+), 24 deletions(-) delete mode 100644 design/exceptions/craft-ui-panels/rails.toml diff --git a/crates/ui-panels/src/docking/floating/stories.rs b/crates/ui-panels/src/docking/floating/stories.rs index 46b096218..65f0cd780 100644 --- a/crates/ui-panels/src/docking/floating/stories.rs +++ b/crates/ui-panels/src/docking/floating/stories.rs @@ -3,6 +3,7 @@ use super::{FloatingGroup, WindowColumn}; use crate::buttons::Button; use crate::contract::Show as _; +use crate::docking::IconicSizes; use crate::menu::MenuItem; use crate::testing::{Drive, StoryData, StoryOutput, story}; use craft_behavior::dock::DockEdge; @@ -10,6 +11,15 @@ use egui::{Pos2, Rect, Ui, Vec2}; const START: Rect = Rect { min: Pos2::new(40.0, 40.0), max: Pos2::new(280.0, 220.0) }; +/// The icons a collapsed story column shows: three panels. +const ICON_CELLS: f32 = 3.0; + +/// The size of a collapsed column of `ICON_CELLS` icon cells. +fn icon_strip(ui: &Ui) -> Vec2 { + let sizes = IconicSizes::of(ui.ctx()); + Vec2::new(sizes.cell, sizes.cell * ICON_CELLS) +} + #[story(FloatingGroup<'static>, covers = [Default], drive = Drive::Never)] fn floating_group(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let rect = *data.value("rect", START); @@ -32,8 +42,7 @@ fn floating_group(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { fn floating_dock_window(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let rect = *data.value("rect", START); let collapsed = *data.value("collapsed", false); - // A strip of three icon cells, as an iconic column of three panels is. - let column = if collapsed { WindowColumn::collapsed(DockEdge::Start, Vec2::new(40.0, 120.0)) } else { WindowColumn::expanded(DockEdge::Start) }; + let column = if collapsed { WindowColumn::collapsed(DockEdge::Start, icon_strip(ui)) } else { WindowColumn::expanded(DockEdge::Start) }; let shown = FloatingGroup::new("Layers", rect).column(column).sized(crate::contract::Sizing::Fill).show_group(ui, |ui, _| { Button::new(if collapsed { "L" } else { "Add layer" }).show(ui); }); @@ -50,7 +59,7 @@ fn floating_dock_window(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { #[story(FloatingGroup<'static>, covers = [Default], drive = Drive::Never)] fn floating_collapsed_window(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let rect = *data.value("rect", START); - let column = WindowColumn::collapsed(DockEdge::End, Vec2::new(40.0, 120.0)); + let column = WindowColumn::collapsed(DockEdge::End, icon_strip(ui)); let shown = FloatingGroup::new("Layers", rect).column(column).sized(crate::contract::Sizing::Fill).show_group(ui, |ui, _| { Button::new("L").show(ui); }); diff --git a/crates/ui-panels/src/rails/tool/stories.rs b/crates/ui-panels/src/rails/tool/stories.rs index 2dae5ea3f..1ded5d28d 100644 --- a/crates/ui-panels/src/rails/tool/stories.rs +++ b/crates/ui-panels/src/rails/tool/stories.rs @@ -50,6 +50,7 @@ fn tool_rail(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let width = ToolRail::::dock_grid(ui.ctx(), slots.len() + 1).width(u16::from(columns)); let out = ui .scope(|ui| { + // design: allow[contract/memory](the story gives the rail the width of its chosen columns, as a dock column does) ui.set_max_width(width); ToolRail::new("Tools", &slots, &BRUSH, &last).hidden(&hidden).edit_toolbar("Edit Toolbar").show_rail(ui, |_, _| {}) }) diff --git a/crates/ui-panels/src/rails/tool/trials.rs b/crates/ui-panels/src/rails/tool/trials.rs index 7b4702b97..e4209d747 100644 --- a/crates/ui-panels/src/rails/tool/trials.rs +++ b/crates/ui-panels/src/rails/tool/trials.rs @@ -66,7 +66,7 @@ fn a_tool_rail_lays_out_the_most_whole_columns_its_width_holds() { let (fixture, _) = rail_in(grid.width(steps), 800.0); assert_eq!(columns_of(&fixture), usize::from(steps), "a width of {steps} steps shows {steps} columns"); let rail = rect(&fixture, "Tools"); - assert!((rail.width() - grid.width(steps)).abs() < 1.0, "{steps} steps: the rail is as wide as its columns: {rail:?}"); + assert!(near(rail.width(), grid.width(steps)), "{steps} steps: the rail is as wide as its columns: {rail:?}"); if steps > 1 { let (short, _) = rail_in(grid.width(steps) - 1.0, 800.0); assert_eq!(columns_of(&short), usize::from(steps) - 1, "a width short of {steps} steps shows one column fewer"); @@ -86,13 +86,10 @@ fn a_tool_rail_measures_its_rows_plus_its_footer_at_a_width() { let (fixture, measured) = rail_in(grid.width(steps), 800.0); let (rail, foot, first) = (rect(&fixture, "Tools"), rect(&fixture, "Foot"), rect(&fixture, "Move")); let size = measured.get(); - assert!((size.y - rail.height()).abs() < 1.0, "{steps} steps: the measure ({size:?}) is the shown rail ({rail:?})"); - assert!((size.x - rail.width()).abs() < 1.0, "{steps} steps: the measure is as wide as the shown rail"); + assert!(near(size.y, rail.height()), "{steps} steps: the measure ({size:?}) is the shown rail ({rail:?})"); + assert!(near(size.x, rail.width()), "{steps} steps: the measure is as wide as the shown rail"); let (top, bottom) = (first.top() - rail.top(), rail.bottom() - foot.bottom()); - assert!( - (top - bottom).abs() < 1.0, - "{steps} steps: the rows and the footer fill the rail between equal paddings ({top} above, {bottom} below)" - ); + assert!(near(top, bottom), "{steps} steps: the rows and the footer fill the rail between equal paddings ({top} above, {bottom} below)"); heights.push(size.y); } assert!(grows_with(heights[1], heights[0]), "one column is taller than two: {heights:?}"); @@ -148,3 +145,7 @@ fn the_tool_rail_shows_its_buttons_icons_in_its_glyph_role() { assert!(tool.side > alone.side, "a tool rail icon ({}) is larger than a lone one ({})", tool.side, alone.side); assert!(tool.color.off.rest != tool.color.off.hover, "a tool rail icon rests quieter than under the pointer"); } + +fn near(a: f32, b: f32) -> bool { + (a - b).abs() < 1.0 +} diff --git a/design-lint.toml b/design-lint.toml index 435346267..b16e36d3d 100644 --- a/design-lint.toml +++ b/design-lint.toml @@ -3,11 +3,6 @@ paths = ["crates/behavior", "crates/ui", "crates/ui-contract", "crates/ui-widget include-tests = false deny-unused = true -[[exempt]] -path = "crates/ui-panels/src/rails/tool/trials.rs" -rules = ["literal-size"] -reason = "trial rooms, not looks" - [[exempt]] path = "crates/ui-panels/src/docking/iconic/trials.rs" rules = ["literal-size"] diff --git a/design/exceptions/craft-ui-panels/rails.toml b/design/exceptions/craft-ui-panels/rails.toml deleted file mode 100644 index 8fd2a55ab..000000000 --- a/design/exceptions/craft-ui-panels/rails.toml +++ /dev/null @@ -1,9 +0,0 @@ -config_version = 1 - -[[exception]] -name = "tool-rail-trial-rooms" -kind = "exempt" -rule = "literal-size" -path = "crates/ui-panels/src/rails/tool/trials.rs" -reason = "Trial rooms, not looks." -count = 1