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