mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
design-lint: the menu bar stories keep their model in a static; GridWidths::Content names the content's measured widths
This commit is contained in:
@@ -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<Tracked<MenuBar>> {
|
||||
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<Tracked<MenuBar>> {
|
||||
static MODEL: LazyLock<Arc<Tracked<MenuBar>>> = 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()
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user