1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//! Shared styling helpers: sizes and `className`-style overrides.
use gpui::{Refineable, StyleRefinement, Styled};
/// Control size, shared by buttons, inputs, badges and toggles.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub enum ComponentSize {
/// Compact.
Small,
/// The default size.
#[default]
Medium,
/// Roomy.
Large,
}
/// Apply caller-supplied style overrides on top of a component's own styles,
/// the way `className` merges into a shadcn/ui component through `cn()`.
pub trait ApplyStyleOverrides: Styled + Sized {
/// Apply `.w_full()`-style overrides collected by a component's `Styled` impl.
#[must_use]
fn apply_style_overrides(mut self, style_overrides: &StyleRefinement) -> Self {
self.style().refine(style_overrides);
self
}
}
impl<Element: Styled> ApplyStyleOverrides for Element {}
/// Implement [`Styled`] (and `.sx(..)`) for a component that stores
/// `style_overrides: StyleRefinement` and `sx: Sx` fields, so callers can chain
/// `.w_full()`, `.mt_4()` and the rest of the GPUI style API, or pass `styles!` styles.
#[macro_export]
macro_rules! implement_style_overrides {
($component:ty) => {
impl $crate::gpui::Styled for $component {
fn style(&mut self) -> &mut $crate::gpui::StyleRefinement {
&mut self.style_overrides
}
}
// StyleX-style `.sx(..)` overrides, stored in the component's `sx`
// field and applied last in its render.
impl $crate::sx::SxStyled for $component {
fn apply_sx(mut self, sx: $crate::sx::Sx) -> Self {
self.sx.merge(&sx);
self
}
}
};
}