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