Skip to main content

wgpui/
styled.rs

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