From a36e14750fe0e0d97677c5bf7d5bd3385fb9df49 Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 20 Nov 2026 20:01:54 +0000 Subject: [PATCH] design-lint: the menu bar stories keep their model in a static; GridWidths::Content names the content's measured widths --- crates/menu/src/bar/stories.rs | 16 ++++++++-------- crates/ui-panels/src/docking/spec.rs | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/menu/src/bar/stories.rs b/crates/menu/src/bar/stories.rs index b21cde03a..b59aedca0 100644 --- a/crates/menu/src/bar/stories.rs +++ b/crates/menu/src/bar/stories.rs @@ -1,6 +1,6 @@ //! Stories of the in-window bar over a small model. -use std::sync::Arc; +use std::sync::{Arc, LazyLock}; use craft_ui::contract::Tracked; use craft_ui::testing::{Drive, Fixture, StoryData, StoryOutput, story}; @@ -40,15 +40,15 @@ fn build() -> MenuBar { layout(&bar, Target::Linux, &LayoutOptions::new("Sample")).bar } -/// The story's model, kept in the story's memory: a model made again each pass is a new source, and the bar would run each time. -fn model(ui: &Ui) -> Arc> { - let id = ui.scope_id().with("model"); - ui.data_mut(|data| data.get_temp_mut_or_insert_with(id, || Arc::new(Tracked::new(build()))).clone()) +/// The stories' model, made once: a model made again each pass is a new source, and the bar would run each time. +fn model() -> Arc> { + static MODEL: LazyLock>> = LazyLock::new(|| Arc::new(Tracked::new(build()))); + MODEL.clone() } #[story(MenuBarUi<'static>, covers = [Default], drive = Drive::Never)] fn menu_bar_ui(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { - MenuBarUi::new(&model(ui)).target(Target::Linux).show(ui); + MenuBarUi::new(&model()).target(Target::Linux).show(ui); StoryOutput::default() } @@ -60,12 +60,12 @@ fn open_window(fixture: &mut Fixture) { #[story(MenuBarUi<'static>, covers = [Open], drive = Drive::Custom(open_window))] fn menu_bar_ui_with_documents(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { - MenuBarUi::new(&model(ui)).target(Target::Linux).show(ui); + MenuBarUi::new(&model()).target(Target::Linux).show(ui); StoryOutput::default() } #[story(MenuBarUi<'static>, covers = [], drive = Drive::Never)] fn menu_bar_ui_with_help_search(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { - MenuBarUi::new(&model(ui)).target(Target::Linux).help_search(true).show(ui); + MenuBarUi::new(&model()).target(Target::Linux).help_search(true).show(ui); StoryOutput::default() } diff --git a/crates/ui-panels/src/docking/spec.rs b/crates/ui-panels/src/docking/spec.rs index 6af8a0ac2..2758a1cd1 100644 --- a/crates/ui-panels/src/docking/spec.rs +++ b/crates/ui-panels/src/docking/spec.rs @@ -69,7 +69,7 @@ pub struct DockGrid { enum GridWidths { /// `first`: the content's width at one column, a cell and the content's own padding on both sides; `step`: the /// width each further column adds, a cell and the gap before it. - Points { first: f32, step: f32 }, + Content { first: f32, step: f32 }, /// A tool rail's cells, sized by the dock's style. Rail, } @@ -77,7 +77,7 @@ enum GridWidths { impl DockGrid { /// A grid `first` wide at one column, `step` wider for each further column, up to `most` columns. pub const fn new(first: f32, step: f32, most: u16) -> Self { - DockGrid { widths: GridWidths::Points { first, step }, most } + DockGrid { widths: GridWidths::Content { first, step }, most } } /// The grid of a tool rail of `cells` cells: a rail button and the control padding on both sides at one column, @@ -89,7 +89,7 @@ impl DockGrid { /// The grid with its widths in points: a [`rail`](Self::rail) grid takes the rail widths of `sizes`. pub fn resolved(self, sizes: &DockSizes) -> Self { match self.widths { - GridWidths::Points { .. } => self, + GridWidths::Content { .. } => self, GridWidths::Rail => DockGrid::new(sizes.rail_first, sizes.rail_step, self.most), } } @@ -98,7 +98,7 @@ impl DockGrid { /// [`resolved`](Self::resolved). fn first_step(self) -> (f32, f32) { match self.widths { - GridWidths::Points { first, step } => (first, step), + GridWidths::Content { first, step } => (first, step), GridWidths::Rail => (0.0, 0.0), } }