diff --git a/crates/ui-widgets/src/display/icon/stories.rs b/crates/ui-widgets/src/display/icon/stories.rs index 81c5f3810..5189c790b 100644 --- a/crates/ui-widgets/src/display/icon/stories.rs +++ b/crates/ui-widgets/src/display/icon/stories.rs @@ -1,13 +1,37 @@ //! Stories of `Icon`. use super::Icon; -use crate::contract::{Props as _, Show as _}; +use crate::contract::{Props as _, Show as _, ShowContainer as _}; +use crate::layout_components::Grid; use crate::primitives::IconSpec; use crate::testing::{Drive, StoryData, StoryOutput, story}; -use craft_behavior::IconId; +use craft_behavior::{ColumnWidth, IconId}; +use craft_theme::ControlSize; +use craft_theme::variant::Tone; use egui::Ui; #[story(Icon<'static>, covers = [Default], drive = Drive::Never)] fn icon(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { Icon::new(IconSpec::svg(IconId::new("settings"))).label("Settings").show(ui).into() } + +/// Six icons at each control size (an icon's side is its control size's icon side), then one in each tone. +#[story(Icon<'static>, covers = [], drive = Drive::Never)] +fn icon_sizes(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { + const ICONS: [&str; 6] = ["settings", "undo", "redo", "copy", "trash", "eye"]; + const COLUMNS: &[ColumnWidth] = &[ColumnWidth::Content; 6]; + let sizes = [("Sm", ControlSize::Sm), ("Md", ControlSize::Md)]; + let tones = [Tone::Neutral, Tone::Accent, Tone::Info, Tone::Good, Tone::Warn, Tone::Bad]; + Grid::new(COLUMNS) + .show(ui, |ui, _| { + for (name, size) in sizes { + for icon in ICONS { + Icon::new(IconSpec::svg(IconId::new(icon))).size(size).id_salt((name, icon)).show(ui); + } + } + for (tone, icon) in tones.into_iter().zip(ICONS) { + Icon::new(IconSpec::svg(IconId::new(icon))).tone(tone).id_salt(("tone", icon)).show(ui); + } + }) + .into() +} diff --git a/crates/ui-widgets/src/display/text/stories.rs b/crates/ui-widgets/src/display/text/stories.rs index 8e1198c46..da0babe0e 100644 --- a/crates/ui-widgets/src/display/text/stories.rs +++ b/crates/ui-widgets/src/display/text/stories.rs @@ -1,9 +1,11 @@ //! Stories of `Text`. use super::{Elide, Shade, Text}; -use crate::contract::Show as _; +use crate::contract::{Props as _, Show as _, ShowContainer as _}; +use crate::layout_components::{Grid, Row}; use crate::style::TypeRole; use crate::testing::{Drive, StoryData, StoryOutput, story}; +use craft_behavior::ColumnWidth; use craft_theme::variant::Tone; use egui::Ui; @@ -49,7 +51,7 @@ fn text_elided(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { ("Mono", TypeRole::Mono), ], ); - let elide = *data.choice("elide", Elide::End, &[("End", Elide::End), ("Path", Elide::Path)]); + let elide = *data.choice("elide", Elide::End, &[("End", Elide::End), ("Middle", Elide::Middle), ("Start", Elide::Start), ("Path", Elide::Path)]); Text::new(text).role(role).elide(elide).show(ui).into() } @@ -57,3 +59,46 @@ fn text_elided(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { fn text_toned(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { Text::new("Enter a value between 0 and 100").role(TypeRole::Caption).tone(Tone::Bad).show(ui).into() } + +/// One line each, cut at the end, the middle and the start, a path that drops leading folders, and a right-to-left +/// name that keeps its logical start. +#[story(Text, covers = [], drive = Drive::Never)] +fn text_elide_places(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { + // A room narrower than every text, so each one shows its cut. + const COLUMNS: &[ColumnWidth] = &[ColumnWidth::Content, ColumnWidth::Fixed(160.0)]; + let name = "IMG_2024_summer_holiday_final_edit.psd"; + let rows = [ + ("End", name, Elide::End), + ("Middle", name, Elide::Middle), + ("Start", name, Elide::Start), + ("Path", "/home/ada/Pictures/2026/summer holiday/IMG_2024.psd", Elide::Path), + ("Right to left", "שם קובץ ארוך מאוד שלא נכנס בשורה אחת של הפאנל.psd", Elide::End), + ]; + Grid::new(COLUMNS) + .show(ui, |ui, _| { + for (place, text, elide) in rows { + Text::new(place).shade(Shade::Muted).id_salt(("place", place)).show(ui); + Text::new(text).elide(elide).id_salt(("text", place)).show(ui); + } + }) + .into() +} + +/// Every content colour: the shades, the tones and the disabled colour. Text on a fill reads the host's ink. +#[story(Text, covers = [], drive = Drive::Never)] +fn text_contents(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { + let shades = [("Normal", Shade::Normal), ("Muted", Shade::Muted), ("Faint", Shade::Faint)]; + let tones = [("Accent", Tone::Accent), ("Info", Tone::Info), ("Good", Tone::Good), ("Warn", Tone::Warn), ("Bad", Tone::Bad)]; + Row::new() + .wrap(true) + .show(ui, |ui, _| { + for (name, shade) in shades { + Text::new(name).role(TypeRole::Label).shade(shade).id_salt(name).show(ui); + } + for (name, tone) in tones { + Text::new(name).role(TypeRole::Label).tone(tone).id_salt(name).show(ui); + } + Text::new("Disabled").role(TypeRole::Label).enabled(false).id_salt("disabled").show(ui); + }) + .into() +}