diff --git a/Cargo.toml b/Cargo.toml index 3065d956..763dd987 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,8 @@ default = ["clipboard"] # The system clipboard, read on demand through `Shell::read_clipboard`. # Without it, or on wasm, a read answers `ClipboardError::Unavailable`. clipboard = ["dep:arboard"] +# Bundles Geist (SIL OFL 1.1, src/fonts/OFL.txt), 165 KiB, as the tokens' font. +fonts = [] # `testing::Driver`: drives a view through kittest's harness in tests. Enable # it in a dev-dependency. driver = ["dep:egui_kittest"] diff --git a/README.md b/README.md index 2fd47657..0b45499e 100644 --- a/README.md +++ b/README.md @@ -120,4 +120,4 @@ MIT The symbol fallback face (`src/fonts/DejaVuSans-symbols.ttf`) is a subset of DejaVu Sans, under the licence in `src/fonts/DejaVuSans-LICENSE.txt` (Bitstream Vera with public-domain changes). `src/fonts/README.md` says how it was made. -The `eggshell-ui-shadcn` crate's `fonts` feature bundles Geist (`crates/eggshell-ui-shadcn/fonts/Geist-Variable.ttf`), under the SIL Open Font License 1.1 in `crates/eggshell-ui-shadcn/fonts/OFL.txt`. +The `eggshell-ui-shadcn` crate's `fonts` feature bundles Geist (`src/fonts/Geist-Variable.ttf`), under the SIL Open Font License 1.1 in `src/fonts/OFL.txt`. diff --git a/crates/eggshell-ui-extras/src/badge/chip.rs b/crates/eggshell-ui-extras/src/badge/chip.rs index 16c8119a..d964d111 100644 --- a/crates/eggshell-ui-extras/src/badge/chip.rs +++ b/crates/eggshell-ui-extras/src/badge/chip.rs @@ -264,7 +264,7 @@ fn still(mut look: Look) -> Look { fn focus_ring(look: Look, core: &Style, enablement: Enablement) -> Tw { match enablement { Enablement::Enabled => { - let ring = look.paint.focus.unwrap_or(core.tokens.focus); + let ring = look.paint.focus.unwrap_or(core.tokens.focus()); let border = look.paint.states.focused.border; tw().focus_within(|p| p.border_color(border).ring(ring.width, ring.color)) } diff --git a/crates/eggshell-ui-extras/src/command/list.rs b/crates/eggshell-ui-extras/src/command/list.rs index a9980f0c..251111a1 100644 --- a/crates/eggshell-ui-extras/src/command/list.rs +++ b/crates/eggshell-ui-extras/src/command/list.rs @@ -505,7 +505,7 @@ pub(crate) fn group_classes(style: &Style) -> Tw { &[eggshell_ui::sheet::Key::Size(size)], &style.tokens, ); - let focus = style.tokens.focus; + let focus = style.tokens.focus(); trigger .w_auto() .justify_start() diff --git a/crates/eggshell-ui-extras/src/disclosure/style.rs b/crates/eggshell-ui-extras/src/disclosure/style.rs index 4e8bdefd..e812e241 100644 --- a/crates/eggshell-ui-extras/src/disclosure/style.rs +++ b/crates/eggshell-ui-extras/src/disclosure/style.rs @@ -121,7 +121,7 @@ impl DisclosureStyle { tone_opacity: style.select().chevron_opacity, nudge: 2.0, header: HeaderStyle { - ring: style.tokens.focus, + ring: style.tokens.focus(), focus_border: None, radius: 6, padding_y: 16.0, diff --git a/crates/eggshell-ui-extras/src/markdown/style.rs b/crates/eggshell-ui-extras/src/markdown/style.rs index 25183674..67e71e4c 100644 --- a/crates/eggshell-ui-extras/src/markdown/style.rs +++ b/crates/eggshell-ui-extras/src/markdown/style.rs @@ -1,8 +1,9 @@ //! How the Markdown widget looks. -use eggshell_ui::contract::{Em, Tokens}; +use eggshell_ui::contract::Em; use eggshell_ui::owned::TablePart; use eggshell_ui::sheet::Sheet; +use eggshell_ui::theme::Tokens; use eggshell_ui::{Style, TextSpec, Tracking, Tw, Weight}; use egui::{Color32, FontFamily}; diff --git a/crates/eggshell-ui-shadcn/Cargo.toml b/crates/eggshell-ui-shadcn/Cargo.toml index d0941a72..7f9c18a7 100644 --- a/crates/eggshell-ui-shadcn/Cargo.toml +++ b/crates/eggshell-ui-shadcn/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/samitbasu/eggshell" [features] default = ["fonts"] # Bundles Geist (SIL OFL 1.1, fonts/OFL.txt), 165 KiB, as the preset's font. -fonts = [] +fonts = ["eggshell-ui/fonts"] # Fills the looks of eggshell-ui-extras' widgets from the preset's tokens. extras = [ "dep:eggshell-ui-extras", diff --git a/crates/eggshell-ui-shadcn/README.md b/crates/eggshell-ui-shadcn/README.md index 83b32886..e3268505 100644 --- a/crates/eggshell-ui-shadcn/README.md +++ b/crates/eggshell-ui-shadcn/README.md @@ -6,14 +6,14 @@ application calls `Shadcn::apply` (or `Shadcn::apply_both`). ## Fonts With the default `fonts` feature the preset bundles **Geist**, shadcn's -default sans-serif, as one variable font, `fonts/Geist-Variable.ttf` +default sans-serif, as one variable font, `src/fonts/Geist-Variable.ttf` (`Geist[wght].ttf` from [vercel/geist-font](https://github.com/vercel/geist-font) v1.9.2, 165 KiB). `Shadcn::apply` registers it at 400, 500, 600 and 700, so `font_medium()`, `font_semibold()` and `font_bold()` draw real faces, and the preset's buttons, labels and menu headings take shadcn's weights. Geist is licensed under the SIL Open Font License 1.1; the licence is shipped -beside the font in [`fonts/OFL.txt`](fonts/OFL.txt) and applies to the font +beside the font in [`src/fonts/OFL.txt`](../../src/fonts/OFL.txt) and applies to the font file only. The crate's code is MIT. - Swap the font with `Shadcn::with_fonts(Some(FontSet::variable(..)))` or diff --git a/crates/eggshell-ui-shadcn/src/lib.rs b/crates/eggshell-ui-shadcn/src/lib.rs index 67fe7faa..bd0f0402 100644 --- a/crates/eggshell-ui-shadcn/src/lib.rs +++ b/crates/eggshell-ui-shadcn/src/lib.rs @@ -101,25 +101,17 @@ //! so a hover on a `muted` surface needs the half-strength variant of the //! selected colour, not a different token. -mod contrast; mod drag_chip; -mod fonts; -mod palette; mod preset; #[rustfmt::skip] mod sheets; -mod styles; -mod theme_color; -mod tokens; -pub use contrast::{ContrastPair, ContrastRatio, REGISTRY_MISSES, RegistryMiss}; pub use drag_chip::{DragChip, drag_chip}; -pub use fonts::FontSet; -pub use palette::{BaseColor, Palette}; +pub use eggshell_ui::theme::{ + BaseColor, ContrastPair, ContrastRatio, Elevation, FontSet, HoverSurface, Palette, + REGISTRY_MISSES, RegistryMiss, ShadcnStyle, ThemeColor, Tokens, +}; pub use preset::{Shadcn, tokens}; -pub use styles::{Elevation, HoverSurface, ShadcnStyle}; -pub use theme_color::ThemeColor; -pub use tokens::Tokens; /// The names of the button sizes this preset defines besides the default. pub mod size { diff --git a/crates/eggshell-ui-shadcn/src/preset.rs b/crates/eggshell-ui-shadcn/src/preset.rs index e8baa925..cf3cc6e3 100644 --- a/crates/eggshell-ui-shadcn/src/preset.rs +++ b/crates/eggshell-ui-shadcn/src/preset.rs @@ -11,10 +11,10 @@ use eggshell_ui::sheet::{Sheet, When}; use eggshell_ui::{Aria, Easing, Match, Opacity, TextSpec, Weight}; use egui::{Color32, Context, Id, Shadow, Theme, vec2}; -use crate::styles::{HoverSurface, ShadcnStyle}; #[cfg(feature = "extras")] use crate::variant; use crate::{ContrastPair, FontSet, Palette, Tokens, size}; +use crate::{HoverSurface, ShadcnStyle}; /// TODO(prose): eggshell's smaller fields, which shadcn does not draw: a `sm` /// field a unit shorter than the preset's controls and a `xs` one three, each @@ -230,10 +230,6 @@ impl Shadcn { let t = &self.tokens; let dark = self.theme == Theme::Dark; let clear = Color32::TRANSPARENT; - let ring = Focus { - width: t.ring_width, - color: t.ring.gamma_multiply(0.5), - }; let focused = |rest: Colors| self.focused(rest); let flat = |fill, text| Colors { fill, @@ -748,8 +744,7 @@ impl Shadcn { exit: Duration::from_millis(300), easing: Easing::InOut, }; - style.tokens = self.core_tokens(); - style.tokens.focus = ring; + style.tokens = self.tokens.clone(); style.sheet.as_preset(); style.rewrite_rules(); if dark { @@ -778,43 +773,6 @@ impl Shadcn { style } - /// The preset's tokens as core's design-system-neutral set. - fn core_tokens(&self) -> contract::Tokens { - let t = &self.tokens; - let mut core = contract::Tokens::from_egui(&egui::Style::default()); - core.background = t.background; - core.foreground = t.foreground; - core.card = t.card; - core.card_foreground = t.card_foreground; - core.popover = t.popover; - core.popover_foreground = t.popover_foreground; - core.primary = t.primary; - core.primary_foreground = t.primary_foreground; - core.secondary = t.secondary; - core.secondary_foreground = t.secondary_foreground; - core.muted = t.muted; - core.muted_foreground = t.muted_foreground; - core.accent = t.accent; - core.accent_foreground = t.accent_foreground; - core.destructive = t.destructive; - core.destructive_foreground = t.destructive_foreground; - core.border = t.border; - core.input = t.input; - core.ring = t.ring; - core.spacing = t.spacing; - core.radius = t.radius; - core.text = t.text; - core.control_height = t.control_height(); - core.button_padding = t.points_vec(t.button_padding); - core.text_size = t.control_text_size().size; - core.switch_thumb = t.points(t.switch_thumb); - core.shadow_xs = t.shadow_xs; - core.shadow_sm = t.shadow_sm; - core.shadow_md = t.shadow_md; - core.shadow_lg = t.shadow_lg; - core - } - /// This preset drawing its text in `font`, or with `None` in egui's /// fonts as the application has set them. #[must_use] @@ -838,7 +796,7 @@ impl Shadcn { /// unless the tokens accept it or it is shadcn's own colour; it never /// changes a colour. pub fn apply(&self, ctx: &Context) { - crate::contrast::warn_low_contrast(ctx, self.theme, &self.tokens); + eggshell_ui::theme::warn_low_contrast(ctx, self.theme, &self.tokens); if let Some(font) = &self.tokens.font { font.install(ctx); } @@ -1090,7 +1048,7 @@ impl Shadcn { disclosure.tone = Some(t.muted_foreground); disclosure.tone_opacity = Opacity::new(1.0); disclosure.nudge = 2.0; - disclosure.header.ring = style.tokens.focus; + disclosure.header.ring = style.tokens.focus(); disclosure.header.focus_border = Some(t.ring); disclosure.header.radius = if lyra { 0 } else { t.radius_md() }; disclosure.header.padding_y = if lyra { 10.0 } else { 16.0 }; diff --git a/crates/eggshell-ui-shadcn/tests/styles.rs b/crates/eggshell-ui-shadcn/tests/styles.rs index 296cfb28..1036abd6 100644 --- a/crates/eggshell-ui-shadcn/tests/styles.rs +++ b/crates/eggshell-ui-shadcn/tests/styles.rs @@ -84,7 +84,7 @@ fn lyra_values_are_style_lyra_css() { (Some(32.0), 0), "h-8 rounded-none" ); - assert_eq!(style.tokens.focus.width, 1.0); + assert_eq!(style.tokens.focus().width, 1.0); assert_eq!(style.text.size, 12.0); assert_eq!(style.checkbox().sizes.get(Size::DEFAULT).radius, 0); assert_eq!(style.slider.sizes.get(Size::DEFAULT).radius, 0); @@ -144,7 +144,7 @@ fn style_light_dark_and_theme_colour_vary_independently() { ( box_of(&s, Size::DEFAULT), field_of(&s, Size::DEFAULT).0, - s.tokens.focus.width, + s.tokens.focus().width, ) }; let reference = sizes(Theme::Light, ThemeColor::Base); @@ -180,10 +180,10 @@ fn the_ring_is_the_neutral_ring_under_every_theme_colour() { preset.tokens.ring, neutral.tokens.ring, "{theme:?} {color:?}: the registry's coloured themes leave `ring` to the base colour" ); - let ring = preset.style().tokens.focus.color; + let ring = preset.style().tokens.focus().color; assert_eq!( ring, - neutral.style().tokens.focus.color, + neutral.style().tokens.focus().color, "{theme:?} {color:?}" ); } diff --git a/src/contract.rs b/src/contract.rs index 681d28ff..6c35d81b 100644 --- a/src/contract.rs +++ b/src/contract.rs @@ -19,6 +19,7 @@ use std::time::Duration; use egui::{Color32, Context, FontFamily, Id, Shadow, Theme, Vec2, vec2}; pub use crate::presence::{Entry, KindMotion, MotionStyle}; +use crate::theme::Tokens; use crate::{Faces, Opacity, Progress, TextSpec, Tracking, Weight}; /// A button variant, named by the style that defines it. @@ -1425,124 +1426,6 @@ fn extensions_id() -> egui::Id { crate::key::root_id().with("extensions") } -/// TODO(prose): a design system's named values, neutral of any one: its colours and the few sizes egui's own widgets are given. -#[derive(Clone, Copy, Debug, PartialEq)] -#[non_exhaustive] -pub struct Tokens { - /// TODO(prose): the page. - pub background: Color32, - /// TODO(prose): text on the page. - pub foreground: Color32, - /// TODO(prose): a card's fill. - pub card: Color32, - /// TODO(prose): text on a card. - pub card_foreground: Color32, - /// TODO(prose): a popover's fill: menus, windows. - pub popover: Color32, - /// TODO(prose): text on a popover. - pub popover_foreground: Color32, - /// TODO(prose): the primary action's fill. - pub primary: Color32, - /// TODO(prose): text on the primary fill. - pub primary_foreground: Color32, - /// TODO(prose): a secondary action's fill. - pub secondary: Color32, - /// TODO(prose): text on the secondary fill. - pub secondary_foreground: Color32, - /// TODO(prose): a muted surface. - pub muted: Color32, - /// TODO(prose): muted text. - pub muted_foreground: Color32, - /// TODO(prose): a hovered or active item's fill. - pub accent: Color32, - /// TODO(prose): text on the accent fill. - pub accent_foreground: Color32, - /// TODO(prose): a destructive action's colour. - pub destructive: Color32, - /// TODO(prose): text on the destructive fill. - pub destructive_foreground: Color32, - /// TODO(prose): borders. - pub border: Color32, - /// TODO(prose): an input's border and fill tint. - pub input: Color32, - /// TODO(prose): the focus ring. - pub ring: Color32, - /// TODO(prose): the keyboard focus indicator every control draws unless its look names its own. - pub focus: Focus, - /// TODO(prose): how disabled controls are drawn. - pub disabled: Disabled, - /// TODO(prose): the points one spacing unit is. - pub spacing: Spacing, - /// TODO(prose): the corner radii. - pub radius: Radius, - /// TODO(prose): the text sizes. - pub text: TextScale, - /// TODO(prose): a control's height. - pub control_height: f32, - /// TODO(prose): a button's padding. - pub button_padding: Vec2, - /// TODO(prose): the body text size. - pub text_size: f32, - /// TODO(prose): a switch's thumb, egui's checkbox and radio size. - pub switch_thumb: f32, - /// TODO(prose): the smallest shadow: a control at rest. - pub shadow_xs: Shadow, - /// TODO(prose): a small shadow: a slider's thumb, a tab. - pub shadow_sm: Shadow, - /// TODO(prose): a medium shadow: a menu, a popover. - pub shadow_md: Shadow, - /// TODO(prose): a large shadow: a dialog. - pub shadow_lg: Shadow, -} - -impl Tokens { - /// Tokens read off egui's own style. - pub fn from_egui(egui: &egui::Style) -> Self { - let v = &egui.visuals; - let w = &v.widgets; - Self { - background: v.panel_fill, - foreground: v.text_color(), - card: v.panel_fill, - card_foreground: v.text_color(), - popover: v.window_fill, - popover_foreground: v.text_color(), - primary: v.selection.bg_fill, - primary_foreground: v.selection.stroke.color, - secondary: w.inactive.weak_bg_fill, - secondary_foreground: w.inactive.fg_stroke.color, - muted: v.faint_bg_color, - muted_foreground: v.weak_text_color(), - accent: w.active.weak_bg_fill, - accent_foreground: w.active.fg_stroke.color, - destructive: v.error_fg_color, - destructive_foreground: v.text_color(), - border: v.window_stroke.color, - input: w.inactive.bg_stroke.color, - ring: w.active.bg_stroke.color, - focus: Focus { - width: 2.0, - color: v.selection.bg_fill, - }, - disabled: Disabled::Colors, - spacing: Spacing::DEFAULT, - radius: Radius::new(f32::from(w.inactive.corner_radius.nw)), - text: TextScale::default(), - control_height: egui.spacing.interact_size.y, - button_padding: egui.spacing.button_padding, - text_size: egui - .text_styles - .get(&egui::TextStyle::Body) - .map_or(14.0, |font| font.size), - switch_thumb: egui.spacing.icon_width, - shadow_xs: Shadow::NONE, - shadow_sm: Shadow::NONE, - shadow_md: v.popup_shadow, - shadow_lg: v.window_shadow, - } - } -} - /// TODO(prose): the fonts a style is drawn in, added to egui as a layout first builds with the style. #[derive(Clone, Debug, Default)] pub struct Fonts(pub Vec); @@ -1769,7 +1652,7 @@ impl Style { ..metrics }; let track = vec2(2.0 * s.icon_width, s.icon_width); - let tokens = Tokens::from_egui(egui); + let tokens = Tokens::light(); let mut sheet = crate::sheet::Sheet::defaults(); crate::owned::select_defaults( &mut sheet, @@ -2150,7 +2033,7 @@ impl Style { border_width: v.widgets.noninteractive.bg_stroke.width.max(1.0), radius, padding: f32::from(s.window_margin.left), - bare_padding: tokens.focus.clearance(), + bare_padding: tokens.focus().clearance(), selected_ring: v.selection.stroke.color, }, rich: RichTextStyle { diff --git a/src/draw.rs b/src/draw.rs index 2a8fa8b0..1021418a 100644 --- a/src/draw.rs +++ b/src/draw.rs @@ -1200,7 +1200,7 @@ impl Walk<'_, A> { && !interaction.variants.has_focus() && response.as_ref().is_some_and(Response::has_focus) { - let ring = node.style.tokens.focus; + let ring = node.style.tokens.focus(); self.painter(parent.clip, opacity).add(RectShape::stroke( boxes.border, look.paint.radius, diff --git a/src/egui_look.rs b/src/egui_look.rs index 8286f28f..97829bf0 100644 --- a/src/egui_look.rs +++ b/src/egui_look.rs @@ -8,7 +8,8 @@ use egui::{ }; use crate::Style; -use crate::contract::{Tokens, corner}; +use crate::contract::corner; +use crate::theme::Tokens; impl Tokens { fn widget( @@ -105,19 +106,21 @@ impl Style { v.popup_shadow = overlay; let s = &mut style.spacing; - s.interact_size.y = t.control_height; - s.button_padding = t.button_padding; + s.interact_size.y = t.control_height(); + s.button_padding = t.points_vec(t.button_padding); s.item_spacing = vec2(8.0, 8.0); - s.icon_width = t.switch_thumb; - s.icon_width_inner = t.switch_thumb * 0.625; + let switch_thumb = t.points(t.switch_thumb); + s.icon_width = switch_thumb; + s.icon_width_inner = switch_thumb * 0.625; s.icon_spacing = 8.0; s.combo_height = 400.0; s.window_margin = Margin::same(16); s.menu_margin = Margin::same(4); + let text_size = t.control_text_size().size; for text_style in [TextStyle::Body, TextStyle::Button, TextStyle::Monospace] { if let Some(font) = style.text_styles.get_mut(&text_style) { - font.size = t.text_size; + font.size = text_size; } } } diff --git a/crates/eggshell-ui-shadcn/fonts/Geist-Variable.ttf b/src/fonts/Geist-Variable.ttf similarity index 100% rename from crates/eggshell-ui-shadcn/fonts/Geist-Variable.ttf rename to src/fonts/Geist-Variable.ttf diff --git a/crates/eggshell-ui-shadcn/fonts/OFL.txt b/src/fonts/OFL.txt similarity index 100% rename from crates/eggshell-ui-shadcn/fonts/OFL.txt rename to src/fonts/OFL.txt diff --git a/src/lib.rs b/src/lib.rs index 054de931..270c9338 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -400,6 +400,7 @@ mod stack; mod symbols; mod sync; pub mod testing; +pub mod theme; #[cfg(all(feature = "screenshots", not(target_os = "linux")))] compile_error!( "the `screenshots` feature renders on Mesa lavapipe and is Linux-only for now; \ diff --git a/src/mount.rs b/src/mount.rs index 63c8ff9f..b8f43780 100644 --- a/src/mount.rs +++ b/src/mount.rs @@ -119,7 +119,7 @@ where .p_px(look.padding), }; let frame = match selected { - Selected::Yes => frame.ring(style.tokens.focus.width, look.selected_ring), + Selected::Yes => frame.ring(style.tokens.focus().width, look.selected_ring), Selected::No => frame, }; let label = caption.clone().or(name); diff --git a/src/owned/button.rs b/src/owned/button.rs index b6c3e4f2..f5588d84 100644 --- a/src/owned/button.rs +++ b/src/owned/button.rs @@ -60,7 +60,7 @@ pub(crate) fn button_defaults(sheet: &mut Sheet, defaults: ButtonDefaults) { move |t, k| { let classes = t.merge(look.paint.classes_in( look.border_width, - (k.focus, k.disabled), + (k.focus(), k.disabled), radius, Enablement::Enabled, transition, @@ -74,7 +74,7 @@ pub(crate) fn button_defaults(sheet: &mut Sheet, defaults: ButtonDefaults) { move |t, k| { let classes = t.merge(look.paint.classes_in( look.border_width, - (k.focus, k.disabled), + (k.focus(), k.disabled), radius, Enablement::Disabled, transition, diff --git a/src/owned/choices_sheet.rs b/src/owned/choices_sheet.rs index d29aaf2c..c2e07e4b 100644 --- a/src/owned/choices_sheet.rs +++ b/src/owned/choices_sheet.rs @@ -10,8 +10,9 @@ use core::time::Duration; -use crate::contract::{CheckboxStyle, Paint, RadioStyle, Size, States, SwitchStyle, Tokens}; +use crate::contract::{CheckboxStyle, Paint, RadioStyle, Size, States, SwitchStyle}; use crate::sheet::{Key, Part, Sheet, When}; +use crate::theme::Tokens; use crate::{Aria, Match, Tw, Weight}; use egui::Color32; @@ -269,7 +270,7 @@ impl Painted { }; paint.classes_in( self.border_width, - (k.focus, k.disabled), + (k.focus(), k.disabled), radius, enablement, self.transition, @@ -331,7 +332,8 @@ fn write_card_rules(sheet: &mut Sheet) { .border_color(k.primary.gamma_multiply(0.3)) }) .has(Match::focus_visible(), |b| { - b.border_color(k.ring).ring(k.focus.width, k.focus.color) + b.border_color(k.ring) + .ring(k.focus().width, k.focus().color) }) .children(field, |t| t.p(3.0)); for control in CONTROLS { @@ -359,15 +361,17 @@ fn write_card_rules(sheet: &mut Sheet) { t.flex().flex_1().flex_col().gap(1.0).whitespace_normal() }); sheet.rule(FieldPart::Title, |t, k| { + let size = k.control_text_size().size; t.flex() .w_fit() .items_center() .gap(2.0) - .text_size(k.text_size, k.text_size * 1.375) + .text_size(size, size * 1.375) .font_weight(Weight::Medium) }); sheet.rule(FieldPart::Description, |t, k| { - t.text_size(k.text_size, k.text_size * 1.5) + let size = k.control_text_size().size; + t.text_size(size, size * 1.5) .font_weight(Weight::Normal) .text(k.muted_foreground) }); diff --git a/src/owned/input_sheet.rs b/src/owned/input_sheet.rs index f22fbca8..6cc83a62 100644 --- a/src/owned/input_sheet.rs +++ b/src/owned/input_sheet.rs @@ -7,8 +7,9 @@ use egui::{Color32, Vec2}; -use crate::contract::{Colors, Disabled, InputStyle, Look, Size, Spacing, Tokens}; +use crate::contract::{Colors, Disabled, InputStyle, Look, Size, Spacing}; use crate::sheet::{Key, Part, Sheet, When}; +use crate::theme::Tokens; use crate::{Aria, Match, Tw}; /// TODO(prose): the anatomy of a text field: shadcn's `input`. @@ -94,7 +95,7 @@ pub(crate) fn input_defaults(sheet: &mut Sheet, defaults: InputDefaults) { height, } = defaults; let (states, shadow, width) = (look.paint.states, look.paint.shadow, look.border_width); - let ring = move |k: &Tokens| look.paint.focus.unwrap_or(k.focus); + let ring = move |k: &Tokens| look.paint.focus.unwrap_or(k.focus()); let radius = f32::from(radius); sheet.rule(InputPart::Root, move |t, k| { diff --git a/src/owned/mod.rs b/src/owned/mod.rs index 92fc56da..ae55aee2 100644 --- a/src/owned/mod.rs +++ b/src/owned/mod.rs @@ -596,7 +596,7 @@ impl Paint { ) -> Tw { self.classes_in( border_width, - (style.tokens.focus, style.tokens.disabled), + (style.tokens.focus(), style.tokens.disabled), radius, enablement, transition, diff --git a/src/owned/select.rs b/src/owned/select.rs index 288afcc6..263dd879 100644 --- a/src/owned/select.rs +++ b/src/owned/select.rs @@ -96,7 +96,7 @@ pub(crate) fn select_defaults(sheet: &mut Sheet, defaults: SelectDefaults) { sheet.replace_when(SelectPart::Trigger, when, move |t, k| { t.merge(trigger.paint.classes_in( trigger.border_width, - (k.focus, k.disabled), + (k.focus(), k.disabled), radius, enablement, transition, diff --git a/src/owned/splitter.rs b/src/owned/splitter.rs index fb8967ae..43b7aec6 100644 --- a/src/owned/splitter.rs +++ b/src/owned/splitter.rs @@ -365,7 +365,7 @@ impl<'a, 'f, A: 'static> SplitterChain<'a, 'f, A> { let travel = Travel::of(direction.unwrap_or(FlexDirection::Row), side); let (style, ring) = { let style = b.style().clone(); - (style.splitter, style.tokens.focus) + (style.splitter, style.tokens.focus()) }; let thickness = style.thickness.max(0.0); let classes = match travel.axis { diff --git a/src/owned/tabs_sheet.rs b/src/owned/tabs_sheet.rs index 184347a8..da467b15 100644 --- a/src/owned/tabs_sheet.rs +++ b/src/owned/tabs_sheet.rs @@ -145,8 +145,13 @@ pub(crate) fn tabs_defaults(sheet: &mut Sheet, defaults: TabsDefaults) { Enablement::Disabled => when.aria(Aria::Disabled), }; sheet.rule_when(TabsPart::Trigger, when, move |t, k| { - let look = - paint.classes_in(width, (k.focus, k.disabled), radius, enablement, transition); + let look = paint.classes_in( + width, + (k.focus(), k.disabled), + radius, + enablement, + transition, + ); t.merge(look) }); } diff --git a/src/sheet.rs b/src/sheet.rs index 33a05a11..ee8210c1 100644 --- a/src/sheet.rs +++ b/src/sheet.rs @@ -7,7 +7,8 @@ use std::fmt::Debug; use std::sync::Arc; use std::sync::atomic::{AtomicU64, Ordering}; -use crate::contract::{Size, Tokens, Variant}; +use crate::contract::{Size, Variant}; +use crate::theme::Tokens; use crate::{Aria, Tw}; /// TODO(prose): the anatomy of a widget: the nodes a [`Sheet`] styles. @@ -206,7 +207,8 @@ fn next_version() -> u64 { /// TODO(prose): the rules of a style: for each part of each widget, the classes it gets when its keys hold. /// /// ``` -/// use eggshell_ui::contract::{Tokens, Variant}; +/// use eggshell_ui::contract::Variant; +/// use eggshell_ui::theme::Tokens; /// use eggshell_ui::sheet::{Key, Part, Sheet, When}; /// use eggshell_ui::tw; /// @@ -221,7 +223,7 @@ fn next_version() -> u64 { /// } /// } /// -/// let tokens = Tokens::from_egui(&egui::Style::default()); +/// let tokens = Tokens::light(); /// let mut sheet = Sheet::defaults(); /// sheet /// .rule(Chip, |t, _| t.px(2.0).rounded_md()) @@ -319,7 +321,7 @@ impl Sheet { /// TODO(prose): [`rule`](Self::rule), but the part's classes start empty under it: every rule below that holds with it is dropped. /// /// ``` - /// use eggshell_ui::contract::Tokens; + /// use eggshell_ui::theme::Tokens; /// use eggshell_ui::sheet::{Part, Sheet, When}; /// use eggshell_ui::tw; /// @@ -334,7 +336,7 @@ impl Sheet { /// } /// } /// - /// let tokens = Tokens::from_egui(&egui::Style::default()); + /// let tokens = Tokens::light(); /// let mut sheet = Sheet::defaults(); /// sheet.rule(Chip, |t, _| t.px(2.0).gap(1.0)); /// sheet.as_app().replace(Chip, |t, _| t.px(4.0)); @@ -505,11 +507,11 @@ impl Memo { } let at = part_key(part); let kept = self.sheets.entry(sheet.version).or_insert_with(|| Kept { - tokens: *tokens, + tokens: tokens.clone(), parts: HashMap::new(), }); if kept.tokens != *tokens { - kept.tokens = *tokens; + kept.tokens = tokens.clone(); kept.parts.clear(); } let known = kept.parts.entry(at).or_default(); @@ -549,7 +551,7 @@ mod tests { } fn tokens() -> Tokens { - Tokens::from_egui(&egui::Style::default()) + Tokens::light() } const WIDE: Variant = Variant("wide"); diff --git a/crates/eggshell-ui-shadcn/src/contrast.rs b/src/theme/contrast.rs similarity index 95% rename from crates/eggshell-ui-shadcn/src/contrast.rs rename to src/theme/contrast.rs index 1455606a..0a440a54 100644 --- a/crates/eggshell-ui-shadcn/src/contrast.rs +++ b/src/theme/contrast.rs @@ -2,9 +2,9 @@ use std::fmt; use egui::{Color32, Context, Theme}; -use eggshell_ui::Tone; +use crate::Tone; -use crate::{BaseColor, Palette, ThemeColor, Tokens}; +use super::{BaseColor, Palette, ThemeColor, Tokens}; /// TODO(prose): a pair of tokens the components draw text on: the text /// colour, then the surface under it. @@ -242,7 +242,7 @@ impl RegistryMiss { /// Reports, in a debug build, each pair of `tokens` under AA that is neither /// accepted nor a registry miss, once per pair and theme. The colours are not /// changed. -pub(crate) fn warn_low_contrast(ctx: &Context, theme: Theme, tokens: &Tokens) { +pub fn warn_low_contrast(ctx: &Context, theme: Theme, tokens: &Tokens) { if !cfg!(debug_assertions) { return; } @@ -255,17 +255,12 @@ pub(crate) fn warn_low_contrast(ctx: &Context, theme: Theme, tokens: &Tokens) { continue; } let subject = egui::Id::NULL.with(("eggshell-ui-shadcn-contrast", theme, pair)); - eggshell_ui::report( - ctx, - eggshell_ui::Problem::LowContrast, - Some(subject), - || { - format!( - "{} is {ratio} in {theme:?} (AA text needs {})", - pair.name(), - ContrastRatio::AA_TEXT - ) - }, - ); + crate::report(ctx, crate::Problem::LowContrast, Some(subject), || { + format!( + "{} is {ratio} in {theme:?} (AA text needs {})", + pair.name(), + ContrastRatio::AA_TEXT + ) + }); } } diff --git a/crates/eggshell-ui-shadcn/src/fonts.rs b/src/theme/fonts.rs similarity index 94% rename from crates/eggshell-ui-shadcn/src/fonts.rs rename to src/theme/fonts.rs index 19dc3e94..59722072 100644 --- a/crates/eggshell-ui-shadcn/src/fonts.rs +++ b/src/theme/fonts.rs @@ -1,11 +1,11 @@ //! The font a preset draws its text in: shadcn's `--font-sans`. -use eggshell_ui::{Faces, Weight}; +use crate::{Faces, Weight}; use egui::epaint::text::{FontInsert, FontPriority, FontTweak, InsertFontFamily, VariationCoords}; use egui::{Context, FontData, FontFamily}; /// A font with a face for each of the weights it has, which -/// [`Shadcn::apply`](crate::Shadcn::apply) registers with egui: the +/// `Shadcn::apply` registers with egui: the /// [`Normal`](Weight::Normal) face as the first font of /// [`FontFamily::Proportional`], every other as a named family that the /// preset's [`Faces`] give its weight. @@ -82,7 +82,7 @@ impl FontSet { } /// The named family of each weight but Normal, for the style contract. - pub(crate) fn declared(&self) -> Faces { + pub fn declared(&self) -> Faces { self.weighted().fold(Faces::default(), |faces, weight| { faces.with(FontFamily::Proportional, weight, self.family(weight)) }) @@ -91,7 +91,7 @@ impl FontSet { /// Adds the faces to `ctx`'s fonts. The Normal face also backs every /// named family, for the glyphs a weighted face lacks. Adding a face egui /// has under its name already does nothing. - pub(crate) fn install(&self, ctx: &Context) { + pub fn install(&self, ctx: &Context) { for font in self.inserts() { ctx.add_font(font); } @@ -99,7 +99,7 @@ impl FontSet { /// The faces as egui font insertions: each weight's face first in its /// own family, and the Normal face last in every weighted family. - pub(crate) fn inserts(&self) -> Vec { + pub fn inserts(&self) -> Vec { let first = |family| InsertFontFamily { family, priority: FontPriority::Highest, diff --git a/src/theme/mod.rs b/src/theme/mod.rs new file mode 100644 index 00000000..696e3719 --- /dev/null +++ b/src/theme/mod.rs @@ -0,0 +1,17 @@ +//! TODO(prose): shadcn's tokens, the values every look is drawn from: the +//! palette, light and dark, the shadcn style's sizes, the density tokens, +//! the font and the contrast check. + +mod contrast; +mod fonts; +mod palette; +mod styles; +mod theme_color; +mod tokens; + +pub use contrast::{ContrastPair, ContrastRatio, REGISTRY_MISSES, RegistryMiss, warn_low_contrast}; +pub use fonts::FontSet; +pub use palette::{BaseColor, Palette}; +pub use styles::{Elevation, HoverSurface, ShadcnStyle}; +pub use theme_color::ThemeColor; +pub use tokens::Tokens; diff --git a/crates/eggshell-ui-shadcn/src/palette.rs b/src/theme/palette.rs similarity index 99% rename from crates/eggshell-ui-shadcn/src/palette.rs rename to src/theme/palette.rs index 87c4f732..326bba85 100644 --- a/crates/eggshell-ui-shadcn/src/palette.rs +++ b/src/theme/palette.rs @@ -1,7 +1,7 @@ use egui::{Color32, Theme}; -use crate::ThemeColor; -use crate::tokens::rgb; +use super::ThemeColor; +use super::tokens::rgb; /// TODO(prose): one of shadcn's base colours (`baseColor`), which sets the /// greys: the page, its text, cards, popovers, borders, inputs, the muted, @@ -433,7 +433,7 @@ impl BaseColor { /// [`ThemeColor::Base`] and the other variants are. /// /// ``` -/// use eggshell_ui_shadcn::{BaseColor, Palette, ThemeColor}; +/// use eggshell_ui::theme::{BaseColor, Palette, ThemeColor}; /// /// let palette = Palette::new().base(BaseColor::Zinc).theme(ThemeColor::Blue); /// # let _ = palette; diff --git a/crates/eggshell-ui-shadcn/src/styles.rs b/src/theme/styles.rs similarity index 94% rename from crates/eggshell-ui-shadcn/src/styles.rs rename to src/theme/styles.rs index e0073ac7..719cc529 100644 --- a/crates/eggshell-ui-shadcn/src/styles.rs +++ b/src/theme/styles.rs @@ -1,14 +1,14 @@ //! shadcn's styles: parameter sets that differ in a handful of values. -use eggshell_ui::Weight; -use eggshell_ui::contract::{Radius, TextStep}; +use crate::Weight; +use crate::contract::{Radius, TextStep}; use egui::vec2; -use crate::Tokens; +use super::Tokens; /// One of shadcn's styles, from `apps/v4/registry/styles/style-*.css`. A /// style is a parameter set (radii, control height, text size, ring width and -/// a few choices of surface); it is independent of the [`Palette`](crate::Palette) +/// a few choices of surface); it is independent of the [`Palette`](super::Palette) /// and of light or dark. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub enum ShadcnStyle { @@ -102,7 +102,8 @@ pub enum Elevation { } impl Elevation { - pub(crate) fn shadow(self, shadow: egui::Shadow) -> Option { + /// TODO(prose): `shadow` on a raised control, or none on a flat one. + pub fn shadow(self, shadow: egui::Shadow) -> Option { match self { Self::Raised => Some(shadow), Self::Flat => None, diff --git a/crates/eggshell-ui-shadcn/src/theme_color.rs b/src/theme/theme_color.rs similarity index 99% rename from crates/eggshell-ui-shadcn/src/theme_color.rs rename to src/theme/theme_color.rs index dd7c6854..e96235df 100644 --- a/crates/eggshell-ui-shadcn/src/theme_color.rs +++ b/src/theme/theme_color.rs @@ -1,7 +1,7 @@ use egui::{Color32, Theme}; -use crate::palette::Scheme; -use crate::tokens::rgb; +use super::palette::Scheme; +use super::tokens::rgb; /// One of shadcn's theme colours, which re-tints `primary` and /// `primary-foreground`, and the charts. [`Base`](Self::Base), the base colour's own theme, is diff --git a/crates/eggshell-ui-shadcn/src/tokens.rs b/src/theme/tokens.rs similarity index 94% rename from crates/eggshell-ui-shadcn/src/tokens.rs rename to src/theme/tokens.rs index 8c1d27cb..14c6f8aa 100644 --- a/crates/eggshell-ui-shadcn/src/tokens.rs +++ b/src/theme/tokens.rs @@ -1,10 +1,10 @@ -use eggshell_ui::contract::{Radius, Spacing, TextScale, TextSize, TextStep, corner}; -use eggshell_ui::{TextSpec, Weight}; +use crate::contract::{Disabled, Focus, Radius, Spacing, TextScale, TextSize, TextStep, corner}; +use crate::{TextSpec, Weight}; use egui::{Color32, Shadow, Theme, Vec2, vec2}; -use crate::palette::{Palette, Scheme}; -use crate::styles::{Elevation, HoverSurface, ShadcnStyle}; -use crate::{ContrastPair, FontSet}; +use super::palette::{Palette, Scheme}; +use super::styles::{Elevation, HoverSurface, ShadcnStyle}; +use super::{ContrastPair, FontSet}; /// A colour from `0xRRGGBB`. pub(crate) const fn rgb(hex: u32) -> Color32 { @@ -151,18 +151,20 @@ pub struct Tokens { pub shadow_md: Shadow, /// `shadow-lg`, without its negative spread. pub shadow_lg: Shadow, - /// `--font-sans`: the font [`Shadcn::apply`](crate::Shadcn::apply) + /// `--font-sans`: the font `Shadcn::apply` /// registers, or `None` to leave egui's fonts alone. pub font: Option, /// The weight of buttons, toggles, tabs and key chips (`font-medium`). pub control_weight: Weight, /// TODO(prose): the pairs under AA contrast the application accepts: - /// [`Shadcn::apply`](crate::Shadcn::apply) warns about the others in a + /// `Shadcn::apply` warns about the others in a /// debug build. pub accepted_contrast: Vec, /// The weight of a label (`.cn-label`): beside a checkbox, radio button /// or switch, and over a group of menu items. pub label_weight: Weight, + /// TODO(prose): how disabled controls are drawn. Not a shadcn variable. + pub disabled: Disabled, } impl Tokens { @@ -299,6 +301,7 @@ impl Tokens { control_weight: Weight::Normal, label_weight: Weight::Normal, accepted_contrast: Vec::new(), + disabled: Disabled::Colors, }; ShadcnStyle::Vega.shape(&mut tokens); tokens @@ -326,6 +329,15 @@ impl Tokens { Vec2::new(self.points(units.x), self.points(units.y)) } + /// TODO(prose): the keyboard focus ring every control draws unless its + /// look names its own: `ring-[3px] ring-ring/50` at the style's ring width. + pub fn focus(&self) -> Focus { + Focus { + width: self.ring_width, + color: self.ring.gamma_multiply(0.5), + } + } + /// `rounded-md`: the radius of buttons, inputs and selects. pub fn radius_md(&self) -> u8 { corner(self.radius.md()) @@ -389,9 +401,9 @@ impl Tokens { } /// TODO(prose): the colours of each tone: the status tokens. - pub fn tones(&self) -> eggshell_ui::contract::Tones { - let on = |tone, foreground| eggshell_ui::contract::ToneColors { tone, foreground }; - eggshell_ui::contract::Tones { + pub fn tones(&self) -> crate::contract::Tones { + let on = |tone, foreground| crate::contract::ToneColors { tone, foreground }; + crate::contract::Tones { info: on(self.info, self.info_foreground), success: on(self.success, self.success_foreground), warning: on(self.warning, self.warning_foreground), diff --git a/tests/it/choice_cards.rs b/tests/it/choice_cards.rs index 319fc7b8..2441ac08 100644 --- a/tests/it/choice_cards.rs +++ b/tests/it/choice_cards.rs @@ -166,7 +166,7 @@ fn a_focused_control_rings_its_card_not_itself() { let card = d.rect(Target::suffix(BACKUPS)); let control = d.rect(Target::suffix("/\"backups\"/Label/Box")); let ring = ring_at(&d, card).expect("the card rings"); - let focus = Shadcn::for_theme(Theme::Light).style().tokens.focus; + let focus = Shadcn::for_theme(Theme::Light).style().tokens.focus(); assert_eq!(ring.stroke.width, focus.width); assert!(ring_at(&d, control).is_none(), "the control does not"); } diff --git a/tests/it/command_palette.rs b/tests/it/command_palette.rs index 5ad79fb6..1d808929 100644 --- a/tests/it/command_palette.rs +++ b/tests/it/command_palette.rs @@ -228,7 +228,7 @@ fn the_combobox_is_a_field_that_opens_on_a_click_filters_as_typed_and_picks() { /// The rects painted with a stroke in the focus ring's color. fn ring_rects(harness: &Harness<'_, Rig>) -> Vec { - let ring = harness.view_shell().style().tokens.focus.color; + let ring = harness.view_shell().style().tokens.focus().color; harness .output() .shapes diff --git a/tests/it/density.rs b/tests/it/density.rs index c93512f4..18f2bf2b 100644 --- a/tests/it/density.rs +++ b/tests/it/density.rs @@ -168,7 +168,7 @@ fn the_presets_unit_tokens_scale_the_metrics_they_feed() { "h-1.5, size-4" ); assert_eq!( - style.tokens.button_padding, + style.tokens.points_vec(style.tokens.button_padding), vec2(u(4.0), u(2.0)), "px-4 py-2, as egui's button padding" ); diff --git a/tests/it/egui_look.rs b/tests/it/egui_look.rs index b350ed0b..fa7600a9 100644 --- a/tests/it/egui_look.rs +++ b/tests/it/egui_look.rs @@ -124,31 +124,10 @@ fn set_style_gives_egui_the_new_look_on_the_next_build() { } #[test] -fn the_core_tokens_are_the_preset_s() { +fn the_style_s_tokens_are_the_preset_s() { for theme in [Theme::Light, Theme::Dark] { let preset = Shadcn::for_theme(theme); - let tokens = preset.style().tokens; - let t = preset.tokens; - assert_eq!( - ( - tokens.background, - tokens.foreground, - tokens.popover, - tokens.primary - ), - (t.background, t.foreground, t.popover, t.primary), - "{theme:?}" - ); - assert_eq!( - ( - tokens.muted_foreground, - tokens.border, - tokens.input, - tokens.ring - ), - (t.muted_foreground, t.border, t.input, t.ring), - "{theme:?}" - ); + assert_eq!(preset.style().tokens, preset.tokens, "{theme:?}"); } let _: Themed> = Shadcn::themed(ShadcnStyle::Vega, Palette::new()); @@ -181,9 +160,9 @@ fn each_token_lands_where_egui_reads_it() { *colour = next(); } t.radius = eggshell_ui::contract::Radius::new(9.0); - t.control_height = 41.0; - t.text_size = 17.0; - let t = style.tokens; + t.control_units = 10.25; + t.text.sm.size = 17.0; + let t = style.tokens.clone(); let mut egui = egui::Style::default(); style.egui_style(Theme::Light, &mut egui); let v = &egui.visuals; diff --git a/tests/it/field_box.rs b/tests/it/field_box.rs index b53f6bc9..e3fdb9cb 100644 --- a/tests/it/field_box.rs +++ b/tests/it/field_box.rs @@ -2,7 +2,7 @@ use std::sync::Arc; -use eggshell_ui::contract::{Focus, Size, Themed}; +use eggshell_ui::contract::{Size, Themed}; use eggshell_ui::testing::{Driver, Target}; use eggshell_ui::{Builder, Icon, TextSpec, TextStyle, Weight, icons, tw}; use eggshell_ui_shadcn::{Shadcn, size}; @@ -169,13 +169,11 @@ fn a_focused_addon_button_rings_itself_not_its_group() { #[test] fn a_field_box_without_a_ring_of_its_own_rings_in_the_tokens_focus() { - let ring = Focus { - width: 5.0, - color: Color32::from_rgb(200, 30, 30), - }; // The widgets' own look, whose input has no ring of its own. let mut style = eggshell_ui::Style::from_egui(&egui::Context::default().style_of(Theme::Light)); - style.tokens.focus = ring; + style.tokens.ring_width = 5.0; + style.tokens.ring = Color32::from_rgb(200, 30, 30); + let ring = style.tokens.focus(); let mut d = support::driver( vec2(340.0, 360.0), TextStyle::new(style.text.clone(), style.tokens.foreground), diff --git a/tests/it/font_weights.rs b/tests/it/font_weights.rs index 316d08d5..3eb8ef57 100644 --- a/tests/it/font_weights.rs +++ b/tests/it/font_weights.rs @@ -97,9 +97,7 @@ fn without_a_font_every_weight_draws_the_regular_family() { #[test] fn a_set_without_semibold_draws_semibold_in_its_medium_face() { - let font = egui::FontData::from_static(include_bytes!( - "../../crates/eggshell-ui-shadcn/fonts/Geist-Variable.ttf" - )); + let font = egui::FontData::from_static(include_bytes!("../../src/fonts/Geist-Variable.ttf")); let partial = FontSet::faces( "partial", [Weight::Normal, Weight::Medium, Weight::Bold].map(|weight| (weight, font.clone())), diff --git a/tests/it/mount.rs b/tests/it/mount.rs index 564f838b..737ef527 100644 --- a/tests/it/mount.rs +++ b/tests/it/mount.rs @@ -1081,8 +1081,8 @@ mod selection { field.min, content.min, "precondition: the field sits at the content's edge" ); - let focus_ring = field.expand(style.tokens.focus.width); - let selected_ring = frame.expand(style.tokens.focus.width); + let focus_ring = field.expand(style.tokens.focus().width); + let selected_ring = frame.expand(style.tokens.focus().width); assert!( frame.contains_rect(focus_ring), "the focus ring {focus_ring:?} stays clear of the selected ring's band, \ @@ -1104,7 +1104,7 @@ mod selection { caption.max.y <= frame.min.y && caption.x_range().intersects(frame.x_range()), "precondition: the caption {caption:?} sits above the frame {frame:?}" ); - let selected_ring = frame.expand(style.tokens.focus.width); + let selected_ring = frame.expand(style.tokens.focus().width); assert!( !selected_ring.intersects(caption), "the selected ring {selected_ring:?} stays clear of the caption {caption:?}" diff --git a/tests/it/owned.rs b/tests/it/owned.rs index 7cc4c9b0..0259590c 100644 --- a/tests/it/owned.rs +++ b/tests/it/owned.rs @@ -706,10 +706,9 @@ fn an_app_rule_can_take_the_press_shift_away() { #[test] fn without_the_preset_a_button_reads_focus_and_disabled_from_the_tokens() { let mut style = Style::default(); - style.tokens.focus = eggshell_ui::contract::Focus { - width: 5.0, - color: Color32::RED, - }; + style.tokens.ring_width = 5.0; + style.tokens.ring = Color32::RED; + let focus = style.tokens.focus(); style.tokens.disabled = eggshell_ui::contract::Disabled::Faded(eggshell_ui::Opacity::new(0.4)); let mut d = harness(Theme::Light); d.set_style(Themed::both(Arc::new(style))); @@ -733,7 +732,10 @@ fn without_the_preset_a_button_reads_focus_and_disabled_from_the_tokens() { let node = path(variant::PRIMARY, Enablement::Enabled); assert_eq!(focused_path(&d).as_deref(), Some(node.as_str())); let ring = ring_at(&d, enabled).expect("a focus ring"); - assert_eq!((ring.stroke.width, ring.stroke.color), (5.0, Color32::RED)); + assert_eq!( + (ring.stroke.width, ring.stroke.color), + (focus.width, focus.color) + ); } mod toggle_chain { diff --git a/tests/it/owned_choice.rs b/tests/it/owned_choice.rs index 0fb0cfed..9170ef91 100644 --- a/tests/it/owned_choice.rs +++ b/tests/it/owned_choice.rs @@ -5,7 +5,7 @@ use core::time::Duration; use std::sync::Arc; -use eggshell_ui::contract::{Focus, Size, Themed}; +use eggshell_ui::contract::{Size, Themed}; use eggshell_ui::owned::{Cell, Enablement, Mark, SegmentedRows, SwitchPart, TabsPart}; use eggshell_ui::{Builder, Style, TextStyle, tw}; use eggshell_ui_shadcn::{Shadcn, Tokens}; @@ -401,8 +401,8 @@ fn a_focused_switch_shows_the_styles_ring() { d.frames(12); let rect = d.rect(Target::suffix("/\"air\"/Track")); let ring = ring_at(&d, rect).expect("a focus ring"); - assert_eq!(ring.stroke.width, style.tokens.focus.width); - assert_eq!(ring.stroke.color, style.tokens.focus.color); + assert_eq!(ring.stroke.width, style.tokens.focus().width); + assert_eq!(ring.stroke.color, style.tokens.focus().color); } } @@ -618,19 +618,18 @@ fn the_switch_thumb_keeps_its_rest_colour_when_hovered_or_pressed() { #[test] fn the_tokens_ring_is_the_mechanisms_on_a_switch_and_a_cell() { - let ring = Focus { - width: 5.0, - color: egui::Color32::from_rgb(200, 30, 30), - }; // The preset's switch and cells take shadcn's // `focus-visible:ring-[3px]`; the tokens' ring is the mechanism's, which // the style without a preset draws them with. let mut style = Style::from_egui(&egui::Context::default().style_of(Theme::Light)); + style.tokens.ring_width = 5.0; + style.tokens.ring = egui::Color32::from_rgb(200, 30, 30); + let ring = style.tokens.focus(); assert_ne!( - style.tokens.focus, ring, + Shadcn::for_theme(Theme::Light).tokens.focus(), + ring, "precondition: the preset's ring is another" ); - style.tokens.focus = ring; for path in ["/\"air\"/Track".to_owned(), cell_path(Unit::Metric)] { let mut d = harness(Theme::Light); d.set_style(Themed::both(Arc::new(style.clone()))); diff --git a/tests/it/scroll_keys.rs b/tests/it/scroll_keys.rs index 0557606c..4e0bd25e 100644 --- a/tests/it/scroll_keys.rs +++ b/tests/it/scroll_keys.rs @@ -378,7 +378,7 @@ fn the_innermost_container_holding_the_focus_scrolls_and_the_keys_do_not_chain() } fn focus_rings(h: &H) -> Vec { - let ring = h.shell().style().tokens.focus.color; + let ring = h.shell().style().tokens.focus().color; support::shapes(h) .into_iter() .filter_map(|shape| match shape { @@ -630,7 +630,7 @@ fn a_click_in_a_container_shows_no_ring_only_the_keyboard_does() { const FRAME: &str = "/\"list\""; fn focus_style(h: &H) -> eggshell_ui::contract::Focus { - h.shell().style().tokens.focus + h.shell().style().tokens.focus() } /// Every shape of the last frame in paint order, with the clip it is painted in. diff --git a/tests/it/sheet.rs b/tests/it/sheet.rs index 36399acd..6d7226fb 100644 --- a/tests/it/sheet.rs +++ b/tests/it/sheet.rs @@ -268,13 +268,13 @@ fn by_token(b: &mut Builder<'_, '_, ()>, _: &()) { |style| { style .sheet - .rule(Chip::Root, |t, k| t.w_px(k.control_height).h_px(10.0)); + .rule(Chip::Root, |t, k| t.w_px(k.control_height()).h_px(10.0)); }, |b| { let before = b.part(Chip::Root, &[], tw()); b.div_id("before", before, |_| {}); b.styled( - |style| style.tokens.control_height = 77.0, + |style| style.tokens.control_units = 77.0 / style.tokens.spacing.points(1.0), |b| { let scoped = b.part(Chip::Root, &[], tw()); b.div_id("scoped", scoped, |_| {}); @@ -303,7 +303,7 @@ fn a_rule_body_is_given_the_tokens_of_the_style_it_is_resolved_in() { fn the_preset_fills_the_shadow_scale() { use eggshell_ui_shadcn::{Palette, Shadcn, ShadcnStyle}; let themed = Shadcn::themed(ShadcnStyle::Vega, Palette::new()); - let tokens = themed.light.tokens; + let tokens = &themed.light.tokens; assert_ne!(tokens.shadow_xs, egui::Shadow::NONE); assert!(tokens.shadow_lg.offset[1] > tokens.shadow_md.offset[1]); } diff --git a/tests/it/splitter.rs b/tests/it/splitter.rs index b925537b..8b5ddb86 100644 --- a/tests/it/splitter.rs +++ b/tests/it/splitter.rs @@ -316,7 +316,7 @@ mod keys { tab_to(&mut d, LEFT); d.frames(12); let ring = ring_at(&d).expect("a ring inside the hit area"); - let focus = Shadcn::for_theme(Theme::Light).style().tokens.focus; + let focus = Shadcn::for_theme(Theme::Light).style().tokens.focus(); assert_eq!( (ring.stroke.width, ring.stroke.color), (focus.width, focus.color) diff --git a/tests/it/style_switch.rs b/tests/it/style_switch.rs index b68aed7f..45135298 100644 --- a/tests/it/style_switch.rs +++ b/tests/it/style_switch.rs @@ -139,8 +139,8 @@ fn switching_the_style_at_run_time_resizes_the_controls_per_the_style() { assert_eq!(radius(&vega_style), vega_tokens.radius_md()); assert_eq!(radius(&lyra_style), 0, "Lyra is square"); assert!(radius(&vega_style) > 0, "precondition: Vega is rounded"); - assert_eq!(vega_style.tokens.focus.width, 3.0); - assert_eq!(lyra_style.tokens.focus.width, 1.0); + assert_eq!(vega_style.tokens.focus().width, 3.0); + assert_eq!(lyra_style.tokens.focus().width, 1.0); let field = |style| crate::support::field_box(style, eggshell_ui::contract::Size::DEFAULT); assert_eq!(field(&vega_style).height, 36.0); assert_eq!(field(&lyra_style).height, 32.0); diff --git a/xtask/src/shadcn_import/mod.rs b/xtask/src/shadcn_import/mod.rs index 0f6de3fc..ad9fa437 100644 --- a/xtask/src/shadcn_import/mod.rs +++ b/xtask/src/shadcn_import/mod.rs @@ -1107,7 +1107,7 @@ pub fn run(plan: &Plan) -> Result<()> { let root = crate::process::workspace_root(); let registry = root.join(&plan.reference).join("apps/v4/registry"); let tw = tw_table(&root)?; - let tokens = classes::token_names(&read(&root.join("src/contract.rs"))?); + let tokens = classes::token_names(&read(&root.join("src/theme/tokens.rs"))?); let radius = theme_radius(&read(®istry.join("themes.ts"))?) .context("no `radius` in registry/themes.ts")?; let classifier = Classifier {