1use crate::{
2 self as gpui2, relative, rems, AlignItems, Display, Fill, FlexDirection, Hsla, JustifyContent,
3 Length, Position, SharedString, Style, Styled,
4};
5
6pub trait StyleHelpers: Styled<Style = Style> {
7 gpui3_macros::style_helpers!();
8
9 fn h(mut self, height: Length) -> Self
10 where
11 Self: Sized,
12 {
13 self.declared_style().size.height = Some(height);
14 self
15 }
16
17 /// size_{n}: Sets width & height to {n}
18 ///
19 /// Example:
20 /// size_1: Sets width & height to 1
21 fn size(mut self, size: Length) -> Self
22 where
23 Self: Sized,
24 {
25 self.declared_style().size.height = Some(size);
26 self.declared_style().size.width = Some(size);
27 self
28 }
29
30 fn full(mut self) -> Self
31 where
32 Self: Sized,
33 {
34 self.declared_style().size.width = Some(relative(1.).into());
35 self.declared_style().size.height = Some(relative(1.).into());
36 self
37 }
38
39 fn relative(mut self) -> Self
40 where
41 Self: Sized,
42 {
43 self.declared_style().position = Some(Position::Relative);
44 self
45 }
46
47 fn absolute(mut self) -> Self
48 where
49 Self: Sized,
50 {
51 self.declared_style().position = Some(Position::Absolute);
52 self
53 }
54
55 fn block(mut self) -> Self
56 where
57 Self: Sized,
58 {
59 self.declared_style().display = Some(Display::Block);
60 self
61 }
62
63 fn flex(mut self) -> Self
64 where
65 Self: Sized,
66 {
67 self.declared_style().display = Some(Display::Flex);
68 self
69 }
70
71 fn flex_col(mut self) -> Self
72 where
73 Self: Sized,
74 {
75 self.declared_style().flex_direction = Some(FlexDirection::Column);
76 self
77 }
78
79 fn flex_row(mut self) -> Self
80 where
81 Self: Sized,
82 {
83 self.declared_style().flex_direction = Some(FlexDirection::Row);
84 self
85 }
86
87 fn flex_1(mut self) -> Self
88 where
89 Self: Sized,
90 {
91 self.declared_style().flex_grow = Some(1.);
92 self.declared_style().flex_shrink = Some(1.);
93 self.declared_style().flex_basis = Some(relative(0.).into());
94 self
95 }
96
97 fn flex_auto(mut self) -> Self
98 where
99 Self: Sized,
100 {
101 self.declared_style().flex_grow = Some(1.);
102 self.declared_style().flex_shrink = Some(1.);
103 self.declared_style().flex_basis = Some(Length::Auto);
104 self
105 }
106
107 fn flex_initial(mut self) -> Self
108 where
109 Self: Sized,
110 {
111 self.declared_style().flex_grow = Some(0.);
112 self.declared_style().flex_shrink = Some(1.);
113 self.declared_style().flex_basis = Some(Length::Auto);
114 self
115 }
116
117 fn flex_none(mut self) -> Self
118 where
119 Self: Sized,
120 {
121 self.declared_style().flex_grow = Some(0.);
122 self.declared_style().flex_shrink = Some(0.);
123 self
124 }
125
126 fn grow(mut self) -> Self
127 where
128 Self: Sized,
129 {
130 self.declared_style().flex_grow = Some(1.);
131 self
132 }
133
134 fn items_start(mut self) -> Self
135 where
136 Self: Sized,
137 {
138 self.declared_style().align_items = Some(AlignItems::FlexStart);
139 self
140 }
141
142 fn items_end(mut self) -> Self
143 where
144 Self: Sized,
145 {
146 self.declared_style().align_items = Some(AlignItems::FlexEnd);
147 self
148 }
149
150 fn items_center(mut self) -> Self
151 where
152 Self: Sized,
153 {
154 self.declared_style().align_items = Some(AlignItems::Center);
155 self
156 }
157
158 fn justify_between(mut self) -> Self
159 where
160 Self: Sized,
161 {
162 self.declared_style().justify_content = Some(JustifyContent::SpaceBetween);
163 self
164 }
165
166 fn justify_center(mut self) -> Self
167 where
168 Self: Sized,
169 {
170 self.declared_style().justify_content = Some(JustifyContent::Center);
171 self
172 }
173
174 fn justify_start(mut self) -> Self
175 where
176 Self: Sized,
177 {
178 self.declared_style().justify_content = Some(JustifyContent::Start);
179 self
180 }
181
182 fn justify_end(mut self) -> Self
183 where
184 Self: Sized,
185 {
186 self.declared_style().justify_content = Some(JustifyContent::End);
187 self
188 }
189
190 fn justify_around(mut self) -> Self
191 where
192 Self: Sized,
193 {
194 self.declared_style().justify_content = Some(JustifyContent::SpaceAround);
195 self
196 }
197
198 fn fill<F>(mut self, fill: F) -> Self
199 where
200 F: Into<Fill>,
201 Self: Sized,
202 {
203 self.declared_style().fill = Some(fill.into());
204 self
205 }
206
207 fn border_color<C>(mut self, border_color: C) -> Self
208 where
209 C: Into<Hsla>,
210 Self: Sized,
211 {
212 self.declared_style().border_color = Some(border_color.into());
213 self
214 }
215
216 fn text_color<C>(mut self, color: C) -> Self
217 where
218 C: Into<Hsla>,
219 Self: Sized,
220 {
221 self.declared_style().text_color = Some(color.into());
222 self
223 }
224
225 fn text_xs(mut self) -> Self
226 where
227 Self: Sized,
228 {
229 self.declared_style().font_size = Some(rems(0.75));
230 self
231 }
232
233 fn text_sm(mut self) -> Self
234 where
235 Self: Sized,
236 {
237 self.declared_style().font_size = Some(rems(0.875));
238 self
239 }
240
241 fn text_base(mut self) -> Self
242 where
243 Self: Sized,
244 {
245 self.declared_style().font_size = Some(rems(1.0));
246 self
247 }
248
249 fn text_lg(mut self) -> Self
250 where
251 Self: Sized,
252 {
253 self.declared_style().font_size = Some(rems(1.125));
254 self
255 }
256
257 fn text_xl(mut self) -> Self
258 where
259 Self: Sized,
260 {
261 self.declared_style().font_size = Some(rems(1.25));
262 self
263 }
264
265 fn text_2xl(mut self) -> Self
266 where
267 Self: Sized,
268 {
269 self.declared_style().font_size = Some(rems(1.5));
270 self
271 }
272
273 fn text_3xl(mut self) -> Self
274 where
275 Self: Sized,
276 {
277 self.declared_style().font_size = Some(rems(1.875));
278 self
279 }
280
281 fn font(mut self, family_name: impl Into<SharedString>) -> Self
282 where
283 Self: Sized,
284 {
285 self.declared_style().font_family = Some(family_name.into());
286 self
287 }
288}