mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 05:14:24 +00:00
Text and Icon stories: every cut place, every content colour, six icons at each control size and in each tone (prim:20, prim:22)
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user