Shared helpers on tokens (tooltips, primary pill, underline fields, bare icon buttons, rank as text)
Browse files at this commit6874b35cbb49ee29db67829ad54db49cdba0b160Parent: cf9648d- refactor
- shared helpers on tokens (tooltips, primary pill, underline fields, bare icon buttons, rank as text)
- motion moves to parts
- more size tokens
5 changed files +90 -98
- crates/client/design/tokens.toml +10 -0
- crates/client/src/gui.rs +34 -72
- crates/client/src/gui/parts.rs +29 -1
- crates/client/src/gui/style.rs +5 -7
- crates/client/src/gui/widget.rs +12 -18
crates/client/design/tokens.tomlmodified+10 -0
| @@ -29,6 +29,7 @@ bad = "#b33b2a" | ||
| 29 | 29 | hue = ["#9c520c", "#11638d", "#7a43c9", "#1a6e41", "#b8325f", "#765b00", "#b33b2a", "#0a6c67", "#5a54c4", "#151726"] |
| 30 | 30 | |
| 31 | 31 | [space] |
| 32 | +xxs = 2 | |
| 32 | 33 | xs = 4 |
| 33 | 34 | sm = 8 |
| 34 | 35 | md = 12 |
| @@ -57,10 +58,19 @@ display = 28 | ||
| 57 | 58 | text = 1.4 |
| 58 | 59 | |
| 59 | 60 | [size] |
| 61 | +icon_sm = 14 | |
| 60 | 62 | icon = 18 |
| 63 | +chip = 22 | |
| 64 | +control_sm = 26 | |
| 61 | 65 | control = 34 |
| 62 | 66 | row = 44 |
| 63 | 67 | avatar = 26 |
| 68 | +avatar_lg = 64 | |
| 69 | +thumb = 120 | |
| 64 | 70 | sidebar = 230 |
| 65 | 71 | talk = 300 |
| 66 | 72 | popover = 300 |
| 73 | +sheet = 380 | |
| 74 | +media = 400 | |
| 75 | +wide = 520 | |
| 76 | +page = 640 |
crates/client/src/gui.rsmodified+34 -72
| @@ -3,7 +3,7 @@ use std::{ | ||
| 3 | 3 | collections::HashMap, |
| 4 | 4 | fmt::Display, |
| 5 | 5 | sync::Arc, |
| 6 | - time::{Duration, Instant}, | |
| 6 | + time::Instant, | |
| 7 | 7 | }; |
| 8 | 8 | |
| 9 | 9 | use common::{ |
| @@ -17,7 +17,7 @@ use common::{ | ||
| 17 | 17 | }, |
| 18 | 18 | }; |
| 19 | 19 | use gpui_kit::{ |
| 20 | - Anchor, Animation, AnimationElement, AnimationExt, AnyElement, AnyWindowHandle, App, | |
| 20 | + AnyElement, AnyWindowHandle, App, | |
| 21 | 21 | AppContext, AsyncWindowContext, Context, Div, ElementId, Entity, FontWeight, Hsla, Image, |
| 22 | 22 | ImageFormat, InteractiveElement, IntoElement, KeyBinding, KeyDownEvent, KeyUpEvent, |
| 23 | 23 | ModifiersChangedEvent, ParentElement, Pixels, Rems, Render, RenderOnce, Stateful, |
| @@ -29,7 +29,7 @@ use gpui_kit::{ | ||
| 29 | 29 | notification::Notification, |
| 30 | 30 | spinner::Spinner, |
| 31 | 31 | }, |
| 32 | - div, ease_out_quint, img, px, rems, | |
| 32 | + div, img, px, rems, | |
| 33 | 33 | }; |
| 34 | 34 | use jiff::{Timestamp, tz::TimeZone}; |
| 35 | 35 | use tokio::sync::mpsc; |
| @@ -71,16 +71,14 @@ mod wave; | ||
| 71 | 71 | mod widget; |
| 72 | 72 | |
| 73 | 73 | use auth::Auth; |
| 74 | -use style::Tokens; | |
| 74 | +use style::{Tokens, radius, size, space, text}; | |
| 75 | 75 | use chat::{Chat, View}; |
| 76 | 76 | use voice_settings::VoiceControls; |
| 77 | 77 | |
| 78 | 78 | actions!(yumush, [FocusFind, CloseSettings]); |
| 79 | 79 | |
| 80 | -pub const BASE_FONT: f32 = 14.; | |
| 81 | - | |
| 82 | 80 | pub fn text(size: f32) -> Rems { |
| 83 | - rems(size / BASE_FONT) | |
| 81 | + rems(size / text::UI) | |
| 84 | 82 | } |
| 85 | 83 | |
| 86 | 84 | #[derive(Clone, Copy)] |
| @@ -186,15 +184,15 @@ pub fn sync_theme(cx: &mut App) { | ||
| 186 | 184 | colors.secondary = palette.field; |
| 187 | 185 | colors.secondary_foreground = palette.text; |
| 188 | 186 | colors.primary = palette.accent; |
| 189 | - colors.primary_hover = palette.accent.opacity(0.85); | |
| 187 | + colors.primary_hover = palette.accent; | |
| 190 | 188 | colors.primary_active = palette.accent; |
| 191 | 189 | colors.primary_foreground = palette.on_accent; |
| 192 | 190 | colors.ring = palette.accent; |
| 193 | 191 | colors.caret = palette.accent; |
| 194 | 192 | colors.danger = palette.danger; |
| 195 | 193 | theme.tokens = (&theme.colors).into(); |
| 196 | - theme.radius = px(6.); | |
| 197 | - theme.radius_lg = px(10.); | |
| 194 | + theme.radius = px(radius::SM); | |
| 195 | + theme.radius_lg = px(radius::LG); | |
| 198 | 196 | theme.font_size = font_size; |
| 199 | 197 | theme.focus_ring = false; |
| 200 | 198 | } |
| @@ -264,13 +262,13 @@ pub fn community_icon( | ||
| 264 | 262 | Some(image) => div() |
| 265 | 263 | .size(size) |
| 266 | 264 | .flex_shrink_0() |
| 267 | - .rounded(px(4.)) | |
| 265 | + .rounded(px(radius::SM)) | |
| 268 | 266 | .overflow_hidden() |
| 269 | 267 | .child(img(image.clone()).size_full()), |
| 270 | - None => badge(palette, community.id, &community.name, size, font).rounded(px(4.)), | |
| 268 | + None => badge(palette, community.id, &community.name, size, font).rounded(px(radius::SM)), | |
| 271 | 269 | }, |
| 272 | 270 | CommunityKind::Direct { peer } => avatar(palette, peer, size, font, avatars), |
| 273 | - CommunityKind::Notes => badge(palette, community.id, "Notes", size, font).rounded(px(4.)), | |
| 271 | + CommunityKind::Notes => badge(palette, community.id, "Notes", size, font).rounded(px(radius::SM)), | |
| 274 | 272 | } |
| 275 | 273 | } |
| 276 | 274 | |
| @@ -307,43 +305,7 @@ pub fn millis_time(millis: u64, format: &str) -> String { | ||
| 307 | 305 | .to_string() |
| 308 | 306 | } |
| 309 | 307 | |
| 310 | -const MOTION_TRAVEL: f32 = 6.; | |
| 311 | - | |
| 312 | -pub fn motion() -> Animation { | |
| 313 | - Animation::new(Duration::from_millis(160)).with_easing(ease_out_quint()) | |
| 314 | -} | |
| 315 | - | |
| 316 | -pub fn pop_in<E: IntoElement + Styled + 'static>( | |
| 317 | - id: impl Into<ElementId>, | |
| 318 | - element: E, | |
| 319 | - anchor: Anchor, | |
| 320 | -) -> AnimationElement<E> { | |
| 321 | - let travel = if anchor.is_bottom() { | |
| 322 | - MOTION_TRAVEL | |
| 323 | - } else { | |
| 324 | - -MOTION_TRAVEL | |
| 325 | - }; | |
| 326 | - | |
| 327 | - element.with_animation(id, motion(), move |element, delta| { | |
| 328 | - element.top(px(travel * (1. - delta))).opacity(delta) | |
| 329 | - }) | |
| 330 | -} | |
| 331 | - | |
| 332 | -pub fn swap_in<E: IntoElement + Styled + 'static>( | |
| 333 | - id: impl Into<ElementId>, | |
| 334 | - element: E, | |
| 335 | - forward: bool, | |
| 336 | -) -> AnimationElement<E> { | |
| 337 | - let travel = if forward { | |
| 338 | - MOTION_TRAVEL | |
| 339 | - } else { | |
| 340 | - -MOTION_TRAVEL | |
| 341 | - }; | |
| 342 | - | |
| 343 | - element.with_animation(id, motion(), move |element, delta| { | |
| 344 | - element.left(px(travel * (1. - delta))).opacity(delta) | |
| 345 | - }) | |
| 346 | -} | |
| 308 | +pub use parts::{motion, pop_in, swap_in}; | |
| 347 | 309 | |
| 348 | 310 | pub fn hoverable(id: impl Into<ElementId>, element: Div, palette: Palette) -> Stateful<Div> { |
| 349 | 311 | hoverable_with(id, element, palette.hover) |
| @@ -379,15 +341,15 @@ impl Render for Tip { | ||
| 379 | 341 | fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { |
| 380 | 342 | let palette = palette(cx); |
| 381 | 343 | div() |
| 382 | - .px(px(6.)) | |
| 383 | - .py(px(3.)) | |
| 384 | - .rounded(px(4.)) | |
| 344 | + .px(px(space::SM)) | |
| 345 | + .py(px(space::XS)) | |
| 346 | + .rounded(px(radius::SM)) | |
| 385 | 347 | .border_1() |
| 386 | 348 | .border_color(palette.border) |
| 387 | - .bg(palette.panel) | |
| 349 | + .bg(palette.field) | |
| 388 | 350 | .text_color(palette.text) |
| 389 | 351 | .font_family(FONT) |
| 390 | - .text_size(text(12.)) | |
| 352 | + .text_size(text(text::LABEL)) | |
| 391 | 353 | .child(self.0) |
| 392 | 354 | } |
| 393 | 355 | } |
| @@ -411,9 +373,10 @@ pub fn primary_button( | ||
| 411 | 373 | .id(id) |
| 412 | 374 | .cursor_pointer() |
| 413 | 375 | .on_click(move |_, window, cx| on_click(window, cx)) |
| 376 | + .rounded_full() | |
| 414 | 377 | .bg(palette.accent) |
| 415 | 378 | .text_color(palette.on_accent) |
| 416 | - .hover(|style| style.opacity(0.85)) | |
| 379 | + .font_weight(FontWeight::SEMIBOLD) | |
| 417 | 380 | } |
| 418 | 381 | |
| 419 | 382 | #[derive(IntoElement)] |
| @@ -451,11 +414,7 @@ pub fn rank_tag(rank: Option<Rank>, palette: Palette) -> Option<Div> { | ||
| 451 | 414 | |
| 452 | 415 | Some( |
| 453 | 416 | div() |
| 454 | - .px(px(5.)) | |
| 455 | - .py(px(1.)) | |
| 456 | - .rounded(px(4.)) | |
| 457 | - .bg(palette.hover) | |
| 458 | - .text_size(text(11.)) | |
| 417 | + .text_size(text(text::CAPTION)) | |
| 459 | 418 | .text_color(color) |
| 460 | 419 | .child(rank.label()), |
| 461 | 420 | ) |
| @@ -475,13 +434,17 @@ pub fn presence_avatar( | ||
| 475 | 434 | size: Pixels, |
| 476 | 435 | palette: Palette, |
| 477 | 436 | ) -> Div { |
| 478 | - let dot = if size > px(20.) { px(10.) } else { px(8.) }; | |
| 437 | + let dot = if size > px(size::CHIP) { | |
| 438 | + px(space::SM + space::XXS) | |
| 439 | + } else { | |
| 440 | + px(space::SM) | |
| 441 | + }; | |
| 479 | 442 | |
| 480 | 443 | div().relative().flex_shrink_0().child(avatar).child( |
| 481 | 444 | div() |
| 482 | 445 | .absolute() |
| 483 | - .right(px(-2.)) | |
| 484 | - .bottom(px(-2.)) | |
| 446 | + .right(px(-space::XXS)) | |
| 447 | + .bottom(px(-space::XXS)) | |
| 485 | 448 | .size(dot) |
| 486 | 449 | .rounded_full() |
| 487 | 450 | .border_2() |
| @@ -539,12 +502,12 @@ fn connection_notice(connection: &Connection, palette: Palette) -> Option<Div> { | ||
| 539 | 502 | }; |
| 540 | 503 | Some( |
| 541 | 504 | div() |
| 542 | - .h(px(22.)) | |
| 505 | + .h(px(size::CHIP)) | |
| 543 | 506 | .flex() |
| 544 | 507 | .items_center() |
| 545 | 508 | .justify_center() |
| 546 | - .gap(px(6.)) | |
| 547 | - .text_size(text(11.)) | |
| 509 | + .gap(px(space::SM)) | |
| 510 | + .text_size(text(text::CAPTION)) | |
| 548 | 511 | .text_color(color) |
| 549 | 512 | .child(Spinner::new().xsmall().color(color)) |
| 550 | 513 | .child(label), |
| @@ -1263,7 +1226,7 @@ pub fn input_dialog( | ||
| 1263 | 1226 | div() |
| 1264 | 1227 | .flex() |
| 1265 | 1228 | .flex_col() |
| 1266 | - .gap(px(12.)) | |
| 1229 | + .gap(px(space::MD)) | |
| 1267 | 1230 | .child(Input::new(&dialog_input)) |
| 1268 | 1231 | .child( |
| 1269 | 1232 | div().flex().justify_end().child( |
| @@ -1271,11 +1234,10 @@ pub fn input_dialog( | ||
| 1271 | 1234 | let text = button_input.read(cx).text().to_string(); |
| 1272 | 1235 | entity.update(cx, |this, cx| on_submit(this, text, window, cx)); |
| 1273 | 1236 | }) |
| 1274 | - .h(px(30.)) | |
| 1275 | - .px(px(14.)) | |
| 1237 | + .h(px(size::CONTROL_SM + space::XS)) | |
| 1238 | + .px(px(space::LG)) | |
| 1276 | 1239 | .flex() |
| 1277 | 1240 | .items_center() |
| 1278 | - .rounded(px(8.)) | |
| 1279 | 1241 | .child(action), |
| 1280 | 1242 | ), |
| 1281 | 1243 | ), |
| @@ -1338,7 +1300,7 @@ impl Render for Yumush { | ||
| 1338 | 1300 | .size_full() |
| 1339 | 1301 | .bg(palette.window) |
| 1340 | 1302 | .text_color(palette.text) |
| 1341 | - .text_size(text(13.)) | |
| 1303 | + .text_size(text(text::UI)) | |
| 1342 | 1304 | .track_focus(&self.focus) |
| 1343 | 1305 | .on_action( |
| 1344 | 1306 | cx.listener(|this, _: &FocusFind, window, cx| this.chat.focus_find(window, cx)), |
crates/client/src/gui/parts.rsmodified+29 -1
| @@ -1,4 +1,4 @@ | ||
| 1 | -use std::collections::VecDeque; | |
| 1 | +use std::{collections::VecDeque, time::Duration}; | |
| 2 | 2 | |
| 3 | 3 | use gpui_kit::{ |
| 4 | 4 | prelude::FluentBuilder, |
| @@ -365,3 +365,31 @@ fn sample(levels: &[f32], along: f32) -> f32 { | ||
| 365 | 365 | pub fn spark(values: Vec<f32>, slots: usize, color: Hsla) -> AnyElement { |
| 366 | 366 | super::wave::line_of(values, slots, color).into_any_element() |
| 367 | 367 | } |
| 368 | + | |
| 369 | +const MOTION_TRAVEL: f32 = 6.; | |
| 370 | + | |
| 371 | +pub fn motion() -> gpui_kit::Animation { | |
| 372 | + gpui_kit::Animation::new(Duration::from_millis(160)).with_easing(gpui_kit::ease_out_quint()) | |
| 373 | +} | |
| 374 | + | |
| 375 | +pub fn pop_in<E: IntoElement + Styled + 'static>( | |
| 376 | + id: impl Into<ElementId>, | |
| 377 | + element: E, | |
| 378 | + anchor: gpui_kit::Anchor, | |
| 379 | +) -> gpui_kit::AnimationElement<E> { | |
| 380 | + let travel = if anchor.is_bottom() { MOTION_TRAVEL } else { -MOTION_TRAVEL }; | |
| 381 | + gpui_kit::AnimationExt::with_animation(element, id, motion(), move |element, delta| { | |
| 382 | + element.top(px(travel * (1. - delta))).opacity(delta) | |
| 383 | + }) | |
| 384 | +} | |
| 385 | + | |
| 386 | +pub fn swap_in<E: IntoElement + Styled + 'static>( | |
| 387 | + id: impl Into<ElementId>, | |
| 388 | + element: E, | |
| 389 | + forward: bool, | |
| 390 | +) -> gpui_kit::AnimationElement<E> { | |
| 391 | + let travel = if forward { MOTION_TRAVEL } else { -MOTION_TRAVEL }; | |
| 392 | + gpui_kit::AnimationExt::with_animation(element, id, motion(), move |element, delta| { | |
| 393 | + element.left(px(travel * (1. - delta))).opacity(delta) | |
| 394 | + }) | |
| 395 | +} |
crates/client/src/gui/style.rsmodified+5 -7
| @@ -125,8 +125,7 @@ mod tests { | ||
| 125 | 125 | assert_eq!(names, HUE_NAMES); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - const UNMIGRATED: [&str; 36] = [ | |
| 129 | - "gui.rs", | |
| 128 | + const UNMIGRATED: [&str; 34] = [ | |
| 130 | 129 | "gui/auth.rs", |
| 131 | 130 | "gui/builder.rs", |
| 132 | 131 | "gui/builder/access.rs", |
| @@ -161,7 +160,6 @@ mod tests { | ||
| 161 | 160 | "gui/voice_settings.rs", |
| 162 | 161 | "gui/voice_stats.rs", |
| 163 | 162 | "gui/wave.rs", |
| 164 | - "gui/widget.rs", | |
| 165 | 163 | ]; |
| 166 | 164 | const FREE: [&str; 2] = ["gui/style.rs", "gui/parts.rs"]; |
| 167 | 165 | |
| @@ -179,10 +177,10 @@ mod tests { | ||
| 179 | 177 | fn raw(line: &str) -> Option<&'static str> { |
| 180 | 178 | let literal = |pattern: &str| { |
| 181 | 179 | line.match_indices(pattern).any(|(at, _)| { |
| 182 | - line[at + pattern.len()..] | |
| 183 | - .chars() | |
| 184 | - .next() | |
| 185 | - .is_some_and(|next| next.is_ascii_digit()) | |
| 180 | + let rest = &line[at + pattern.len()..]; | |
| 181 | + rest.chars().next().is_some_and(|next| next.is_ascii_digit()) | |
| 182 | + && !rest.starts_with("0.)") | |
| 183 | + && !rest.starts_with("0.0)") | |
| 186 | 184 | }) |
| 187 | 185 | }; |
| 188 | 186 | [ |
crates/client/src/gui/widget.rsmodified+12 -18
| @@ -8,7 +8,10 @@ use gpui_kit::{ | ||
| 8 | 8 | div, px, |
| 9 | 9 | }; |
| 10 | 10 | |
| 11 | -use super::{Palette, Tooltip as _, Yumush, clickable, notify_error}; | |
| 11 | +use super::{ | |
| 12 | + Palette, Tooltip as _, Yumush, clickable, notify_error, | |
| 13 | + style::{radius, size, space}, | |
| 14 | +}; | |
| 12 | 15 | |
| 13 | 16 | pub(super) fn icon_button( |
| 14 | 17 | id: impl Into<ElementId>, |
| @@ -19,22 +22,18 @@ pub(super) fn icon_button( | ||
| 19 | 22 | ) -> Stateful<Div> { |
| 20 | 23 | clickable(id, palette, on_click) |
| 21 | 24 | .tip(tip) |
| 22 | - .size(px(26.)) | |
| 25 | + .size(px(size::CONTROL_SM)) | |
| 23 | 26 | .flex_shrink_0() |
| 24 | 27 | .flex() |
| 25 | 28 | .items_center() |
| 26 | 29 | .justify_center() |
| 27 | - .rounded(px(6.)) | |
| 30 | + .rounded_full() | |
| 28 | 31 | .text_color(palette.muted) |
| 29 | - .child(Icon::new(icon).w(px(14.)).h(px(14.))) | |
| 32 | + .child(Icon::new(icon).size(px(size::ICON_SM))) | |
| 30 | 33 | } |
| 31 | 34 | |
| 32 | 35 | pub(super) fn panel(palette: Palette) -> Div { |
| 33 | - div() | |
| 34 | - .rounded(px(8.)) | |
| 35 | - .border_1() | |
| 36 | - .border_color(palette.border) | |
| 37 | - .bg(palette.panel) | |
| 36 | + div().rounded(px(radius::LG)).bg(palette.field) | |
| 38 | 37 | } |
| 39 | 38 | |
| 40 | 39 | pub(super) fn field(palette: Palette, input: &Entity<InputState>) -> Div { |
| @@ -43,14 +42,11 @@ pub(super) fn field(palette: Palette, input: &Entity<InputState>) -> Div { | ||
| 43 | 42 | |
| 44 | 43 | pub(super) fn compact_frame(palette: Palette) -> Div { |
| 45 | 44 | div() |
| 46 | - .h(px(30.)) | |
| 47 | - .px(px(10.)) | |
| 45 | + .h(px(size::CONTROL_SM + space::XS)) | |
| 48 | 46 | .flex() |
| 49 | 47 | .items_center() |
| 50 | - .rounded(px(8.)) | |
| 51 | - .border_1() | |
| 48 | + .border_b_1() | |
| 52 | 49 | .border_color(palette.border) |
| 53 | - .bg(palette.field) | |
| 54 | 50 | } |
| 55 | 51 | |
| 56 | 52 | pub(super) fn compact_field(palette: Palette, input: &Entity<InputState>) -> Div { |
| @@ -59,13 +55,11 @@ pub(super) fn compact_field(palette: Palette, input: &Entity<InputState>) -> Div | ||
| 59 | 55 | |
| 60 | 56 | pub(super) fn frame(palette: Palette, input: Input) -> Div { |
| 61 | 57 | div() |
| 62 | - .h(px(32.)) | |
| 58 | + .h(px(size::CONTROL)) | |
| 63 | 59 | .flex() |
| 64 | 60 | .items_center() |
| 65 | - .rounded(px(8.)) | |
| 66 | - .border_1() | |
| 61 | + .border_b_1() | |
| 67 | 62 | .border_color(palette.border) |
| 68 | - .bg(palette.field) | |
| 69 | 63 | .child(bare_input(palette, input)) |
| 70 | 64 | } |
| 71 | 65 |