Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
2 changes: 1 addition & 1 deletion crates/eggshell-ui-extras/src/badge/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/eggshell-ui-extras/src/command/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion crates/eggshell-ui-extras/src/disclosure/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion crates/eggshell-ui-extras/src/markdown/style.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
2 changes: 1 addition & 1 deletion crates/eggshell-ui-shadcn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions crates/eggshell-ui-shadcn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions crates/eggshell-ui-shadcn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
50 changes: 4 additions & 46 deletions crates/eggshell-ui-shadcn/src/preset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand All @@ -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);
}
Expand Down Expand Up @@ -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 };
Expand Down
8 changes: 4 additions & 4 deletions crates/eggshell-ui-shadcn/tests/styles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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:?}"
);
}
Expand Down
123 changes: 3 additions & 120 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<egui::FontInsert>);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ impl<A> 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,
Expand Down
Loading
Loading