styled_ext.rs

 1use gpui::{Div, Styled};
 2
 3use crate::UITextSize;
 4
 5/// Extends [`Styled`](gpui::Styled) with Zed specific styling methods.
 6pub trait StyledExt {
 7    fn text_ui_size(self, size: UITextSize) -> Self;
 8    fn text_ui(self) -> Self;
 9    fn text_ui_sm(self) -> Self;
10}
11
12impl<V: 'static> StyledExt for Div<V> {
13    fn text_ui_size(self, size: UITextSize) -> Self {
14        let size = size.rems();
15
16        self.text_size(size)
17    }
18    /// The default size for UI text.
19    ///
20    /// `0.825rem` or `14px` at the default scale of `1rem` = `16px`.
21    ///
22    /// Note: The absolute size of this text will change based on a user's `ui_scale` setting.
23    ///
24    /// Use [`text_ui_sm`] for regular-sized text.
25    fn text_ui(self) -> Self {
26        let size = UITextSize::default().rems();
27
28        self.text_size(size)
29    }
30    /// The small size for UI text.
31    ///
32    /// `0.75rem` or `12px` at the default scale of `1rem` = `16px`.
33    ///
34    /// Note: The absolute size of this text will change based on a user's `ui_scale` setting.
35    ///
36    /// Use [`text_ui`] for regular-sized text.
37    fn text_ui_sm(self) -> Self {
38        let size = UITextSize::Small.rems();
39
40        self.text_size(size)
41    }
42}