Skip to main content

gpui/
styled.rs

1use crate::{
2    self as gpui, AbsoluteLength, AlignContent, AlignItems, BlendMode, BorderStyle, CursorStyle,
3    DefiniteLength, Display, Fill, FlexDirection, FlexWrap, Font, FontStyle, FontWeight,
4    GridPlacement, Hsla, JustifyContent, Length, Pixels, SharedString, StrikethroughStyle,
5    StyleRefinement, TextAlign, TextOverflow, TextShadow, TextStyleRefinement, UnderlineStyle,
6    WhiteSpace, point, px, relative, rems,
7};
8pub use gpui_macros::{
9    border_style_methods, box_shadow_style_methods, cursor_style_methods, margin_style_methods,
10    overflow_style_methods, padding_style_methods, position_style_methods,
11    visibility_style_methods,
12};
13
14const ELLIPSIS: SharedString = SharedString::new_static("…");
15
16/// A trait for elements that can be styled.
17/// Use this to opt-in to a utility CSS-like styling API.
18#[cfg_attr(
19    any(feature = "inspector", debug_assertions),
20    gpui_macros::derive_inspector_reflection
21)]
22pub trait Styled: Sized {
23    /// Returns a reference to the style memory of this element.
24    fn style(&mut self) -> &mut StyleRefinement;
25
26    gpui_macros::style_helpers!();
27    gpui_macros::visibility_style_methods!();
28    gpui_macros::margin_style_methods!();
29    gpui_macros::padding_style_methods!();
30    gpui_macros::position_style_methods!();
31    gpui_macros::overflow_style_methods!();
32    gpui_macros::cursor_style_methods!();
33    gpui_macros::border_style_methods!();
34    gpui_macros::box_shadow_style_methods!();
35
36    /// Sets the display type of the element to `block`.
37    /// [Docs](https://tailwindcss.com/docs/display)
38    fn block(mut self) -> Self {
39        self.style().display = Some(Display::Block);
40        self
41    }
42
43    /// Sets the display type of the element to `flex`.
44    /// [Docs](https://tailwindcss.com/docs/display)
45    fn flex(mut self) -> Self {
46        self.style().display = Some(Display::Flex);
47        self
48    }
49
50    /// Sets the display type of the element to `grid`.
51    /// [Docs](https://tailwindcss.com/docs/display)
52    fn grid(mut self) -> Self {
53        self.style().display = Some(Display::Grid);
54        self
55    }
56
57    /// Sets the whitespace of the element to `normal`.
58    /// [Docs](https://tailwindcss.com/docs/whitespace#normal)
59    fn whitespace_normal(mut self) -> Self {
60        self.text_style()
61            .get_or_insert_with(Default::default)
62            .white_space = Some(WhiteSpace::Normal);
63        self
64    }
65
66    /// Sets the whitespace of the element to `nowrap`.
67    /// [Docs](https://tailwindcss.com/docs/whitespace#nowrap)
68    fn whitespace_nowrap(mut self) -> Self {
69        self.text_style()
70            .get_or_insert_with(Default::default)
71            .white_space = Some(WhiteSpace::Nowrap);
72        self
73    }
74
75    /// Sets the truncate overflowing text with an ellipsis (…) if needed.
76    /// [Docs](https://tailwindcss.com/docs/text-overflow#ellipsis)
77    fn text_ellipsis(mut self) -> Self {
78        self.text_style()
79            .get_or_insert_with(Default::default)
80            .text_overflow = Some(TextOverflow::Truncate(ELLIPSIS));
81        self
82    }
83
84    /// Sets the text overflow behavior of the element.
85    fn text_overflow(mut self, overflow: TextOverflow) -> Self {
86        self.text_style()
87            .get_or_insert_with(Default::default)
88            .text_overflow = Some(overflow);
89        self
90    }
91
92    /// Set the text alignment of the element.
93    fn text_align(mut self, align: TextAlign) -> Self {
94        self.text_style()
95            .get_or_insert_with(Default::default)
96            .text_align = Some(align);
97        self
98    }
99
100    /// Sets the text alignment to left
101    fn text_left(mut self) -> Self {
102        self.text_align(TextAlign::Left)
103    }
104
105    /// Sets the text alignment to center
106    fn text_center(mut self) -> Self {
107        self.text_align(TextAlign::Center)
108    }
109
110    /// Sets the text alignment to right
111    fn text_right(mut self) -> Self {
112        self.text_align(TextAlign::Right)
113    }
114
115    /// Sets the truncate to prevent text from wrapping and truncate overflowing text with an ellipsis (…) if needed.
116    /// [Docs](https://tailwindcss.com/docs/text-overflow#truncate)
117    fn truncate(mut self) -> Self {
118        self.overflow_hidden().whitespace_nowrap().text_ellipsis()
119    }
120
121    /// Sets number of lines to show before truncating the text.
122    /// [Docs](https://tailwindcss.com/docs/line-clamp)
123    fn line_clamp(mut self, lines: usize) -> Self {
124        let mut text_style = self.text_style().get_or_insert_with(Default::default);
125        text_style.line_clamp = Some(lines);
126        self.overflow_hidden()
127    }
128
129    /// Sets the letter spacing (tracking) for text.
130    /// [Docs](https://tailwindcss.com/docs/letter-spacing)
131    fn letter_spacing(mut self, spacing: impl Into<Pixels>) -> Self {
132        self.text_style()
133            .get_or_insert_with(Default::default)
134            .letter_spacing = Some(spacing.into());
135        self
136    }
137
138    /// Sets letter spacing to -0.5px (tighter tracking).
139    fn tracking_tighter(self) -> Self {
140        self.letter_spacing(px(-0.5))
141    }
142
143    /// Sets letter spacing to -0.25px (tight tracking).
144    fn tracking_tight(self) -> Self {
145        self.letter_spacing(px(-0.25))
146    }
147
148    /// Resets letter spacing to 0px (normal tracking).
149    fn tracking_normal(self) -> Self {
150        self.letter_spacing(px(0.0))
151    }
152
153    /// Sets letter spacing to 0.5px (wide tracking).
154    fn tracking_wide(self) -> Self {
155        self.letter_spacing(px(0.5))
156    }
157
158    /// Sets letter spacing to 1.0px (wider tracking).
159    fn tracking_wider(self) -> Self {
160        self.letter_spacing(px(1.0))
161    }
162
163    /// Sets letter spacing to 2.0px (widest tracking).
164    fn tracking_widest(self) -> Self {
165        self.letter_spacing(px(2.0))
166    }
167
168    /// Enables continuous (squircle) corner rounding instead of circular.
169    /// This produces smooth Apple-style corners matching SwiftUI's continuous corner style.
170    fn continuous_corners(mut self) -> Self {
171        self.style().continuous_corners = Some(true);
172        self
173    }
174
175    /// Sets the blend mode for this element's background rendering.
176    fn blend_mode(mut self, mode: BlendMode) -> Self {
177        self.style().blend_mode = Some(mode);
178        self
179    }
180
181    /// Applies a text shadow with custom parameters.
182    fn text_shadow(mut self, shadow: TextShadow) -> Self {
183        self.text_style()
184            .get_or_insert_with(Default::default)
185            .text_shadow = Some(shadow);
186        self
187    }
188
189    /// Applies a small text shadow (1px offset, 2px blur).
190    fn text_shadow_sm(mut self) -> Self {
191        self.text_style()
192            .get_or_insert_with(Default::default)
193            .text_shadow = Some(TextShadow {
194            color: Hsla {
195                h: 0.0,
196                s: 0.0,
197                l: 0.0,
198                a: 0.2,
199            },
200            offset: point(px(0.0), px(1.0)),
201            blur_radius: px(2.0),
202        });
203        self
204    }
205
206    /// Applies a medium text shadow (2px offset, 4px blur).
207    fn text_shadow_md(mut self) -> Self {
208        self.text_style()
209            .get_or_insert_with(Default::default)
210            .text_shadow = Some(TextShadow {
211            color: Hsla {
212                h: 0.0,
213                s: 0.0,
214                l: 0.0,
215                a: 0.25,
216            },
217            offset: point(px(0.0), px(2.0)),
218            blur_radius: px(4.0),
219        });
220        self
221    }
222
223    /// Applies a large text shadow (3px offset, 6px blur).
224    fn text_shadow_lg(mut self) -> Self {
225        self.text_style()
226            .get_or_insert_with(Default::default)
227            .text_shadow = Some(TextShadow {
228            color: Hsla {
229                h: 0.0,
230                s: 0.0,
231                l: 0.0,
232                a: 0.3,
233            },
234            offset: point(px(0.0), px(3.0)),
235            blur_radius: px(6.0),
236        });
237        self
238    }
239
240    /// Sets the flex direction of the element to `column`.
241    /// [Docs](https://tailwindcss.com/docs/flex-direction#column)
242    fn flex_col(mut self) -> Self {
243        self.style().flex_direction = Some(FlexDirection::Column);
244        self
245    }
246
247    /// Sets the flex direction of the element to `column-reverse`.
248    /// [Docs](https://tailwindcss.com/docs/flex-direction#column-reverse)
249    fn flex_col_reverse(mut self) -> Self {
250        self.style().flex_direction = Some(FlexDirection::ColumnReverse);
251        self
252    }
253
254    /// Sets the flex direction of the element to `row`.
255    /// [Docs](https://tailwindcss.com/docs/flex-direction#row)
256    fn flex_row(mut self) -> Self {
257        self.style().flex_direction = Some(FlexDirection::Row);
258        self
259    }
260
261    /// Sets the flex direction of the element to `row-reverse`.
262    /// [Docs](https://tailwindcss.com/docs/flex-direction#row-reverse)
263    fn flex_row_reverse(mut self) -> Self {
264        self.style().flex_direction = Some(FlexDirection::RowReverse);
265        self
266    }
267
268    /// Sets the element to allow a flex item to grow and shrink as needed, ignoring its initial size.
269    /// [Docs](https://tailwindcss.com/docs/flex#flex-1)
270    fn flex_1(mut self) -> Self {
271        self.style().flex_grow = Some(1.);
272        self.style().flex_shrink = Some(1.);
273        self.style().flex_basis = Some(relative(0.).into());
274        self
275    }
276
277    /// Sets the element to allow a flex item to grow and shrink, taking into account its initial size.
278    /// [Docs](https://tailwindcss.com/docs/flex#auto)
279    fn flex_auto(mut self) -> Self {
280        self.style().flex_grow = Some(1.);
281        self.style().flex_shrink = Some(1.);
282        self.style().flex_basis = Some(Length::Auto);
283        self
284    }
285
286    /// Sets the element to allow a flex item to shrink but not grow, taking into account its initial size.
287    /// [Docs](https://tailwindcss.com/docs/flex#initial)
288    fn flex_initial(mut self) -> Self {
289        self.style().flex_grow = Some(0.);
290        self.style().flex_shrink = Some(1.);
291        self.style().flex_basis = Some(Length::Auto);
292        self
293    }
294
295    /// Sets the element to prevent a flex item from growing or shrinking.
296    /// [Docs](https://tailwindcss.com/docs/flex#none)
297    fn flex_none(mut self) -> Self {
298        self.style().flex_grow = Some(0.);
299        self.style().flex_shrink = Some(0.);
300        self
301    }
302
303    /// Sets the initial size of flex items for this element.
304    /// [Docs](https://tailwindcss.com/docs/flex-basis)
305    fn flex_basis(mut self, basis: impl Into<Length>) -> Self {
306        self.style().flex_basis = Some(basis.into());
307        self
308    }
309
310    /// Sets the element to allow a flex item to grow to fill any available space.
311    /// [Docs](https://tailwindcss.com/docs/flex-grow)
312    fn flex_grow(mut self) -> Self {
313        self.style().flex_grow = Some(1.);
314        self
315    }
316
317    /// Sets the element to allow a flex item to shrink if needed.
318    /// [Docs](https://tailwindcss.com/docs/flex-shrink)
319    fn flex_shrink(mut self) -> Self {
320        self.style().flex_shrink = Some(1.);
321        self
322    }
323
324    /// Sets the element to prevent a flex item from shrinking.
325    /// [Docs](https://tailwindcss.com/docs/flex-shrink#dont-shrink)
326    fn flex_shrink_0(mut self) -> Self {
327        self.style().flex_shrink = Some(0.);
328        self
329    }
330
331    /// Sets the element to allow flex items to wrap.
332    /// [Docs](https://tailwindcss.com/docs/flex-wrap#wrap-normally)
333    fn flex_wrap(mut self) -> Self {
334        self.style().flex_wrap = Some(FlexWrap::Wrap);
335        self
336    }
337
338    /// Sets the element wrap flex items in the reverse direction.
339    /// [Docs](https://tailwindcss.com/docs/flex-wrap#wrap-reversed)
340    fn flex_wrap_reverse(mut self) -> Self {
341        self.style().flex_wrap = Some(FlexWrap::WrapReverse);
342        self
343    }
344
345    /// Sets the element to prevent flex items from wrapping, causing inflexible items to overflow the container if necessary.
346    /// [Docs](https://tailwindcss.com/docs/flex-wrap#dont-wrap)
347    fn flex_nowrap(mut self) -> Self {
348        self.style().flex_wrap = Some(FlexWrap::NoWrap);
349        self
350    }
351
352    /// Sets the element to align flex items to the start of the container's cross axis.
353    /// [Docs](https://tailwindcss.com/docs/align-items#start)
354    fn items_start(mut self) -> Self {
355        self.style().align_items = Some(AlignItems::FlexStart);
356        self
357    }
358
359    /// Sets the element to align flex items to the end of the container's cross axis.
360    /// [Docs](https://tailwindcss.com/docs/align-items#end)
361    fn items_end(mut self) -> Self {
362        self.style().align_items = Some(AlignItems::FlexEnd);
363        self
364    }
365
366    /// Sets the element to align flex items along the center of the container's cross axis.
367    /// [Docs](https://tailwindcss.com/docs/align-items#center)
368    fn items_center(mut self) -> Self {
369        self.style().align_items = Some(AlignItems::Center);
370        self
371    }
372
373    /// Sets the element to align flex items along the baseline of the container's cross axis.
374    /// [Docs](https://tailwindcss.com/docs/align-items#baseline)
375    fn items_baseline(mut self) -> Self {
376        self.style().align_items = Some(AlignItems::Baseline);
377        self
378    }
379
380    /// Sets the element to justify flex items against the start of the container's main axis.
381    /// [Docs](https://tailwindcss.com/docs/justify-content#start)
382    fn justify_start(mut self) -> Self {
383        self.style().justify_content = Some(JustifyContent::Start);
384        self
385    }
386
387    /// Sets the element to justify flex items against the end of the container's main axis.
388    /// [Docs](https://tailwindcss.com/docs/justify-content#end)
389    fn justify_end(mut self) -> Self {
390        self.style().justify_content = Some(JustifyContent::End);
391        self
392    }
393
394    /// Sets the element to justify flex items along the center of the container's main axis.
395    /// [Docs](https://tailwindcss.com/docs/justify-content#center)
396    fn justify_center(mut self) -> Self {
397        self.style().justify_content = Some(JustifyContent::Center);
398        self
399    }
400
401    /// Sets the element to justify flex items along the container's main axis
402    /// such that there is an equal amount of space between each item.
403    /// [Docs](https://tailwindcss.com/docs/justify-content#space-between)
404    fn justify_between(mut self) -> Self {
405        self.style().justify_content = Some(JustifyContent::SpaceBetween);
406        self
407    }
408
409    /// Sets the element to justify items along the container's main axis such
410    /// that there is an equal amount of space on each side of each item.
411    /// [Docs](https://tailwindcss.com/docs/justify-content#space-around)
412    fn justify_around(mut self) -> Self {
413        self.style().justify_content = Some(JustifyContent::SpaceAround);
414        self
415    }
416
417    /// Sets the element to pack content items in their default position as if no align-content value was set.
418    /// [Docs](https://tailwindcss.com/docs/align-content#normal)
419    fn content_normal(mut self) -> Self {
420        self.style().align_content = None;
421        self
422    }
423
424    /// Sets the element to pack content items in the center of the container's cross axis.
425    /// [Docs](https://tailwindcss.com/docs/align-content#center)
426    fn content_center(mut self) -> Self {
427        self.style().align_content = Some(AlignContent::Center);
428        self
429    }
430
431    /// Sets the element to pack content items against the start of the container's cross axis.
432    /// [Docs](https://tailwindcss.com/docs/align-content#start)
433    fn content_start(mut self) -> Self {
434        self.style().align_content = Some(AlignContent::FlexStart);
435        self
436    }
437
438    /// Sets the element to pack content items against the end of the container's cross axis.
439    /// [Docs](https://tailwindcss.com/docs/align-content#end)
440    fn content_end(mut self) -> Self {
441        self.style().align_content = Some(AlignContent::FlexEnd);
442        self
443    }
444
445    /// Sets the element to pack content items along the container's cross axis
446    /// such that there is an equal amount of space between each item.
447    /// [Docs](https://tailwindcss.com/docs/align-content#space-between)
448    fn content_between(mut self) -> Self {
449        self.style().align_content = Some(AlignContent::SpaceBetween);
450        self
451    }
452
453    /// Sets the element to pack content items along the container's cross axis
454    /// such that there is an equal amount of space on each side of each item.
455    /// [Docs](https://tailwindcss.com/docs/align-content#space-around)
456    fn content_around(mut self) -> Self {
457        self.style().align_content = Some(AlignContent::SpaceAround);
458        self
459    }
460
461    /// Sets the element to pack content items along the container's cross axis
462    /// such that there is an equal amount of space between each item.
463    /// [Docs](https://tailwindcss.com/docs/align-content#space-evenly)
464    fn content_evenly(mut self) -> Self {
465        self.style().align_content = Some(AlignContent::SpaceEvenly);
466        self
467    }
468
469    /// Sets the element to allow content items to fill the available space along the container's cross axis.
470    /// [Docs](https://tailwindcss.com/docs/align-content#stretch)
471    fn content_stretch(mut self) -> Self {
472        self.style().align_content = Some(AlignContent::Stretch);
473        self
474    }
475
476    /// Sets the background color of the element.
477    fn bg<F>(mut self, fill: F) -> Self
478    where
479        F: Into<Fill>,
480        Self: Sized,
481    {
482        self.style().background = Some(fill.into());
483        self
484    }
485
486    /// Sets the border style of the element.
487    fn border_dashed(mut self) -> Self {
488        self.style().border_style = Some(BorderStyle::Dashed);
489        self
490    }
491
492    /// Returns a mutable reference to the text style that has been configured on this element.
493    fn text_style(&mut self) -> &mut Option<TextStyleRefinement> {
494        let style: &mut StyleRefinement = self.style();
495        &mut style.text
496    }
497
498    /// Sets the text color of this element.
499    ///
500    /// This value cascades to its child elements.
501    fn text_color(mut self, color: impl Into<Hsla>) -> Self {
502        self.text_style().get_or_insert_with(Default::default).color = Some(color.into());
503        self
504    }
505
506    /// Sets the font weight of this element
507    ///
508    /// This value cascades to its child elements.
509    fn font_weight(mut self, weight: FontWeight) -> Self {
510        self.text_style()
511            .get_or_insert_with(Default::default)
512            .font_weight = Some(weight);
513        self
514    }
515
516    /// Sets the background color of this element.
517    ///
518    /// This value cascades to its child elements.
519    fn text_bg(mut self, bg: impl Into<Hsla>) -> Self {
520        self.text_style()
521            .get_or_insert_with(Default::default)
522            .background_color = Some(bg.into());
523        self
524    }
525
526    /// Sets the text size of this element.
527    ///
528    /// This value cascades to its child elements.
529    fn text_size(mut self, size: impl Into<AbsoluteLength>) -> Self {
530        self.text_style()
531            .get_or_insert_with(Default::default)
532            .font_size = Some(size.into());
533        self
534    }
535
536    /// Sets the text size to 'extra small'.
537    /// [Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
538    fn text_xs(mut self) -> Self {
539        self.text_style()
540            .get_or_insert_with(Default::default)
541            .font_size = Some(rems(0.75).into());
542        self
543    }
544
545    /// Sets the text size to 'small'.
546    /// [Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
547    fn text_sm(mut self) -> Self {
548        self.text_style()
549            .get_or_insert_with(Default::default)
550            .font_size = Some(rems(0.875).into());
551        self
552    }
553
554    /// Sets the text size to 'base'.
555    /// [Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
556    fn text_base(mut self) -> Self {
557        self.text_style()
558            .get_or_insert_with(Default::default)
559            .font_size = Some(rems(1.0).into());
560        self
561    }
562
563    /// Sets the text size to 'large'.
564    /// [Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
565    fn text_lg(mut self) -> Self {
566        self.text_style()
567            .get_or_insert_with(Default::default)
568            .font_size = Some(rems(1.125).into());
569        self
570    }
571
572    /// Sets the text size to 'extra large'.
573    /// [Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
574    fn text_xl(mut self) -> Self {
575        self.text_style()
576            .get_or_insert_with(Default::default)
577            .font_size = Some(rems(1.25).into());
578        self
579    }
580
581    /// Sets the text size to 'extra extra large'.
582    /// [Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
583    fn text_2xl(mut self) -> Self {
584        self.text_style()
585            .get_or_insert_with(Default::default)
586            .font_size = Some(rems(1.5).into());
587        self
588    }
589
590    /// Sets the text size to 'extra extra extra large'.
591    /// [Docs](https://tailwindcss.com/docs/font-size#setting-the-font-size)
592    fn text_3xl(mut self) -> Self {
593        self.text_style()
594            .get_or_insert_with(Default::default)
595            .font_size = Some(rems(1.875).into());
596        self
597    }
598
599    /// Sets the font style of the element to italic.
600    /// [Docs](https://tailwindcss.com/docs/font-style#italicizing-text)
601    fn italic(mut self) -> Self {
602        self.text_style()
603            .get_or_insert_with(Default::default)
604            .font_style = Some(FontStyle::Italic);
605        self
606    }
607
608    /// Sets the font style of the element to normal (not italic).
609    /// [Docs](https://tailwindcss.com/docs/font-style#displaying-text-normally)
610    fn not_italic(mut self) -> Self {
611        self.text_style()
612            .get_or_insert_with(Default::default)
613            .font_style = Some(FontStyle::Normal);
614        self
615    }
616
617    /// Sets the text decoration to underline.
618    /// [Docs](https://tailwindcss.com/docs/text-decoration-line#underling-text)
619    fn underline(mut self) -> Self {
620        let style = self.text_style().get_or_insert_with(Default::default);
621        style.underline = Some(UnderlineStyle {
622            thickness: px(1.),
623            ..Default::default()
624        });
625        self
626    }
627
628    /// Sets the decoration of the text to have a line through it.
629    /// [Docs](https://tailwindcss.com/docs/text-decoration-line#adding-a-line-through-text)
630    fn line_through(mut self) -> Self {
631        let style = self.text_style().get_or_insert_with(Default::default);
632        style.strikethrough = Some(StrikethroughStyle {
633            thickness: px(1.),
634            ..Default::default()
635        });
636        self
637    }
638
639    /// Removes the text decoration on this element.
640    ///
641    /// This value cascades to its child elements.
642    fn text_decoration_none(mut self) -> Self {
643        self.text_style()
644            .get_or_insert_with(Default::default)
645            .underline = None;
646        self
647    }
648
649    /// Sets the color for the underline on this element
650    fn text_decoration_color(mut self, color: impl Into<Hsla>) -> Self {
651        let style = self.text_style().get_or_insert_with(Default::default);
652        let underline = style.underline.get_or_insert_with(Default::default);
653        underline.color = Some(color.into());
654        self
655    }
656
657    /// Sets the text decoration style to a solid line.
658    /// [Docs](https://tailwindcss.com/docs/text-decoration-style)
659    fn text_decoration_solid(mut self) -> Self {
660        let style = self.text_style().get_or_insert_with(Default::default);
661        let underline = style.underline.get_or_insert_with(Default::default);
662        underline.wavy = false;
663        self
664    }
665
666    /// Sets the text decoration style to a wavy line.
667    /// [Docs](https://tailwindcss.com/docs/text-decoration-style)
668    fn text_decoration_wavy(mut self) -> Self {
669        let style = self.text_style().get_or_insert_with(Default::default);
670        let underline = style.underline.get_or_insert_with(Default::default);
671        underline.wavy = true;
672        self
673    }
674
675    /// Sets the text decoration to be 0px thick.
676    /// [Docs](https://tailwindcss.com/docs/text-decoration-thickness)
677    fn text_decoration_0(mut self) -> Self {
678        let style = self.text_style().get_or_insert_with(Default::default);
679        let underline = style.underline.get_or_insert_with(Default::default);
680        underline.thickness = px(0.);
681        self
682    }
683
684    /// Sets the text decoration to be 1px thick.
685    /// [Docs](https://tailwindcss.com/docs/text-decoration-thickness)
686    fn text_decoration_1(mut self) -> Self {
687        let style = self.text_style().get_or_insert_with(Default::default);
688        let underline = style.underline.get_or_insert_with(Default::default);
689        underline.thickness = px(1.);
690        self
691    }
692
693    /// Sets the text decoration to be 2px thick.
694    /// [Docs](https://tailwindcss.com/docs/text-decoration-thickness)
695    fn text_decoration_2(mut self) -> Self {
696        let style = self.text_style().get_or_insert_with(Default::default);
697        let underline = style.underline.get_or_insert_with(Default::default);
698        underline.thickness = px(2.);
699        self
700    }
701
702    /// Sets the text decoration to be 4px thick.
703    /// [Docs](https://tailwindcss.com/docs/text-decoration-thickness)
704    fn text_decoration_4(mut self) -> Self {
705        let style = self.text_style().get_or_insert_with(Default::default);
706        let underline = style.underline.get_or_insert_with(Default::default);
707        underline.thickness = px(4.);
708        self
709    }
710
711    /// Sets the text decoration to be 8px thick.
712    /// [Docs](https://tailwindcss.com/docs/text-decoration-thickness)
713    fn text_decoration_8(mut self) -> Self {
714        let style = self.text_style().get_or_insert_with(Default::default);
715        let underline = style.underline.get_or_insert_with(Default::default);
716        underline.thickness = px(8.);
717        self
718    }
719
720    /// Sets the font family of this element and its children.
721    fn font_family(mut self, family_name: impl Into<SharedString>) -> Self {
722        self.text_style()
723            .get_or_insert_with(Default::default)
724            .font_family = Some(family_name.into());
725        self
726    }
727
728    /// Sets the font of this element and its children.
729    fn font(mut self, font: Font) -> Self {
730        let Font {
731            family,
732            features,
733            fallbacks,
734            weight,
735            style,
736        } = font;
737
738        let text_style = self.text_style().get_or_insert_with(Default::default);
739        text_style.font_family = Some(family);
740        text_style.font_features = Some(features);
741        text_style.font_weight = Some(weight);
742        text_style.font_style = Some(style);
743        text_style.font_fallbacks = fallbacks;
744
745        self
746    }
747
748    /// Sets the line height of this element and its children.
749    fn line_height(mut self, line_height: impl Into<DefiniteLength>) -> Self {
750        self.text_style()
751            .get_or_insert_with(Default::default)
752            .line_height = Some(line_height.into());
753        self
754    }
755
756    /// Sets the opacity of this element and its children.
757    fn opacity(mut self, opacity: f32) -> Self {
758        self.style().opacity = Some(opacity);
759        self
760    }
761
762    /// Sets clockwise rotation in degrees.
763    fn rotate(mut self, angle_degrees: f32) -> Self {
764        self.style().rotate = Some(angle_degrees.to_radians());
765        self
766    }
767
768    /// Sets uniform scale factor.
769    fn scale(mut self, factor: f32) -> Self {
770        self.style().scale = Some(point(factor, factor));
771        self
772    }
773
774    /// Sets non-uniform scale factors for x and y axes.
775    fn scale_xy(mut self, x: f32, y: f32) -> Self {
776        self.style().scale = Some(point(x, y));
777        self
778    }
779
780    /// Sets the transform origin as a fraction of element size (0.0-1.0).
781    /// Default is center (0.5, 0.5).
782    fn transform_origin(mut self, x: f32, y: f32) -> Self {
783        self.style().transform_origin = Some(point(x, y));
784        self
785    }
786
787    /// Sets the grid columns of this element.
788    fn grid_cols(mut self, cols: u16) -> Self {
789        self.style().grid_cols = Some(cols);
790        self
791    }
792
793    /// Sets the grid rows of this element.
794    fn grid_rows(mut self, rows: u16) -> Self {
795        self.style().grid_rows = Some(rows);
796        self
797    }
798
799    /// Sets the column start of this element.
800    fn col_start(mut self, start: i16) -> Self {
801        let grid_location = self.style().grid_location_mut();
802        grid_location.column.start = GridPlacement::Line(start);
803        self
804    }
805
806    /// Sets the column start of this element to auto.
807    fn col_start_auto(mut self) -> Self {
808        let grid_location = self.style().grid_location_mut();
809        grid_location.column.start = GridPlacement::Auto;
810        self
811    }
812
813    /// Sets the column end of this element.
814    fn col_end(mut self, end: i16) -> Self {
815        let grid_location = self.style().grid_location_mut();
816        grid_location.column.end = GridPlacement::Line(end);
817        self
818    }
819
820    /// Sets the column end of this element to auto.
821    fn col_end_auto(mut self) -> Self {
822        let grid_location = self.style().grid_location_mut();
823        grid_location.column.end = GridPlacement::Auto;
824        self
825    }
826
827    /// Sets the column span of this element.
828    fn col_span(mut self, span: u16) -> Self {
829        let grid_location = self.style().grid_location_mut();
830        grid_location.column = GridPlacement::Span(span)..GridPlacement::Span(span);
831        self
832    }
833
834    /// Sets the row span of this element.
835    fn col_span_full(mut self) -> Self {
836        let grid_location = self.style().grid_location_mut();
837        grid_location.column = GridPlacement::Line(1)..GridPlacement::Line(-1);
838        self
839    }
840
841    /// Sets the row start of this element.
842    fn row_start(mut self, start: i16) -> Self {
843        let grid_location = self.style().grid_location_mut();
844        grid_location.row.start = GridPlacement::Line(start);
845        self
846    }
847
848    /// Sets the row start of this element to "auto"
849    fn row_start_auto(mut self) -> Self {
850        let grid_location = self.style().grid_location_mut();
851        grid_location.row.start = GridPlacement::Auto;
852        self
853    }
854
855    /// Sets the row end of this element.
856    fn row_end(mut self, end: i16) -> Self {
857        let grid_location = self.style().grid_location_mut();
858        grid_location.row.end = GridPlacement::Line(end);
859        self
860    }
861
862    /// Sets the row end of this element to "auto"
863    fn row_end_auto(mut self) -> Self {
864        let grid_location = self.style().grid_location_mut();
865        grid_location.row.end = GridPlacement::Auto;
866        self
867    }
868
869    /// Sets the row span of this element.
870    fn row_span(mut self, span: u16) -> Self {
871        let grid_location = self.style().grid_location_mut();
872        grid_location.row = GridPlacement::Span(span)..GridPlacement::Span(span);
873        self
874    }
875
876    /// Sets the row span of this element.
877    fn row_span_full(mut self) -> Self {
878        let grid_location = self.style().grid_location_mut();
879        grid_location.row = GridPlacement::Line(1)..GridPlacement::Line(-1);
880        self
881    }
882
883    /// Draws a debug border around this element.
884    #[cfg(debug_assertions)]
885    fn debug(mut self) -> Self {
886        self.style().debug = Some(true);
887        self
888    }
889
890    /// Draws a debug border on all conforming elements below this element.
891    #[cfg(debug_assertions)]
892    fn debug_below(mut self) -> Self {
893        self.style().debug_below = Some(true);
894        self
895    }
896}