forge
Explore
Log in

Don't you dare go Hollow

Shared helpers on tokens (tooltips, primary pill, underline fields, bare icon buttons, rank as text)

Browse files at this commit

6874b35cbb49ee29db67829ad54db49cdba0b160Ahmet Kaan GümüşParent: cf9648d
  • refactor
    • shared helpers on tokens (tooltips, primary pill, underline fields, bare icon buttons, rank as text)
    • motion moves to parts
    • more size tokens
Show full message
♻️ refactor: shared helpers on tokens (tooltips, primary pill, underline fields, bare icon buttons, rank as text); motion moves to parts; more size tokens
crates/client/design/tokens.tomlmodified+10 -0
@@ -29,6 +29,7 @@ bad = "#b33b2a"
2929 hue = ["#9c520c", "#11638d", "#7a43c9", "#1a6e41", "#b8325f", "#765b00", "#b33b2a", "#0a6c67", "#5a54c4", "#151726"]
3030
3131 [space]
32+xxs = 2
3233 xs = 4
3334 sm = 8
3435 md = 12
@@ -57,10 +58,19 @@ display = 28
5758 text = 1.4
5859
5960 [size]
61+icon_sm = 14
6062 icon = 18
63+chip = 22
64+control_sm = 26
6165 control = 34
6266 row = 44
6367 avatar = 26
68+avatar_lg = 64
69+thumb = 120
6470 sidebar = 230
6571 talk = 300
6672 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::{
33 collections::HashMap,
44 fmt::Display,
55 sync::Arc,
6- time::{Duration, Instant},
6+ time::Instant,
77 };
88
99 use common::{
@@ -17,7 +17,7 @@ use common::{
1717 },
1818 };
1919 use gpui_kit::{
20- Anchor, Animation, AnimationElement, AnimationExt, AnyElement, AnyWindowHandle, App,
20+ AnyElement, AnyWindowHandle, App,
2121 AppContext, AsyncWindowContext, Context, Div, ElementId, Entity, FontWeight, Hsla, Image,
2222 ImageFormat, InteractiveElement, IntoElement, KeyBinding, KeyDownEvent, KeyUpEvent,
2323 ModifiersChangedEvent, ParentElement, Pixels, Rems, Render, RenderOnce, Stateful,
@@ -29,7 +29,7 @@ use gpui_kit::{
2929 notification::Notification,
3030 spinner::Spinner,
3131 },
32- div, ease_out_quint, img, px, rems,
32+ div, img, px, rems,
3333 };
3434 use jiff::{Timestamp, tz::TimeZone};
3535 use tokio::sync::mpsc;
@@ -71,16 +71,14 @@ mod wave;
7171 mod widget;
7272
7373 use auth::Auth;
74-use style::Tokens;
74+use style::{Tokens, radius, size, space, text};
7575 use chat::{Chat, View};
7676 use voice_settings::VoiceControls;
7777
7878 actions!(yumush, [FocusFind, CloseSettings]);
7979
80-pub const BASE_FONT: f32 = 14.;
81-
8280 pub fn text(size: f32) -> Rems {
83- rems(size / BASE_FONT)
81+ rems(size / text::UI)
8482 }
8583
8684 #[derive(Clone, Copy)]
@@ -186,15 +184,15 @@ pub fn sync_theme(cx: &mut App) {
186184 colors.secondary = palette.field;
187185 colors.secondary_foreground = palette.text;
188186 colors.primary = palette.accent;
189- colors.primary_hover = palette.accent.opacity(0.85);
187+ colors.primary_hover = palette.accent;
190188 colors.primary_active = palette.accent;
191189 colors.primary_foreground = palette.on_accent;
192190 colors.ring = palette.accent;
193191 colors.caret = palette.accent;
194192 colors.danger = palette.danger;
195193 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);
198196 theme.font_size = font_size;
199197 theme.focus_ring = false;
200198 }
@@ -264,13 +262,13 @@ pub fn community_icon(
264262 Some(image) => div()
265263 .size(size)
266264 .flex_shrink_0()
267- .rounded(px(4.))
265+ .rounded(px(radius::SM))
268266 .overflow_hidden()
269267 .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)),
271269 },
272270 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)),
274272 }
275273 }
276274
@@ -307,43 +305,7 @@ pub fn millis_time(millis: u64, format: &str) -> String {
307305 .to_string()
308306 }
309307
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};
347309
348310 pub fn hoverable(id: impl Into<ElementId>, element: Div, palette: Palette) -> Stateful<Div> {
349311 hoverable_with(id, element, palette.hover)
@@ -379,15 +341,15 @@ impl Render for Tip {
379341 fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
380342 let palette = palette(cx);
381343 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))
385347 .border_1()
386348 .border_color(palette.border)
387- .bg(palette.panel)
349+ .bg(palette.field)
388350 .text_color(palette.text)
389351 .font_family(FONT)
390- .text_size(text(12.))
352+ .text_size(text(text::LABEL))
391353 .child(self.0)
392354 }
393355 }
@@ -411,9 +373,10 @@ pub fn primary_button(
411373 .id(id)
412374 .cursor_pointer()
413375 .on_click(move |_, window, cx| on_click(window, cx))
376+ .rounded_full()
414377 .bg(palette.accent)
415378 .text_color(palette.on_accent)
416- .hover(|style| style.opacity(0.85))
379+ .font_weight(FontWeight::SEMIBOLD)
417380 }
418381
419382 #[derive(IntoElement)]
@@ -451,11 +414,7 @@ pub fn rank_tag(rank: Option<Rank>, palette: Palette) -> Option<Div> {
451414
452415 Some(
453416 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))
459418 .text_color(color)
460419 .child(rank.label()),
461420 )
@@ -475,13 +434,17 @@ pub fn presence_avatar(
475434 size: Pixels,
476435 palette: Palette,
477436 ) -> 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+ };
479442
480443 div().relative().flex_shrink_0().child(avatar).child(
481444 div()
482445 .absolute()
483- .right(px(-2.))
484- .bottom(px(-2.))
446+ .right(px(-space::XXS))
447+ .bottom(px(-space::XXS))
485448 .size(dot)
486449 .rounded_full()
487450 .border_2()
@@ -539,12 +502,12 @@ fn connection_notice(connection: &Connection, palette: Palette) -> Option<Div> {
539502 };
540503 Some(
541504 div()
542- .h(px(22.))
505+ .h(px(size::CHIP))
543506 .flex()
544507 .items_center()
545508 .justify_center()
546- .gap(px(6.))
547- .text_size(text(11.))
509+ .gap(px(space::SM))
510+ .text_size(text(text::CAPTION))
548511 .text_color(color)
549512 .child(Spinner::new().xsmall().color(color))
550513 .child(label),
@@ -1263,7 +1226,7 @@ pub fn input_dialog(
12631226 div()
12641227 .flex()
12651228 .flex_col()
1266- .gap(px(12.))
1229+ .gap(px(space::MD))
12671230 .child(Input::new(&dialog_input))
12681231 .child(
12691232 div().flex().justify_end().child(
@@ -1271,11 +1234,10 @@ pub fn input_dialog(
12711234 let text = button_input.read(cx).text().to_string();
12721235 entity.update(cx, |this, cx| on_submit(this, text, window, cx));
12731236 })
1274- .h(px(30.))
1275- .px(px(14.))
1237+ .h(px(size::CONTROL_SM + space::XS))
1238+ .px(px(space::LG))
12761239 .flex()
12771240 .items_center()
1278- .rounded(px(8.))
12791241 .child(action),
12801242 ),
12811243 ),
@@ -1338,7 +1300,7 @@ impl Render for Yumush {
13381300 .size_full()
13391301 .bg(palette.window)
13401302 .text_color(palette.text)
1341- .text_size(text(13.))
1303+ .text_size(text(text::UI))
13421304 .track_focus(&self.focus)
13431305 .on_action(
13441306 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};
22
33 use gpui_kit::{
44 prelude::FluentBuilder,
@@ -365,3 +365,31 @@ fn sample(levels: &[f32], along: f32) -> f32 {
365365 pub fn spark(values: Vec<f32>, slots: usize, color: Hsla) -> AnyElement {
366366 super::wave::line_of(values, slots, color).into_any_element()
367367 }
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 {
125125 assert_eq!(names, HUE_NAMES);
126126 }
127127
128- const UNMIGRATED: [&str; 36] = [
129- "gui.rs",
128+ const UNMIGRATED: [&str; 34] = [
130129 "gui/auth.rs",
131130 "gui/builder.rs",
132131 "gui/builder/access.rs",
@@ -161,7 +160,6 @@ mod tests {
161160 "gui/voice_settings.rs",
162161 "gui/voice_stats.rs",
163162 "gui/wave.rs",
164- "gui/widget.rs",
165163 ];
166164 const FREE: [&str; 2] = ["gui/style.rs", "gui/parts.rs"];
167165
@@ -179,10 +177,10 @@ mod tests {
179177 fn raw(line: &str) -> Option<&'static str> {
180178 let literal = |pattern: &str| {
181179 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)")
186184 })
187185 };
188186 [
crates/client/src/gui/widget.rsmodified+12 -18
@@ -8,7 +8,10 @@ use gpui_kit::{
88 div, px,
99 };
1010
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+};
1215
1316 pub(super) fn icon_button(
1417 id: impl Into<ElementId>,
@@ -19,22 +22,18 @@ pub(super) fn icon_button(
1922 ) -> Stateful<Div> {
2023 clickable(id, palette, on_click)
2124 .tip(tip)
22- .size(px(26.))
25+ .size(px(size::CONTROL_SM))
2326 .flex_shrink_0()
2427 .flex()
2528 .items_center()
2629 .justify_center()
27- .rounded(px(6.))
30+ .rounded_full()
2831 .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)))
3033 }
3134
3235 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)
3837 }
3938
4039 pub(super) fn field(palette: Palette, input: &Entity<InputState>) -> Div {
@@ -43,14 +42,11 @@ pub(super) fn field(palette: Palette, input: &Entity<InputState>) -> Div {
4342
4443 pub(super) fn compact_frame(palette: Palette) -> Div {
4544 div()
46- .h(px(30.))
47- .px(px(10.))
45+ .h(px(size::CONTROL_SM + space::XS))
4846 .flex()
4947 .items_center()
50- .rounded(px(8.))
51- .border_1()
48+ .border_b_1()
5249 .border_color(palette.border)
53- .bg(palette.field)
5450 }
5551
5652 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
5955
6056 pub(super) fn frame(palette: Palette, input: Input) -> Div {
6157 div()
62- .h(px(32.))
58+ .h(px(size::CONTROL))
6359 .flex()
6460 .items_center()
65- .rounded(px(8.))
66- .border_1()
61+ .border_b_1()
6762 .border_color(palette.border)
68- .bg(palette.field)
6963 .child(bare_input(palette, input))
7064 }
7165