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