diff --git a/crates/client/design/tokens.toml b/crates/client/design/tokens.toml index 5a2d26f..1f6365a 100644 --- a/crates/client/design/tokens.toml +++ b/crates/client/design/tokens.toml @@ -29,6 +29,7 @@ bad = "#b33b2a" hue = ["#9c520c", "#11638d", "#7a43c9", "#1a6e41", "#b8325f", "#765b00", "#b33b2a", "#0a6c67", "#5a54c4", "#151726"] [space] +xxs = 2 xs = 4 sm = 8 md = 12 @@ -57,10 +58,19 @@ display = 28 text = 1.4 [size] +icon_sm = 14 icon = 18 +chip = 22 +control_sm = 26 control = 34 row = 44 avatar = 26 +avatar_lg = 64 +thumb = 120 sidebar = 230 talk = 300 popover = 300 +sheet = 380 +media = 400 +wide = 520 +page = 640 diff --git a/crates/client/src/gui.rs b/crates/client/src/gui.rs index c3af014..eebc624 100644 --- a/crates/client/src/gui.rs +++ b/crates/client/src/gui.rs @@ -3,7 +3,7 @@ use std::{ collections::HashMap, fmt::Display, sync::Arc, - time::{Duration, Instant}, + time::Instant, }; use common::{ @@ -17,7 +17,7 @@ use common::{ }, }; use gpui_kit::{ - Anchor, Animation, AnimationElement, AnimationExt, AnyElement, AnyWindowHandle, App, + AnyElement, AnyWindowHandle, App, AppContext, AsyncWindowContext, Context, Div, ElementId, Entity, FontWeight, Hsla, Image, ImageFormat, InteractiveElement, IntoElement, KeyBinding, KeyDownEvent, KeyUpEvent, ModifiersChangedEvent, ParentElement, Pixels, Rems, Render, RenderOnce, Stateful, @@ -29,7 +29,7 @@ use gpui_kit::{ notification::Notification, spinner::Spinner, }, - div, ease_out_quint, img, px, rems, + div, img, px, rems, }; use jiff::{Timestamp, tz::TimeZone}; use tokio::sync::mpsc; @@ -71,16 +71,14 @@ mod wave; mod widget; use auth::Auth; -use style::Tokens; +use style::{Tokens, radius, size, space, text}; use chat::{Chat, View}; use voice_settings::VoiceControls; actions!(yumush, [FocusFind, CloseSettings]); -pub const BASE_FONT: f32 = 14.; - pub fn text(size: f32) -> Rems { - rems(size / BASE_FONT) + rems(size / text::UI) } #[derive(Clone, Copy)] @@ -186,15 +184,15 @@ pub fn sync_theme(cx: &mut App) { colors.secondary = palette.field; colors.secondary_foreground = palette.text; colors.primary = palette.accent; - colors.primary_hover = palette.accent.opacity(0.85); + colors.primary_hover = palette.accent; colors.primary_active = palette.accent; colors.primary_foreground = palette.on_accent; colors.ring = palette.accent; colors.caret = palette.accent; colors.danger = palette.danger; theme.tokens = (&theme.colors).into(); - theme.radius = px(6.); - theme.radius_lg = px(10.); + theme.radius = px(radius::SM); + theme.radius_lg = px(radius::LG); theme.font_size = font_size; theme.focus_ring = false; } @@ -264,13 +262,13 @@ pub fn community_icon( Some(image) => div() .size(size) .flex_shrink_0() - .rounded(px(4.)) + .rounded(px(radius::SM)) .overflow_hidden() .child(img(image.clone()).size_full()), - None => badge(palette, community.id, &community.name, size, font).rounded(px(4.)), + None => badge(palette, community.id, &community.name, size, font).rounded(px(radius::SM)), }, CommunityKind::Direct { peer } => avatar(palette, peer, size, font, avatars), - CommunityKind::Notes => badge(palette, community.id, "Notes", size, font).rounded(px(4.)), + CommunityKind::Notes => badge(palette, community.id, "Notes", size, font).rounded(px(radius::SM)), } } @@ -307,43 +305,7 @@ pub fn millis_time(millis: u64, format: &str) -> String { .to_string() } -const MOTION_TRAVEL: f32 = 6.; - -pub fn motion() -> Animation { - Animation::new(Duration::from_millis(160)).with_easing(ease_out_quint()) -} - -pub fn pop_in( - id: impl Into, - element: E, - anchor: Anchor, -) -> AnimationElement { - let travel = if anchor.is_bottom() { - MOTION_TRAVEL - } else { - -MOTION_TRAVEL - }; - - element.with_animation(id, motion(), move |element, delta| { - element.top(px(travel * (1. - delta))).opacity(delta) - }) -} - -pub fn swap_in( - id: impl Into, - element: E, - forward: bool, -) -> AnimationElement { - let travel = if forward { - MOTION_TRAVEL - } else { - -MOTION_TRAVEL - }; - - element.with_animation(id, motion(), move |element, delta| { - element.left(px(travel * (1. - delta))).opacity(delta) - }) -} +pub use parts::{motion, pop_in, swap_in}; pub fn hoverable(id: impl Into, element: Div, palette: Palette) -> Stateful
{ hoverable_with(id, element, palette.hover) @@ -379,15 +341,15 @@ impl Render for Tip { fn render(&mut self, _: &mut Window, cx: &mut Context) -> impl IntoElement { let palette = palette(cx); div() - .px(px(6.)) - .py(px(3.)) - .rounded(px(4.)) + .px(px(space::SM)) + .py(px(space::XS)) + .rounded(px(radius::SM)) .border_1() .border_color(palette.border) - .bg(palette.panel) + .bg(palette.field) .text_color(palette.text) .font_family(FONT) - .text_size(text(12.)) + .text_size(text(text::LABEL)) .child(self.0) } } @@ -411,9 +373,10 @@ pub fn primary_button( .id(id) .cursor_pointer() .on_click(move |_, window, cx| on_click(window, cx)) + .rounded_full() .bg(palette.accent) .text_color(palette.on_accent) - .hover(|style| style.opacity(0.85)) + .font_weight(FontWeight::SEMIBOLD) } #[derive(IntoElement)] @@ -451,11 +414,7 @@ pub fn rank_tag(rank: Option, palette: Palette) -> Option
{ Some( div() - .px(px(5.)) - .py(px(1.)) - .rounded(px(4.)) - .bg(palette.hover) - .text_size(text(11.)) + .text_size(text(text::CAPTION)) .text_color(color) .child(rank.label()), ) @@ -475,13 +434,17 @@ pub fn presence_avatar( size: Pixels, palette: Palette, ) -> Div { - let dot = if size > px(20.) { px(10.) } else { px(8.) }; + let dot = if size > px(size::CHIP) { + px(space::SM + space::XXS) + } else { + px(space::SM) + }; div().relative().flex_shrink_0().child(avatar).child( div() .absolute() - .right(px(-2.)) - .bottom(px(-2.)) + .right(px(-space::XXS)) + .bottom(px(-space::XXS)) .size(dot) .rounded_full() .border_2() @@ -539,12 +502,12 @@ fn connection_notice(connection: &Connection, palette: Palette) -> Option
{ }; Some( div() - .h(px(22.)) + .h(px(size::CHIP)) .flex() .items_center() .justify_center() - .gap(px(6.)) - .text_size(text(11.)) + .gap(px(space::SM)) + .text_size(text(text::CAPTION)) .text_color(color) .child(Spinner::new().xsmall().color(color)) .child(label), @@ -1263,7 +1226,7 @@ pub fn input_dialog( div() .flex() .flex_col() - .gap(px(12.)) + .gap(px(space::MD)) .child(Input::new(&dialog_input)) .child( div().flex().justify_end().child( @@ -1271,11 +1234,10 @@ pub fn input_dialog( let text = button_input.read(cx).text().to_string(); entity.update(cx, |this, cx| on_submit(this, text, window, cx)); }) - .h(px(30.)) - .px(px(14.)) + .h(px(size::CONTROL_SM + space::XS)) + .px(px(space::LG)) .flex() .items_center() - .rounded(px(8.)) .child(action), ), ), @@ -1338,7 +1300,7 @@ impl Render for Yumush { .size_full() .bg(palette.window) .text_color(palette.text) - .text_size(text(13.)) + .text_size(text(text::UI)) .track_focus(&self.focus) .on_action( cx.listener(|this, _: &FocusFind, window, cx| this.chat.focus_find(window, cx)), diff --git a/crates/client/src/gui/parts.rs b/crates/client/src/gui/parts.rs index 943c9b4..9c201c2 100644 --- a/crates/client/src/gui/parts.rs +++ b/crates/client/src/gui/parts.rs @@ -1,4 +1,4 @@ -use std::collections::VecDeque; +use std::{collections::VecDeque, time::Duration}; use gpui_kit::{ prelude::FluentBuilder, @@ -365,3 +365,31 @@ fn sample(levels: &[f32], along: f32) -> f32 { pub fn spark(values: Vec, slots: usize, color: Hsla) -> AnyElement { super::wave::line_of(values, slots, color).into_any_element() } + +const MOTION_TRAVEL: f32 = 6.; + +pub fn motion() -> gpui_kit::Animation { + gpui_kit::Animation::new(Duration::from_millis(160)).with_easing(gpui_kit::ease_out_quint()) +} + +pub fn pop_in( + id: impl Into, + element: E, + anchor: gpui_kit::Anchor, +) -> gpui_kit::AnimationElement { + let travel = if anchor.is_bottom() { MOTION_TRAVEL } else { -MOTION_TRAVEL }; + gpui_kit::AnimationExt::with_animation(element, id, motion(), move |element, delta| { + element.top(px(travel * (1. - delta))).opacity(delta) + }) +} + +pub fn swap_in( + id: impl Into, + element: E, + forward: bool, +) -> gpui_kit::AnimationElement { + let travel = if forward { MOTION_TRAVEL } else { -MOTION_TRAVEL }; + gpui_kit::AnimationExt::with_animation(element, id, motion(), move |element, delta| { + element.left(px(travel * (1. - delta))).opacity(delta) + }) +} diff --git a/crates/client/src/gui/style.rs b/crates/client/src/gui/style.rs index 77e4630..ac35181 100644 --- a/crates/client/src/gui/style.rs +++ b/crates/client/src/gui/style.rs @@ -125,8 +125,7 @@ mod tests { assert_eq!(names, HUE_NAMES); } - const UNMIGRATED: [&str; 36] = [ - "gui.rs", + const UNMIGRATED: [&str; 34] = [ "gui/auth.rs", "gui/builder.rs", "gui/builder/access.rs", @@ -161,7 +160,6 @@ mod tests { "gui/voice_settings.rs", "gui/voice_stats.rs", "gui/wave.rs", - "gui/widget.rs", ]; const FREE: [&str; 2] = ["gui/style.rs", "gui/parts.rs"]; @@ -179,10 +177,10 @@ mod tests { fn raw(line: &str) -> Option<&'static str> { let literal = |pattern: &str| { line.match_indices(pattern).any(|(at, _)| { - line[at + pattern.len()..] - .chars() - .next() - .is_some_and(|next| next.is_ascii_digit()) + let rest = &line[at + pattern.len()..]; + rest.chars().next().is_some_and(|next| next.is_ascii_digit()) + && !rest.starts_with("0.)") + && !rest.starts_with("0.0)") }) }; [ diff --git a/crates/client/src/gui/widget.rs b/crates/client/src/gui/widget.rs index 3884645..5a2214c 100644 --- a/crates/client/src/gui/widget.rs +++ b/crates/client/src/gui/widget.rs @@ -8,7 +8,10 @@ use gpui_kit::{ div, px, }; -use super::{Palette, Tooltip as _, Yumush, clickable, notify_error}; +use super::{ + Palette, Tooltip as _, Yumush, clickable, notify_error, + style::{radius, size, space}, +}; pub(super) fn icon_button( id: impl Into, @@ -19,22 +22,18 @@ pub(super) fn icon_button( ) -> Stateful
{ clickable(id, palette, on_click) .tip(tip) - .size(px(26.)) + .size(px(size::CONTROL_SM)) .flex_shrink_0() .flex() .items_center() .justify_center() - .rounded(px(6.)) + .rounded_full() .text_color(palette.muted) - .child(Icon::new(icon).w(px(14.)).h(px(14.))) + .child(Icon::new(icon).size(px(size::ICON_SM))) } pub(super) fn panel(palette: Palette) -> Div { - div() - .rounded(px(8.)) - .border_1() - .border_color(palette.border) - .bg(palette.panel) + div().rounded(px(radius::LG)).bg(palette.field) } pub(super) fn field(palette: Palette, input: &Entity) -> Div { @@ -43,14 +42,11 @@ pub(super) fn field(palette: Palette, input: &Entity) -> Div { pub(super) fn compact_frame(palette: Palette) -> Div { div() - .h(px(30.)) - .px(px(10.)) + .h(px(size::CONTROL_SM + space::XS)) .flex() .items_center() - .rounded(px(8.)) - .border_1() + .border_b_1() .border_color(palette.border) - .bg(palette.field) } pub(super) fn compact_field(palette: Palette, input: &Entity) -> Div { @@ -59,13 +55,11 @@ pub(super) fn compact_field(palette: Palette, input: &Entity) -> Div pub(super) fn frame(palette: Palette, input: Input) -> Div { div() - .h(px(32.)) + .h(px(size::CONTROL)) .flex() .items_center() - .rounded(px(8.)) - .border_1() + .border_b_1() .border_color(palette.border) - .bg(palette.field) .child(bare_input(palette, input)) }