1use gpui::{Div, ElementFocus, ElementInteractivity, Styled};
2
3use crate::UITextSize;
4
5/// Extends [`Styled`](gpui::Styled) with Zed specific styling methods.
6pub trait StyledExt: Styled {
7 /// Horizontally stacks elements.
8 ///
9 /// Sets `flex()`, `flex_row()`, `items_center()`
10 fn h_flex(self) -> Self
11 where
12 Self: Sized,
13 {
14 self.flex().flex_row().items_center()
15 }
16
17 /// Vertically stacks elements.
18 ///
19 /// Sets `flex()`, `flex_col()`
20 fn v_flex(self) -> Self
21 where
22 Self: Sized,
23 {
24 self.flex().flex_col()
25 }
26
27 fn text_ui_size(self, size: UITextSize) -> Self
28 where
29 Self: Sized,
30 {
31 let size = size.rems();
32
33 self.text_size(size)
34 }
35
36 /// The default size for UI text.
37 ///
38 /// `0.825rem` or `14px` at the default scale of `1rem` = `16px`.
39 ///
40 /// Note: The absolute size of this text will change based on a user's `ui_scale` setting.
41 ///
42 /// Use [`text_ui_sm`] for regular-sized text.
43 fn text_ui(self) -> Self
44 where
45 Self: Sized,
46 {
47 let size = UITextSize::default().rems();
48
49 self.text_size(size)
50 }
51
52 /// The small size for UI text.
53 ///
54 /// `0.75rem` or `12px` at the default scale of `1rem` = `16px`.
55 ///
56 /// Note: The absolute size of this text will change based on a user's `ui_scale` setting.
57 ///
58 /// Use [`text_ui`] for regular-sized text.
59 fn text_ui_sm(self) -> Self
60 where
61 Self: Sized,
62 {
63 let size = UITextSize::Small.rems();
64
65 self.text_size(size)
66 }
67}
68
69impl<V, I, F> StyledExt for Div<V, I, F>
70where
71 I: ElementInteractivity<V>,
72 F: ElementFocus<V>,
73{
74}