diff --git a/crates/horizon-client/src/ui_theme.rs b/crates/horizon-client/src/ui_theme.rs index 39c6555d3..3b53c34fd 100644 --- a/crates/horizon-client/src/ui_theme.rs +++ b/crates/horizon-client/src/ui_theme.rs @@ -72,22 +72,22 @@ pub fn save_preferences(dir: &Path) { let _ = std::fs::write(dir.join("horizon.txt"), format!("menuStyle:{value}\n")); } -/// The launcher's dark palette (`horizon_theme::DARK`) in the HUD's colour -/// encoding, plus the translucent surfaces the menus put over the backdrop. +/// The dark palette (`horizon_theme::DARK`) in the HUD's colour encoding, plus the +/// translucent surfaces the menus put over the backdrop. pub mod color { use crate::hud::rgba; use horizon_theme::DARK as P; pub const fn hex(c: u32, a: u8) -> u32 { (a as u32) << 24 | (c & 0xff) << 16 | (c >> 8 & 0xff) << 8 | (c >> 16 & 0xff) } - pub const BG: u32 = hex(P.bg, 255); - pub const SIDEBAR: u32 = hex(P.sidebar, 255); - pub const RAISED: u32 = hex(P.raised, 255); - pub const HOVER: u32 = hex(P.hover, 255); - pub const BORDER: u32 = hex(P.border, 255); - pub const TEXT: u32 = hex(P.text, 255); - pub const MUTED: u32 = hex(P.muted, 255); - pub const FAINT: u32 = hex(P.faint, 255); + pub const BG: u32 = hex(P.page, 255); + pub const SIDEBAR: u32 = hex(P.plate_soft, 255); + pub const RAISED: u32 = hex(P.plate_soft, 255); + pub const HOVER: u32 = hex(P.plate, 255); + pub const BORDER: u32 = hex(P.rule, 255); + pub const TEXT: u32 = hex(P.ink, 255); + pub const MUTED: u32 = hex(P.ink_soft, 255); + pub const FAINT: u32 = hex(P.muted, 255); pub const ACCENT: u32 = hex(P.accent, 255); pub const ON_ACCENT: u32 = hex(P.on_accent, 255); pub const DANGER: u32 = hex(P.danger, 255); @@ -106,16 +106,25 @@ pub mod color { } /// The launcher's type scale and shapes (`horizon_theme`), in dp. -pub use horizon_theme::{ - BODY, CONTROL, CONTROL_LARGE, HERO, LARGE, RADIUS, RADIUS_CARD, RADIUS_GROUP, RADIUS_SEGMENT, - ROW_LABEL, SEGMENT, SIDEBAR, SMALL, TITLE, WORDMARK, ease_out_cubic, ease_out_quint, -}; +pub use horizon_theme::{CONTROL, CONTROL_LARGE, SEGMENT, ease_out_cubic, ease_out_quint}; +pub const SMALL: f32 = horizon_theme::CAPTION.px; +pub const BODY: f32 = horizon_theme::LABEL.px; +pub const LARGE: f32 = horizon_theme::BODY.px; +pub const TITLE: f32 = horizon_theme::TITLE.px; +pub const HERO: f32 = horizon_theme::DISPLAY.px; +pub const WORDMARK: f32 = 96.; +pub const RADIUS: f32 = horizon_theme::RADIUS; +pub const RADIUS_SEGMENT: f32 = horizon_theme::RADIUS; +pub const RADIUS_GROUP: f32 = horizon_theme::RADIUS; +pub const RADIUS_CARD: f32 = horizon_theme::RADIUS_PLATE; +pub const ROW_LABEL: f32 = 150.; +pub const SIDEBAR: f32 = 200.; /// Motion durations in seconds (`horizon_theme::QUICK` and `MOVE`). pub fn quick() -> f32 { - horizon_theme::QUICK.as_secs_f32() + horizon_theme::QUICK.secs() } pub fn move_() -> f32 { - horizon_theme::MOVE.as_secs_f32() + horizon_theme::MOVE.secs() } /// How visible the live title backdrop is (0..1), set by the game each frame. static BACKDROP: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0); @@ -153,7 +162,7 @@ impl Fonts { let f = |b: &'static [u8]| FontRef::try_from_slice(b).expect("bundled font"); Self { faces: [ - f(horizon_theme::fonts::INSTRUMENT_SERIF), + f(horizon_theme::fonts::GEIST_MEDIUM), f(horizon_theme::fonts::GEIST_REGULAR), f(horizon_theme::fonts::GEIST_MEDIUM), f(horizon_theme::fonts::GEIST_SEMIBOLD), @@ -862,11 +871,7 @@ impl<'a> Ui<'a> { if !enabled { self.opacity *= horizon_theme::DISABLED; } else if self.pressed(x, y, w, h) { - self.opacity *= if kind == Kind::Primary { - horizon_theme::PRESSED - } else { - horizon_theme::PRESSED_SOFT - }; + self.opacity *= horizon_theme::PRESSED; } let fg = match kind { Kind::Primary => { @@ -877,7 +882,7 @@ impl<'a> Ui<'a> { w, h, RADIUS, - color::with_alpha(color::WHITE, horizon_theme::PRIMARY_HOVER * hover), + color::with_alpha(color::WHITE, 0.10 * hover), ); color::ON_ACCENT } diff --git a/crates/horizon-theme/fonts/InstrumentSerif-Regular.ttf b/crates/horizon-theme/fonts/InstrumentSerif-Regular.ttf deleted file mode 100644 index 36fac00ef..000000000 Binary files a/crates/horizon-theme/fonts/InstrumentSerif-Regular.ttf and /dev/null differ diff --git a/crates/horizon-theme/fonts/OFL-InstrumentSerif.txt b/crates/horizon-theme/fonts/OFL-InstrumentSerif.txt deleted file mode 100644 index 669ce7917..000000000 --- a/crates/horizon-theme/fonts/OFL-InstrumentSerif.txt +++ /dev/null @@ -1,93 +0,0 @@ -Copyright 2022 The Instrument Serif Project Authors (https://github.com/Instrument/instrument-serif) - -This Font Software is licensed under the SIL Open Font License, Version 1.1. -This license is copied below, and is also available with a FAQ at: -https://scripts.sil.org/OFL - - ------------------------------------------------------------ -SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 ------------------------------------------------------------ - -PREAMBLE -The goals of the Open Font License (OFL) are to stimulate worldwide -development of collaborative font projects, to support the font creation -efforts of academic and linguistic communities, and to provide a free and -open framework in which fonts may be shared and improved in partnership -with others. - -The OFL allows the licensed fonts to be used, studied, modified and -redistributed freely as long as they are not sold by themselves. The -fonts, including any derivative works, can be bundled, embedded, -redistributed and/or sold with any software provided that any reserved -names are not used by derivative works. The fonts and derivatives, -however, cannot be released under any other type of license. The -requirement for fonts to remain under this license does not apply -to any document created using the fonts or their derivatives. - -DEFINITIONS -"Font Software" refers to the set of files released by the Copyright -Holder(s) under this license and clearly marked as such. This may -include source files, build scripts and documentation. - -"Reserved Font Name" refers to any names specified as such after the -copyright statement(s). - -"Original Version" refers to the collection of Font Software components as -distributed by the Copyright Holder(s). - -"Modified Version" refers to any derivative made by adding to, deleting, -or substituting -- in part or in whole -- any of the components of the -Original Version, by changing formats or by porting the Font Software to a -new environment. - -"Author" refers to any designer, engineer, programmer, technical -writer or other person who contributed to the Font Software. - -PERMISSION & CONDITIONS -Permission is hereby granted, free of charge, to any person obtaining -a copy of the Font Software, to use, study, copy, merge, embed, modify, -redistribute, and sell modified and unmodified copies of the Font -Software, subject to the following conditions: - -1) Neither the Font Software nor any of its individual components, -in Original or Modified Versions, may be sold by itself. - -2) Original or Modified Versions of the Font Software may be bundled, -redistributed and/or sold with any software, provided that each copy -contains the above copyright notice and this license. These can be -included either as stand-alone text files, human-readable headers or -in the appropriate machine-readable metadata fields within text or -binary files as long as those fields can be easily viewed by the user. - -3) No Modified Version of the Font Software may use the Reserved Font -Name(s) unless explicit written permission is granted by the corresponding -Copyright Holder. This restriction only applies to the primary font name as -presented to the users. - -4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font -Software shall not be used to promote, endorse or advertise any -Modified Version, except to acknowledge the contribution(s) of the -Copyright Holder(s) and the Author(s) or with their explicit written -permission. - -5) The Font Software, modified or unmodified, in part or in whole, -must be distributed entirely under this license, and must not be -distributed under any other license. The requirement for fonts to -remain under this license does not apply to any document created -using the Font Software. - -TERMINATION -This license becomes null and void if any of the above conditions are -not met. - -DISCLAIMER -THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT -OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE -COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL -DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM -OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/crates/horizon-theme/src/lib.rs b/crates/horizon-theme/src/lib.rs index aee597f66..3ed778c7f 100644 --- a/crates/horizon-theme/src/lib.rs +++ b/crates/horizon-theme/src/lib.rs @@ -1,16 +1,15 @@ -//! Horizon's design tokens, shared by the launcher (`launcher/src/theme.rs`) -//! and the game's menus (`horizon-client`'s `ui_theme`), so the two read as -//! one product: change a value here and both follow. +//! Horizon's design tokens, the one source of truth for the launcher (`launcher/src/theme.rs`), +//! the game's own menus (`horizon-client`'s `ui_theme`) and the website (`website/src/tokens.css`, +//! generated from [`css`] by `cargo run -p xtask -- tokens`). Change a value here and all three +//! follow. The system is described in `docs/design-system.md`. //! -//! One neutral palette in two appearances and one accent. Spacing follows -//! 4/8/12/16/24/32. Type: Geist for the interface, Instrument Serif for -//! titles, Geist Mono for consoles and commands, all bundled here under the -//! SIL Open Font License (`fonts/OFL-*.txt`). Five sizes: 12, 13, 15, 28 and 56. -//! Colours are `0xRRGGBB`; sizes are in logical pixels. +//! Cool neutrals in two appearances and one violet accent; Geist and Geist Mono only, bundled +//! here under the SIL Open Font License (`fonts/OFL-Geist.txt`). Colours are `0xRRGGBB`; sizes +//! are in logical pixels. +use std::fmt::Write as _; use std::time::Duration; pub const FONT: &str = "Geist"; -pub const DISPLAY: &str = "Instrument Serif"; pub const MONO: &str = "Geist Mono"; /// The bundled font files. @@ -19,53 +18,194 @@ pub mod fonts { pub const GEIST_MEDIUM: &[u8] = include_bytes!("../fonts/Geist-Medium.ttf"); pub const GEIST_SEMIBOLD: &[u8] = include_bytes!("../fonts/Geist-SemiBold.ttf"); pub const GEIST_MONO: &[u8] = include_bytes!("../fonts/GeistMono-Regular.ttf"); - pub const INSTRUMENT_SERIF: &[u8] = include_bytes!("../fonts/InstrumentSerif-Regular.ttf"); } -pub const SMALL: f32 = 12.; -pub const BODY: f32 = 13.; -pub const LARGE: f32 = 15.; -pub const TITLE: f32 = 28.; -pub const HERO: f32 = 56.; -/// The opening's wordmark. -pub const WORDMARK: f32 = 96.; +/// How a type step sizes on the web. +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum Web { + /// The app size, fixed. + Fixed, + /// From `min` px on a 375 px phone to `max` px at 1440 px and wider. + Fluid(f32, f32), + /// A share of the viewport width, in `vw`. + Viewport(f32), +} + +/// One step of the type scale. +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct Step { + pub name: &'static str, + /// The size in the apps (launcher and game menus). + pub px: f32, + pub web: Web, + /// Line height as a multiple of the size. + pub line: f32, + /// Letter spacing in em. + pub tracking: f32, + pub weight: u16, + pub mono: bool, +} + +impl Step { + /// The line height in pixels at the app size. + pub fn line_px(&self) -> f32 { + (self.px * self.line).round() + } +} + +const fn step( + name: &'static str, + px: f32, + web: Web, + line: f32, + tracking: f32, + weight: u16, + mono: bool, +) -> Step { + Step { + name, + px, + web, + line, + tracking, + weight, + mono, + } +} + +/// Indices (`01`), counts and timestamps, in mono. +pub const MICRO: Step = step("micro", 11., Web::Fixed, 1.5, 0.04, 400, true); +/// Footnotes and help under a control. +pub const CAPTION: Step = step("caption", 12., Web::Fixed, 1.5, 0., 400, false); +/// Row labels, navigation and buttons. +pub const LABEL: Step = step("label", 13., Web::Fixed, 1.5, 0., 400, false); +/// Body text in the apps. +pub const UI: Step = step("ui", 14., Web::Fixed, 1.5, 0., 400, false); +/// Paragraphs. +pub const BODY: Step = step("body", 15., Web::Fluid(15., 17.), 1.6, 0., 400, false); +/// Section heads. +pub const HEADING: Step = step("heading", 20., Web::Fluid(20., 24.), 1.3, -0.01, 500, false); +/// The names in an index list. +pub const TITLE: Step = step("title", 28., Web::Fluid(32., 48.), 1.05, -0.02, 500, false); +/// Page titles. +pub const DISPLAY: Step = step( + "display", + 44., + Web::Fluid(34., 64.), + 1.05, + -0.025, + 500, + false, +); +/// The giant faint signature. +pub const WORDMARK: Step = step("wordmark", 220., Web::Viewport(18.), 0.8, -0.04, 500, false); + +pub const TYPE: [Step; 9] = [ + MICRO, CAPTION, LABEL, UI, BODY, HEADING, TITLE, DISPLAY, WORDMARK, +]; /// The spacing scale. -pub const SPACE: [f32; 6] = [4., 8., 12., 16., 24., 32.]; +pub const SPACE: [f32; 9] = [4., 8., 12., 16., 24., 32., 48., 64., 96.]; +/// Page margins: wide windows and pages, and phones. +pub const GUTTER: f32 = 64.; +pub const GUTTER_NARROW: f32 = 16.; +/// The longest paragraph line, in characters. +pub const MEASURE: f32 = 56.; -/// Corner radii: buttons, fields, nav items and rows; segments inside a -/// segmented control; the segmented control's frame; menus and cards. -pub const RADIUS: f32 = 6.; -pub const RADIUS_SEGMENT: f32 = 5.; -pub const RADIUS_GROUP: f32 = 7.; -pub const RADIUS_CARD: f32 = 8.; -/// Dividers and borders are one pixel. -pub const HAIRLINE: f32 = 1.; +/// Corner radii: fields and small controls; plates (hover rows, console, dialogs); pills +/// (buttons, segmented controls, switches). +pub const RADIUS: f32 = 8.; +pub const RADIUS_PLATE: f32 = 12.; +pub const RADIUS_PILL: f32 = 999.; +/// Rules between rows are one pixel; there are no other borders. +pub const RULE: f32 = 1.; -/// Control heights: buttons and nav items, segments, the large Play button. -pub const CONTROL: f32 = 30.; -pub const SEGMENT: f32 = 26.; +/// Heights: buttons, the one large action, a segment, a field, an index row in the apps and +/// on the web. +pub const CONTROL: f32 = 32.; pub const CONTROL_LARGE: f32 = 40.; -/// A pressed primary button's opacity (secondary and ghost: `PRESSED_SOFT`). -pub const PRESSED: f32 = 0.82; -pub const PRESSED_SOFT: f32 = 0.8; -/// Disabled controls' opacity. +pub const SEGMENT: f32 = 28.; +pub const FIELD: f32 = 36.; +pub const ROW: f32 = 64.; +pub const ROW_WEB: f32 = 86.; +/// The index column of a list (where `01` sits) and how far the hover plate reaches past a row. +pub const INDEX: f32 = 40.; +pub const PLATE_BLEED: f32 = 16.; +/// A pressed primary button's opacity, and disabled controls'. +pub const PRESSED: f32 = 0.85; pub const DISABLED: f32 = 0.4; -/// The hover layer of a primary button: white at this opacity. -pub const PRIMARY_HOVER: f32 = 0.10; -/// Sidebar width and the label column of settings rows. -pub const SIDEBAR: f32 = 200.; -pub const ROW_LABEL: f32 = 150.; -/// Motion: short and eased out, never bouncy. -pub const QUICK: Duration = Duration::from_millis(160); -pub const MOVE: Duration = Duration::from_millis(240); -/// The opening: the wordmark holds, then the interface appears. +/// A duration and its easing curve (CSS `cubic-bezier` control points). +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct Motion { + pub name: &'static str, + pub ms: u64, + pub curve: [f32; 4], +} + +impl Motion { + pub const fn duration(&self) -> Duration { + Duration::from_millis(self.ms) + } + pub fn secs(&self) -> f32 { + self.ms as f32 / 1000. + } + /// The eased progress for a linear `t` in 0..1. + pub fn ease(&self, t: f32) -> f32 { + bezier(self.curve, t) + } +} + +/// Standard ease, for hovers, presses and colour. +pub const QUICK: Motion = Motion { + name: "quick", + ms: 150, + curve: [0.4, 0., 0.2, 1.], +}; +/// Ease-out with a long tail, for selection, switches and page changes. +pub const MOVE: Motion = Motion { + name: "move", + ms: 240, + curve: [0.23, 1., 0.32, 1.], +}; +/// Content arriving: a fade and a [`RISE`]. +pub const ENTER: Motion = Motion { + name: "enter", + ms: 600, + curve: [0.23, 1., 0.32, 1.], +}; +pub const MOTION: [Motion; 3] = [QUICK, MOVE, ENTER]; +/// The delay between list rows arriving, and how far content rises as it arrives. +pub const STAGGER: Duration = Duration::from_millis(40); +pub const RISE: f32 = 8.; + +/// The launcher's opening: the wordmark holds, then the interface arrives. pub const OPENING_HOLD: Duration = Duration::from_millis(1400); pub const OPENING_MAX: Duration = Duration::from_millis(2500); pub const OPENING_REVEAL: Duration = Duration::from_millis(800); -/// GPUI's `ease_out_quint`, used for hovers, the sliding selection and page changes. +/// A CSS `cubic-bezier(x1, y1, x2, y2)` at `t`: solves x for the curve parameter, returns y. +pub fn bezier([x1, y1, x2, y2]: [f32; 4], t: f32) -> f32 { + let t = t.clamp(0., 1.); + if t == 0. || t == 1. { + return t; + } + let at = |a: f32, b: f32, s: f32| { + let u = 1. - s; + 3. * u * u * s * a + 3. * u * s * s * b + s * s * s + }; + let (mut lo, mut hi) = (0f32, 1f32); + for _ in 0..24 { + let mid = (lo + hi) / 2.; + if at(x1, x2, mid) < t { + lo = mid; + } else { + hi = mid; + } + } + at(y1, y2, (lo + hi) / 2.) +} + pub fn ease_out_quint(t: f32) -> f32 { 1. - (1. - t.clamp(0., 1.)).powi(5) } @@ -75,46 +215,298 @@ pub fn ease_out_cubic(t: f32) -> f32 { #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct Palette { - pub bg: u32, - pub sidebar: u32, - pub raised: u32, - pub hover: u32, - pub border: u32, - pub text: u32, + /// The background. + pub page: u32, + /// The hover plate, fields, the segmented track, the console. + pub plate_soft: u32, + /// Pressed plates, a switch that is off, the faint wordmark. + pub plate: u32, + /// Dialogs and menus above the page. + pub surface: u32, + /// One-pixel rules between rows, slider and progress tracks. + pub rule: u32, + /// Text, selection, the slider's fill. + pub ink: u32, + /// Secondary text and values. + pub ink_soft: u32, + /// Labels, descriptions, indices. pub muted: u32, - pub faint: u32, + /// The main action, links, focus, progress. pub accent: u32, pub on_accent: u32, pub danger: u32, + pub success: u32, pub dark: bool, } -pub const DARK: Palette = Palette { - bg: 0x111113, - sidebar: 0x0c0c0d, - raised: 0x1a1a1d, - hover: 0x202024, - border: 0x26262a, - text: 0xe8e8ea, - muted: 0x9a9aa1, - faint: 0x626269, - accent: 0x7c5cc4, +pub const LIGHT: Palette = Palette { + page: 0xfafafc, + plate_soft: 0xf3f3f8, + plate: 0xebecf4, + surface: 0xffffff, + rule: 0xe2e3ea, + ink: 0x16181f, + ink_soft: 0x3b3e49, + muted: 0x646875, + accent: 0x5b3fd6, on_accent: 0xffffff, - danger: 0xd9705f, + danger: 0xb4372a, + success: 0x1d7a48, + dark: false, +}; + +pub const DARK: Palette = Palette { + page: 0x0d0e13, + plate_soft: 0x181a22, + plate: 0x20222c, + surface: 0x16181f, + rule: 0x24262f, + ink: 0xecedf3, + ink_soft: 0xc5c7d1, + muted: 0x8b8f9c, + accent: 0x9a86ff, + on_accent: 0x0d0e13, + danger: 0xf07a68, + success: 0x45c27a, dark: true, }; -pub const LIGHT: Palette = Palette { - bg: 0xfcfcfb, - sidebar: 0xf4f4f2, - raised: 0xf2f2f0, - hover: 0xebebe8, - border: 0xe3e3df, - text: 0x19191b, - muted: 0x63636a, - faint: 0x9a9a9f, - accent: 0x6a4bb3, - on_accent: 0xffffff, - danger: 0xb84a3a, - dark: false, -}; +/// How strongly the game's menus veil the live backdrop (the title panorama, or the world behind +/// the pause and options screens) with the page colour. Every text colour the menus use keeps +/// WCAG AA over it, even on a selected row's plate, with a backdrop as bright as +/// [`BRIGHT_BACKDROP`] (a test checks it). +pub const VEIL: f32 = 0.90; +/// The title's home page shows more of the world; its text is `ink` and `ink_soft` only. +pub const HOME_VEIL: f32 = 0.80; +/// Muted text over the veiled backdrop: the dark palette's `muted`, lifted so it holds AA there. +pub const BACKDROP_MUTED: u32 = 0x9fa3ae; +/// The brightest backdrop the veils are measured against: a light grey of luminance 0.77, +/// brighter than the snowiest title panorama measured (0.49) and a sunlit world. +pub const BRIGHT_BACKDROP: u32 = 0xe3e3e3; + +impl Palette { + /// Every colour with its token name, in the order the docs list them. + pub fn named(&self) -> [(&'static str, u32); 12] { + [ + ("page", self.page), + ("plate-soft", self.plate_soft), + ("plate", self.plate), + ("surface", self.surface), + ("rule", self.rule), + ("ink", self.ink), + ("ink-soft", self.ink_soft), + ("muted", self.muted), + ("accent", self.accent), + ("on-accent", self.on_accent), + ("danger", self.danger), + ("success", self.success), + ] + } +} + +/// The WCAG 2 contrast ratio of two colours. +pub fn contrast(a: u32, b: u32) -> f32 { + fn luminance(c: u32) -> f32 { + let ch = |s: u32| { + let v = ((c >> s) & 255) as f32 / 255.; + if v <= 0.03928 { + v / 12.92 + } else { + ((v + 0.055) / 1.055).powf(2.4) + } + }; + 0.2126 * ch(16) + 0.7152 * ch(8) + 0.0722 * ch(0) + } + let (x, y) = (luminance(a), luminance(b)); + (x.max(y) + 0.05) / (x.min(y) + 0.05) +} + +/// `website/src/tokens.css`: every token as a CSS custom property, the light palette by +/// default, the dark one when the system asks for it or the page sets `data-theme="dark"`. +pub fn css() -> String { + let mut s = String::new(); + let num = |v: f32| { + let t = format!("{v:.3}"); + t.trim_end_matches('0').trim_end_matches('.').to_string() + }; + let colors = |s: &mut String, p: &Palette| { + for (name, c) in p.named() { + let _ = writeln!(s, " --{name}: #{c:06x};"); + } + let _ = writeln!( + s, + " color-scheme: {};", + if p.dark { "dark" } else { "light" } + ); + }; + s.push_str( + "/* Generated from crates/horizon-theme by `cargo run -p xtask -- tokens`; do not edit.\n \ + docs/design-system.md describes the tokens. */\n\n:root {\n", + ); + colors(&mut s, &LIGHT); + let _ = writeln!( + s, + " --font: \"{FONT}\", ui-sans-serif, system-ui, sans-serif;\n --mono: \"{MONO}\", ui-monospace, monospace;" + ); + for step in TYPE { + let size = match step.web { + Web::Fixed => format!("{}px", num(step.px)), + Web::Fluid(min, max) => format!( + "clamp({}px, calc({}px + {} * (100vw - 375px) / 1065), {}px)", + num(min), + num(min), + num(max - min), + num(max) + ), + Web::Viewport(vw) => format!("{}vw", num(vw)), + }; + let n = step.name; + let _ = writeln!(s, " --text-{n}: {size};"); + let _ = writeln!(s, " --text-{n}-line: {};", num(step.line)); + let _ = writeln!(s, " --text-{n}-tracking: {}em;", num(step.tracking)); + let _ = writeln!(s, " --text-{n}-weight: {};", step.weight); + } + for (i, v) in SPACE.iter().enumerate() { + let _ = writeln!(s, " --space-{}: {}px;", i + 1, num(*v)); + } + for (name, v) in [ + ("gutter", GUTTER), + ("gutter-narrow", GUTTER_NARROW), + ("radius", RADIUS), + ("radius-plate", RADIUS_PLATE), + ("radius-pill", RADIUS_PILL), + ("rule-width", RULE), + ("control", CONTROL), + ("control-large", CONTROL_LARGE), + ("segment", SEGMENT), + ("field", FIELD), + ("row", ROW_WEB), + ("index", INDEX), + ("plate-bleed", PLATE_BLEED), + ("rise", RISE), + ] { + let _ = writeln!(s, " --{name}: {}px;", num(v)); + } + let _ = writeln!(s, " --measure: {}ch;", num(MEASURE)); + for m in MOTION { + let [a, b, c, d] = m.curve; + let _ = writeln!(s, " --{}: {}ms;", m.name, m.ms); + let _ = writeln!( + s, + " --ease-{}: cubic-bezier({}, {}, {}, {});", + m.name, + num(a), + num(b), + num(c), + num(d) + ); + } + let _ = writeln!(s, " --stagger: {}ms;", STAGGER.as_millis()); + s.push_str( + "}\n\n@media (prefers-color-scheme: dark) {\n :root:not([data-theme=\"light\"]) {\n", + ); + let mut dark = String::new(); + colors(&mut dark, &DARK); + for line in dark.lines() { + let _ = writeln!(s, " {line}"); + } + s.push_str(" }\n}\n\n:root[data-theme=\"dark\"] {\n"); + s.push_str(&dark); + s.push_str("}\n"); + s +} + +#[cfg(test)] +mod tests { + use super::*; + + /// Every text colour on every background it is drawn on reaches WCAG AA (4.5:1). + #[test] + fn text_meets_wcag_aa_in_both_palettes() { + for p in [LIGHT, DARK] { + let backgrounds = [ + ("page", p.page), + ("plate_soft", p.plate_soft), + ("plate", p.plate), + ("surface", p.surface), + ]; + let texts = [ + ("ink", p.ink), + ("ink_soft", p.ink_soft), + ("muted", p.muted), + ("accent", p.accent), + ("danger", p.danger), + ("success", p.success), + ]; + for (bn, bg) in backgrounds { + for (tn, fg) in texts { + let ratio = contrast(fg, bg); + assert!( + ratio >= 4.5, + "{} {tn} on {bn}: {ratio:.2}", + if p.dark { "dark" } else { "light" } + ); + } + } + // Text on the accent, and page-coloured text on an ink segment. + assert!(contrast(p.on_accent, p.accent) >= 4.5); + assert!(contrast(p.page, p.ink) >= 4.5); + } + } + + /// The game's menus over the brightest backdrop: the page colour veiled over it, and a + /// selected row's plate (ink at 8 %) on top. + #[test] + fn menu_text_meets_wcag_aa_over_a_bright_backdrop() { + let mix = |a: u32, b: u32, t: f32| { + [16, 8, 0].iter().fold(0, |out, s| { + let (x, y) = (((a >> s) & 255) as f32, ((b >> s) & 255) as f32); + out | ((x * (1. - t) + y * t).round() as u32) << s + }) + }; + let p = DARK; + for (veil, texts) in [ + ( + VEIL, + &[p.ink, p.ink_soft, BACKDROP_MUTED, p.danger, p.success][..], + ), + (HOME_VEIL, &[p.ink, p.ink_soft][..]), + ] { + let bg = mix(BRIGHT_BACKDROP, p.page, veil); + let plate = mix(bg, p.ink, 0.08); + for &text in texts { + for under in [bg, plate] { + let ratio = contrast(text, under); + assert!(ratio >= 4.5, "#{text:06x} over veil {veil}: {ratio:.2}"); + } + } + } + assert!(contrast(BACKDROP_MUTED, p.page) >= 4.5); + } + + #[test] + fn contrast_matches_known_values() { + assert!((contrast(0x000000, 0xffffff) - 21.).abs() < 0.01); + assert!((contrast(0x777777, 0xffffff) - 4.48).abs() < 0.01); + } + + #[test] + fn bezier_eases_out() { + assert_eq!(bezier(MOVE.curve, 0.), 0.); + assert!((bezier(MOVE.curve, 1.) - 1.).abs() < 1e-4); + assert!(MOVE.ease(0.25) > 0.6, "{}", MOVE.ease(0.25)); + assert!((bezier([0., 0., 1., 1.], 0.3) - 0.3).abs() < 1e-3); + } + + /// `website/src/tokens.css` is what [`css`] writes; regenerate it with + /// `cargo run -p xtask -- tokens`. + #[test] + fn website_tokens_are_up_to_date() { + let path = concat!(env!("CARGO_MANIFEST_DIR"), "/../../website/src/tokens.css"); + let written = std::fs::read_to_string(path).unwrap_or_default(); + assert!( + written == css(), + "website/src/tokens.css is out of date: run `cargo run -p xtask -- tokens`" + ); + } +} diff --git a/docs/design-system.md b/docs/design-system.md new file mode 100644 index 000000000..7a93fb806 --- /dev/null +++ b/docs/design-system.md @@ -0,0 +1,162 @@ +# Horizon's design system + +One design language for the launcher, the website and the game's own menus (what "Menu style: +Horizon" draws). Vanilla's classic screens and the HUD are not part of it: they stay exactly +vanilla, because parity is the point of the game. + +The tokens live in one place, `crates/horizon-theme`. The launcher (`launcher/src/theme.rs`) +and the game (`crates/horizon-client/src/ui_theme.rs`) read them as Rust constants, and the +website reads them as CSS custom properties generated from the same crate +(`cargo run -p xtask -- tokens` writes `website/src/tokens.css`; a test fails when the file is +out of date). Change a value in the crate and all three follow. + +## Where it comes from + +The direction was set by [mkdir.directory](https://mkdir.directory/), a directory site that is +almost nothing but type. What we take from it is its restraint rather than its content: + +1. **Type is the interface.** One family, Geist, and its mono. Large, tight display type + (medium weight, -2 % tracking) carries the hierarchy, so there is no need for boxes, icons or + colour to say what matters. Instrument Serif is gone. +2. **Lists, not cards.** Content is a numbered list: a small mono index on the left (`01`, + `02`…), the name large, a mono detail on the right, and a 1 px rule between rows. Versions, + settings, worlds, servers, release notes and the parity table are all this one component. +3. **One accent, used once.** Neutrals do the work. The violet marks the single main action on a + screen (Play, Download), focus, links and progress; selection is shown in ink, not in colour. +4. **Space instead of borders.** Generous margins (64 px on wide screens, 16 px on phones), no + shadows, no gradients, no outlines around groups. A surface tint appears only under the + pointer or behind something that must stand apart (a console, a dialog). +5. **Quiet motion.** Things arrive with a short fade and an 8 px rise, a few tens of + milliseconds apart, eased out, never bouncy. Hovers fade a soft plate in behind the row. +6. **A signature.** A giant, faint wordmark: at the foot of the website, behind the launcher's + opening and the game's title screen. + +## Tokens + +### Colour + +Cool, slightly blue neutrals in two appearances with the same restraint, and Horizon's violet. +Every text colour passes WCAG AA (4.5:1) on every background it is used on; the tests in +`horizon-theme` check each pair in both palettes. + +| Token | Light | Dark | Use | +|--------------|-----------|-----------|-----| +| `page` | `#fafafc` | `#0d0e13` | the background | +| `plate_soft` | `#f3f3f8` | `#181a22` | hover plate, fields, segmented track, console | +| `plate` | `#ebecf4` | `#20222c` | pressed plate, switch off, the faint wordmark | +| `surface` | `#ffffff` | `#16181f` | dialogs and menus that sit above the page | +| `rule` | `#e2e3ea` | `#24262f` | 1 px rules between rows, tracks | +| `ink` | `#16181f` | `#ecedf3` | text, selection, slider fill, the inverted segment | +| `ink_soft` | `#3b3e49` | `#c5c7d1` | secondary text, values | +| `muted` | `#646875` | `#8b8f9c` | labels, descriptions, mono indices and details | +| `accent` | `#5b3fd6` | `#9a86ff` | the main action, links, focus, progress | +| `on_accent` | `#ffffff` | `#0d0e13` | text on the accent | +| `danger` | `#b4372a` | `#f07a68` | errors, the crash notice's dot | +| `success` | `#1d7a48` | `#45c27a` | "Matches vanilla", "Ready" | + +The game's menus draw over the live title backdrop, always in the dark palette, with the page +colour as a flat veil so text keeps its contrast whatever the world shows: `VEIL` (0.90) on +every page and in a world, `HOME_VEIL` (0.80) on the title's home page, which shows more of the +world and keeps to `ink` and `ink_soft`. Muted text over the backdrop is `BACKDROP_MUTED` +(`#9fa3ae`). A test holds every pair to AA over a backdrop of luminance 0.77 (the snowiest title +panorama measured reaches 0.49), on the bare veil and on a selected row's plate. + +### Type + +Geist (400, 500, 600) and Geist Mono (400), bundled under the SIL Open Font License. + +| Token | App px | Web (min–max px) | Line | Tracking | Weight | Use | +|------------|--------|------------------|------|----------|--------|-----| +| `micro` | 11 | 11 | 1.5 | +0.04em | mono | indices (`01`), counts, timestamps | +| `caption` | 12 | 12 | 1.5 | 0 | 400 | footnotes, help under a control | +| `label` | 13 | 13 | 1.5 | 0 | 400 | row labels, nav, buttons | +| `ui` | 14 | 14 | 1.5 | 0 | 400 | body text in the apps | +| `body` | 15 | 15–17 | 1.6 | 0 | 400 | paragraphs | +| `heading` | 20 | 20–24 | 1.3 | -0.01em | 500 | section heads | +| `title` | 28 | 32–48 | 1.05 | -0.02em | 500 | list item names | +| `display` | 44 | 34–64 | 1.05 | -0.025em | 500 | page titles | +| `wordmark` | 220 | 18vw | 0.8 | -0.04em | 500 | the faint signature | + +### Space, shape and lines + +- Spacing scale: 4, 8, 12, 16, 24, 32, 48, 64, 96. Page gutter 64 (apps and wide web), 16 on + phones. Text measure at most 56 characters for paragraphs. +- Radii: 8 for fields and small controls, 12 for plates (hover rows, console, dialogs), full for + buttons, segmented controls and switches. +- Lines: 1 px, `rule`. No other borders. +- Heights: control 32, large control (Play) 40, segment 28, list row 64 (apps), 86 (web). + +### Motion + +| Token | Duration | Easing | Use | +|---------|----------|---------------------------------|-----| +| `quick` | 150 ms | `cubic-bezier(.4, 0, .2, 1)` | hovers, presses, colour | +| `move` | 240 ms | `cubic-bezier(.23, 1, .32, 1)` | selection sliding, switches, page changes | +| `enter` | 600 ms | `cubic-bezier(.23, 1, .32, 1)` | content arriving: opacity 0→1, rise 8 px | +| `stagger` | 40 ms | | delay between list rows arriving | + +`prefers-reduced-motion` (web) turns `enter` into a plain fade. + +## Components + +- **Index list** (the signature): `micro` mono index in `muted` (left, 40 px column), the name + in `title` (or `ui`/`label` for dense lists such as settings), details in `micro` mono + `muted` on the right, a `rule` under every row. Hover: a `plate_soft` plate with radius 12 + fades in, extending 16 px past the row on each side, and the index turns `ink`. +- **Buttons**: pill shaped, `label` size, medium weight, 32 high (40 for the one large action). + *Primary* is accent with `on_accent` text, at most one per screen. *Secondary* is + `plate_soft` with `ink` text. *Ghost* is `muted` text that turns `ink` with a `plate_soft` + plate under the pointer. Pressed: `plate` (or the accent at 85 %). Disabled: 40 % opacity. +- **Fields**: 36 high, `plate_soft`, radius 8, no border; focus draws a 1 px accent ring. + Monospace for paths and commands. +- **Switch**: 36×20 pill, `plate` when off, accent when on, a white 16 px knob that slides over + `move`. +- **Slider**: a 2 px `rule` track, the filled part `ink`, a 14 px `ink` knob. The value is + written in mono beside the label, not on the track. +- **Segmented control / tabs**: a `plate_soft` pill; the selected segment is an `ink` pill with + `page` text that slides over `move`. +- **Navigation**: text only. Launcher: a top bar with the mark and "Horizon" on the left and + the pages on the right, `label` size, `muted`, the current one `ink`. Game menus keep their + sidebar layout (it suits a controller), but as a plain column of text items on the page + colour, the current one in `ink` with a 2 px accent tick, no pill and no separate panel tint. +- **Page header**: `display` title, then one `body` line in `muted`, 56 characters at most. +- **Notices and dialogs**: a `plate_soft` plate, radius 12, 16–24 padding, no border; a 6 px dot + in `danger` (or `accent`) leads the title. Actions are buttons in a row below. +- **Progress**: a 2 px `rule` track and an `accent` fill; indeterminate work shuttles a 30 % + segment. +- **Console**: `plate_soft` plate, radius 12, `micro`/`caption` mono in `ink_soft`, newest line + at the bottom, the command field inside the plate under a `rule`. +- **Empty states**: a short `muted` sentence and one secondary button, centred in the space. + +## Surfaces + +- **Launcher** (`launcher/`): top bar; Play is a page header (version as the title, its notes' + first line under it), the client/server segmented control, the version picker and Play, then + an index list of Resources, Minecraft folder (and the server rows). Versions and Patch notes + are index lists with the release name as the title; Settings is an index list of switches and + values. The opening is the faint wordmark drawn letter by letter, then the interface arrives. + The sunset photograph is gone: the window is the page colour, light or dark with the system. +- **Website** (`website/`): the same page structure as before (what it is, screenshots, + parity, launcher, patch notes, community), each section a `micro` mono label, a `display` + heading and a short paragraph, its content an index list. Screenshots stay as images (radius + 12, no frame). Light and dark follow the system, with a toggle. A giant faint wordmark sits + above the footer. No hero photograph: the first screen is the headline, one paragraph, the + download button and the parity score as an index row. +- **Game menus** (Horizon style): the title backdrop under a page-colour veil; text sidebar; + index lists for worlds and servers; options pages as index lists of rows (label left, value + in mono, the control right). The pause menu is a centred column of plain rows over a darker + veil. + +## The mark + +**Horizon line.** A sun half set below a horizon, drawn as three horizontal bars of 4, 8 and +10 units over a 12 unit line, on a 16 unit grid. The bars are the sun cut by the horizon into +slices, which also reads as layers of terrain and as a nod to voxels without drawing a block. It +is built on whole units of the 16 px grid so it stays sharp at 16 px, and it scales without +detail to 1024 px. + +- Monochrome: the mark in `ink` on light, in `ink` (dark) on dark; the line can take the accent. +- App icon: the mark in `#ecedf3` with the line in `#9a86ff`, on a `#16181f` rounded square + (macOS grid: 824 px tile with 185 px corners in a 1024 canvas; Windows and Linux use the full + square with 22 % corners). +- Exports and where they go: `docs/media/brand/README.md`. diff --git a/launcher/src/main.rs b/launcher/src/main.rs index 5a486f6ea..bbbbc5b53 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -2701,7 +2701,6 @@ fn main() { Cow::Borrowed(horizon_theme::fonts::GEIST_MEDIUM), Cow::Borrowed(horizon_theme::fonts::GEIST_SEMIBOLD), Cow::Borrowed(horizon_theme::fonts::GEIST_MONO), - Cow::Borrowed(horizon_theme::fonts::INSTRUMENT_SERIF), ]) .expect("bundled fonts"); let bounds = Bounds::centered(None, size(px(1040.), px(700.)), cx); diff --git a/launcher/src/theme.rs b/launcher/src/theme.rs index 08f8741d7..20f276951 100644 --- a/launcher/src/theme.rs +++ b/launcher/src/theme.rs @@ -1,29 +1,33 @@ -//! The launcher's view of Horizon's design tokens (`crates/horizon-theme`), which the game's -//! menus share: one neutral palette in two appearances and one accent, spacing 4/8/12/16/24/32, -//! Geist / Instrument Serif / Geist Mono (bundled, SIL Open Font License), five sizes. +//! The launcher's view of Horizon's design tokens (`crates/horizon-theme`, described in +//! `docs/design-system.md`), which the game's menus and the website share: cool neutrals in two +//! appearances and one violet accent, Geist and Geist Mono (bundled, SIL Open Font License). use gpui::{rgb, Hsla, WindowAppearance}; use horizon_theme as tokens; use std::time::Duration; pub const FONT: &str = tokens::FONT; -pub const DISPLAY: &str = tokens::DISPLAY; +/// Display type is Geist too, at medium weight. +pub const DISPLAY: &str = tokens::FONT; pub const MONO: &str = tokens::MONO; -pub const SMALL: f32 = tokens::SMALL; -pub const BODY: f32 = tokens::BODY; -pub const LARGE: f32 = tokens::LARGE; -pub const TITLE: f32 = tokens::TITLE; -pub const HERO: f32 = tokens::HERO; +pub const SMALL: f32 = tokens::CAPTION.px; +pub const BODY: f32 = tokens::LABEL.px; +pub const LARGE: f32 = tokens::BODY.px; +pub const TITLE: f32 = tokens::TITLE.px; +pub const HERO: f32 = tokens::DISPLAY.px; /// Shapes and controls, shared with the game's menus. -pub use tokens::{ - CONTROL, DISABLED, PRESSED, PRESSED_SOFT, PRIMARY_HOVER, RADIUS, RADIUS_GROUP, RADIUS_SEGMENT, - ROW_LABEL, SEGMENT, SIDEBAR, -}; +pub use tokens::{CONTROL, DISABLED, PRESSED, RADIUS, SEGMENT}; +pub const PRESSED_SOFT: f32 = tokens::PRESSED; +pub const PRIMARY_HOVER: f32 = 0.10; +pub const RADIUS_SEGMENT: f32 = tokens::RADIUS; +pub const RADIUS_GROUP: f32 = tokens::RADIUS; +pub const ROW_LABEL: f32 = 150.; +pub const SIDEBAR: f32 = 200.; /// Motion: short and eased out, never bouncy. -pub const QUICK: Duration = tokens::QUICK; -pub const MOVE: Duration = tokens::MOVE; +pub const QUICK: Duration = tokens::QUICK.duration(); +pub const MOVE: Duration = tokens::MOVE.duration(); #[derive(Clone, Copy)] pub struct Theme { @@ -63,14 +67,14 @@ impl Theme { fn from(p: tokens::Palette) -> Self { Self { - bg: c(p.bg), - sidebar: c(p.sidebar), - raised: c(p.raised), - hover: c(p.hover), - border: c(p.border), - text: c(p.text), - muted: c(p.muted), - faint: c(p.faint), + bg: c(p.page), + sidebar: c(p.plate_soft), + raised: c(p.plate_soft), + hover: c(p.plate), + border: c(p.rule), + text: c(p.ink), + muted: c(p.ink_soft), + faint: c(p.muted), accent: c(p.accent), on_accent: c(p.on_accent), danger: c(p.danger), diff --git a/website/src/tokens.css b/website/src/tokens.css new file mode 100644 index 000000000..d272865cc --- /dev/null +++ b/website/src/tokens.css @@ -0,0 +1,121 @@ +/* Generated from crates/horizon-theme by `cargo run -p xtask -- tokens`; do not edit. + docs/design-system.md describes the tokens. */ + +:root { + --page: #fafafc; + --plate-soft: #f3f3f8; + --plate: #ebecf4; + --surface: #ffffff; + --rule: #e2e3ea; + --ink: #16181f; + --ink-soft: #3b3e49; + --muted: #646875; + --accent: #5b3fd6; + --on-accent: #ffffff; + --danger: #b4372a; + --success: #1d7a48; + color-scheme: light; + --font: "Geist", ui-sans-serif, system-ui, sans-serif; + --mono: "Geist Mono", ui-monospace, monospace; + --text-micro: 11px; + --text-micro-line: 1.5; + --text-micro-tracking: 0.04em; + --text-micro-weight: 400; + --text-caption: 12px; + --text-caption-line: 1.5; + --text-caption-tracking: 0em; + --text-caption-weight: 400; + --text-label: 13px; + --text-label-line: 1.5; + --text-label-tracking: 0em; + --text-label-weight: 400; + --text-ui: 14px; + --text-ui-line: 1.5; + --text-ui-tracking: 0em; + --text-ui-weight: 400; + --text-body: clamp(15px, calc(15px + 2 * (100vw - 375px) / 1065), 17px); + --text-body-line: 1.6; + --text-body-tracking: 0em; + --text-body-weight: 400; + --text-heading: clamp(20px, calc(20px + 4 * (100vw - 375px) / 1065), 24px); + --text-heading-line: 1.3; + --text-heading-tracking: -0.01em; + --text-heading-weight: 500; + --text-title: clamp(32px, calc(32px + 16 * (100vw - 375px) / 1065), 48px); + --text-title-line: 1.05; + --text-title-tracking: -0.02em; + --text-title-weight: 500; + --text-display: clamp(34px, calc(34px + 30 * (100vw - 375px) / 1065), 64px); + --text-display-line: 1.05; + --text-display-tracking: -0.025em; + --text-display-weight: 500; + --text-wordmark: 18vw; + --text-wordmark-line: 0.8; + --text-wordmark-tracking: -0.04em; + --text-wordmark-weight: 500; + --space-1: 4px; + --space-2: 8px; + --space-3: 12px; + --space-4: 16px; + --space-5: 24px; + --space-6: 32px; + --space-7: 48px; + --space-8: 64px; + --space-9: 96px; + --gutter: 64px; + --gutter-narrow: 16px; + --radius: 8px; + --radius-plate: 12px; + --radius-pill: 999px; + --rule-width: 1px; + --control: 32px; + --control-large: 40px; + --segment: 28px; + --field: 36px; + --row: 86px; + --index: 40px; + --plate-bleed: 16px; + --rise: 8px; + --measure: 56ch; + --quick: 150ms; + --ease-quick: cubic-bezier(0.4, 0, 0.2, 1); + --move: 240ms; + --ease-move: cubic-bezier(0.23, 1, 0.32, 1); + --enter: 600ms; + --ease-enter: cubic-bezier(0.23, 1, 0.32, 1); + --stagger: 40ms; +} + +@media (prefers-color-scheme: dark) { + :root:not([data-theme="light"]) { + --page: #0d0e13; + --plate-soft: #181a22; + --plate: #20222c; + --surface: #16181f; + --rule: #24262f; + --ink: #ecedf3; + --ink-soft: #c5c7d1; + --muted: #8b8f9c; + --accent: #9a86ff; + --on-accent: #0d0e13; + --danger: #f07a68; + --success: #45c27a; + color-scheme: dark; + } +} + +:root[data-theme="dark"] { + --page: #0d0e13; + --plate-soft: #181a22; + --plate: #20222c; + --surface: #16181f; + --rule: #24262f; + --ink: #ecedf3; + --ink-soft: #c5c7d1; + --muted: #8b8f9c; + --accent: #9a86ff; + --on-accent: #0d0e13; + --danger: #f07a68; + --success: #45c27a; + color-scheme: dark; +} diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 9c84fa59b..de1a0ecab 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -4,7 +4,10 @@ version = "0.1.0" edition.workspace = true license.workspace = true publish = false -description = "Repository tasks: cargo run -p xtask -- package BINARY OUTDIR" +description = "Repository tasks: cargo run -p xtask -- package BINARY OUTDIR | tokens" + +[dependencies] +horizon-theme = { path = "../crates/horizon-theme" } [lints] workspace = true diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 3b6b6a1ce..6f54fa132 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -5,12 +5,15 @@ //! horizon-prepare), the exporters horizon-prepare compiles, its sources (the launcher compares //! them to its own), and PLAY.txt. It holds none of Minecraft's files: players prepare those //! from their own copy. .github/workflows/release.yml makes the release folders with it. +//! +//! `tokens`: writes `website/src/tokens.css`, the design tokens of `crates/horizon-theme` as CSS +//! custom properties (a horizon-theme test fails when the file is out of date). use std::fs; use std::path::{Component, Path, PathBuf}; use std::process::{Command, ExitCode}; -const USAGE: &str = "usage: cargo run -p xtask -- package BINARY OUTDIR"; +const USAGE: &str = "usage: cargo run -p xtask -- package BINARY OUTDIR | tokens"; /// What the release folder takes from the repository at HEAD, as `git archive` writes it. const ARCHIVED: [&str; 5] = [ @@ -30,6 +33,7 @@ fn main() -> ExitCode { let args: Vec = std::env::args().skip(1).collect(); let result = match args.as_slice() { [task, binary, out] if task == "package" => package(Path::new(binary), Path::new(out)), + [task] if task == "tokens" => tokens(), _ => Err(USAGE.to_string()), }; match result { @@ -58,6 +62,13 @@ fn git(repo: &Path, args: &[&str]) -> Result, String> { Ok(output.stdout) } +fn tokens() -> Result<(), String> { + let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("../website/src/tokens.css"); + fs::write(&path, horizon_theme::css()).map_err(|e| format!("{}: {e}", path.display()))?; + println!("wrote website/src/tokens.css"); + Ok(()) +} + fn package(binary: &Path, out: &Path) -> Result<(), String> { let top = git( Path::new(env!("CARGO_MANIFEST_DIR")),