euv_core/style/sheet/impl.rs
1use super::*;
2
3/// Fluent zero-allocation builder methods for `Style`.
4impl Style {
5 /// Applies any strongly-typed `StyleApply` value (e.g. `AlignItems::Center`, `Overflow::Hidden`, `Shadow`) to this style.
6 ///
7 /// # Arguments
8 ///
9 /// - `Self` - Source style.
10 /// - `T` - Typed property implementing `StyleApply`.
11 ///
12 /// # Returns
13 ///
14 /// - `Self` - Updated style.
15 #[must_use]
16 pub fn apply<T>(self, prop: T) -> Self
17 where
18 T: StyleApply,
19 {
20 prop.apply_to(self)
21 }
22
23 /// Sets the flex container axis direction (`FlexDirection::Row` or `FlexDirection::Column`).
24 ///
25 /// # Arguments
26 ///
27 /// - `Self` - Source style.
28 /// - `FlexDirection` - Target flex axis direction.
29 ///
30 /// # Returns
31 ///
32 /// - `Self` - Updated style.
33 #[must_use]
34 pub fn direction(mut self, direction: FlexDirection) -> Self {
35 if self.get_layout().get_display() != Display::None {
36 self.get_mut_layout().set_display(Display::Flex);
37 }
38 self.get_mut_layout().set_flex_direction(direction);
39 self
40 }
41
42 /// Sets the box display mode.
43 ///
44 /// # Arguments
45 ///
46 /// - `Self` - Source style.
47 /// - `Display` - Target display mode.
48 ///
49 /// # Returns
50 ///
51 /// - `Self` - Updated style.
52 #[must_use]
53 pub fn display(mut self, display: Display) -> Self {
54 self.get_mut_layout().set_display(display);
55 self
56 }
57
58 /// Sets the positioning mode.
59 ///
60 /// # Arguments
61 ///
62 /// - `Self` - Source style.
63 /// - `Position` - Target position mode.
64 ///
65 /// # Returns
66 ///
67 /// - `Self` - Updated style.
68 #[must_use]
69 pub fn position(mut self, position: Position) -> Self {
70 self.get_mut_layout().set_position(position);
71 self
72 }
73
74 /// Configures a horizontal flex row.
75 ///
76 /// # Arguments
77 ///
78 /// - `Self` - Source style.
79 ///
80 /// # Returns
81 ///
82 /// - `Self` - Updated style.
83 #[must_use]
84 pub fn row(mut self) -> Self {
85 if self.get_layout().get_display() != Display::None {
86 self.get_mut_layout().set_display(Display::Flex);
87 }
88 self.get_mut_layout().set_flex_direction(FlexDirection::Row);
89 self
90 }
91
92 /// Configures a vertical flex column.
93 ///
94 /// # Arguments
95 ///
96 /// - `Self` - Source style.
97 ///
98 /// # Returns
99 ///
100 /// - `Self` - Updated style.
101 #[must_use]
102 pub fn column(mut self) -> Self {
103 if self.get_layout().get_display() != Display::None {
104 self.get_mut_layout().set_display(Display::Flex);
105 }
106 self.get_mut_layout()
107 .set_flex_direction(FlexDirection::Column);
108 self
109 }
110
111 /// Configures a grid layout with `columns` equal-width columns.
112 ///
113 /// # Arguments
114 ///
115 /// - `Self` - Source style.
116 /// - `u16` - Number of grid columns (clamped to at least 1).
117 ///
118 /// # Returns
119 ///
120 /// - `Self` - Updated style.
121 #[must_use]
122 pub fn grid(mut self, columns: u16) -> Self {
123 if self.get_layout().get_display() != Display::None {
124 self.get_mut_layout().set_display(Display::Grid);
125 }
126 self.get_mut_layout().set_grid_columns(columns.max(1));
127 self
128 }
129
130 /// Sets flex wrapping behavior.
131 ///
132 /// # Arguments
133 ///
134 /// - `Self` - Source style.
135 /// - `FlexWrap` - Wrap mode.
136 ///
137 /// # Returns
138 ///
139 /// - `Self` - Updated style.
140 #[must_use]
141 pub fn wrap(mut self, wrap: FlexWrap) -> Self {
142 self.get_mut_layout().set_flex_wrap(wrap);
143 self
144 }
145
146 /// Sets main-axis justification.
147 ///
148 /// # Arguments
149 ///
150 /// - `Self` - Source style.
151 /// - `JustifyContent` - Justification mode.
152 ///
153 /// # Returns
154 ///
155 /// - `Self` - Updated style.
156 #[must_use]
157 pub fn justify(mut self, justify: JustifyContent) -> Self {
158 self.get_mut_layout().set_justify_content(justify);
159 self
160 }
161
162 /// Sets cross-axis alignment.
163 ///
164 /// # Arguments
165 ///
166 /// - `Self` - Source style.
167 /// - `AlignItems` - Cross-axis alignment.
168 ///
169 /// # Returns
170 ///
171 /// - `Self` - Updated style.
172 #[must_use]
173 pub fn align(mut self, align: AlignItems) -> Self {
174 self.get_mut_layout().set_align_items(align);
175 self
176 }
177
178 /// Sets flex grow factor.
179 ///
180 /// # Arguments
181 ///
182 /// - `Self` - Source style.
183 /// - `f32` - Flex grow factor.
184 ///
185 /// # Returns
186 ///
187 /// - `Self` - Updated style.
188 #[must_use]
189 pub fn flex_grow(mut self, grow: f32) -> Self {
190 self.get_mut_layout().set_flex_grow(grow.max(0.0));
191 self
192 }
193
194 /// Sets flex shrink factor.
195 ///
196 /// # Arguments
197 ///
198 /// - `Self` - Source style.
199 /// - `f32` - Flex shrink factor.
200 ///
201 /// # Returns
202 ///
203 /// - `Self` - Updated style.
204 #[must_use]
205 pub fn flex_shrink(mut self, shrink: f32) -> Self {
206 self.get_mut_layout().set_flex_shrink(shrink.max(0.0));
207 self
208 }
209
210 /// Sets width length.
211 ///
212 /// # Arguments
213 ///
214 /// - `Self` - Source style.
215 /// - `Length` - Target width.
216 ///
217 /// # Returns
218 ///
219 /// - `Self` - Updated style.
220 #[must_use]
221 pub fn width(mut self, width: Length) -> Self {
222 self.get_mut_layout().set_width(width);
223 self
224 }
225
226 /// Sets height length.
227 ///
228 /// # Arguments
229 ///
230 /// - `Self` - Source style.
231 /// - `Length` - Target height.
232 ///
233 /// # Returns
234 ///
235 /// - `Self` - Updated style.
236 #[must_use]
237 pub fn height(mut self, height: Length) -> Self {
238 self.get_mut_layout().set_height(height);
239 self
240 }
241
242 /// Sets minimum width constraint.
243 ///
244 /// # Arguments
245 ///
246 /// - `Self` - Source style.
247 /// - `Length` - Minimum width.
248 ///
249 /// # Returns
250 ///
251 /// - `Self` - Updated style.
252 #[must_use]
253 pub fn min_width(mut self, min_width: Length) -> Self {
254 self.get_mut_layout().set_min_width(min_width);
255 self
256 }
257
258 /// Sets minimum height constraint.
259 ///
260 /// # Arguments
261 ///
262 /// - `Self` - Source style.
263 /// - `Length` - Minimum height.
264 ///
265 /// # Returns
266 ///
267 /// - `Self` - Updated style.
268 #[must_use]
269 pub fn min_height(mut self, min_height: Length) -> Self {
270 self.get_mut_layout().set_min_height(min_height);
271 self
272 }
273
274 /// Sets maximum width constraint.
275 ///
276 /// # Arguments
277 ///
278 /// - `Self` - Source style.
279 /// - `Length` - Maximum width.
280 ///
281 /// # Returns
282 ///
283 /// - `Self` - Updated style.
284 #[must_use]
285 pub fn max_width(mut self, max_width: Length) -> Self {
286 self.get_mut_layout().set_max_width(max_width);
287 self
288 }
289
290 /// Sets maximum height constraint.
291 ///
292 /// # Arguments
293 ///
294 /// - `Self` - Source style.
295 /// - `Length` - Maximum height.
296 ///
297 /// # Returns
298 ///
299 /// - `Self` - Updated style.
300 #[must_use]
301 pub fn max_height(mut self, max_height: Length) -> Self {
302 self.get_mut_layout().set_max_height(max_height);
303 self
304 }
305
306 /// Sets an explicit width-to-height aspect ratio constraint.
307 ///
308 /// # Arguments
309 ///
310 /// - `Self` - Source style.
311 /// - `f32` - Positive aspect ratio (`width / height`).
312 ///
313 /// # Returns
314 ///
315 /// - `Self` - Updated style.
316 #[must_use]
317 pub fn aspect_ratio(mut self, ratio: f32) -> Self {
318 if ratio > 0.0 && ratio.is_finite() {
319 self.get_mut_layout().set_aspect_ratio(Some(ratio));
320 }
321 self
322 }
323
324 /// Sets uniform gap along both row and column axes.
325 ///
326 /// # Arguments
327 ///
328 /// - `Self` - Source style.
329 /// - `f32` - Gap in logical pixels.
330 ///
331 /// # Returns
332 ///
333 /// - `Self` - Updated style.
334 #[must_use]
335 pub fn gap(mut self, gap: f32) -> Self {
336 let clamped: f32 = gap.max(0.0);
337 self.get_mut_layout().set_row_gap(clamped);
338 self.get_mut_layout().set_column_gap(clamped);
339 self
340 }
341
342 /// Sets inner padding edges.
343 ///
344 /// # Arguments
345 ///
346 /// - `Self` - Source style.
347 /// - `Edges` - Inner padding insets.
348 ///
349 /// # Returns
350 ///
351 /// - `Self` - Updated style.
352 #[must_use]
353 pub fn padding(mut self, padding: Edges) -> Self {
354 self.get_mut_layout().set_padding(padding);
355 self
356 }
357
358 /// Sets outer margin edges.
359 ///
360 /// # Arguments
361 ///
362 /// - `Self` - Source style.
363 /// - `Edges` - Outer margin insets.
364 ///
365 /// # Returns
366 ///
367 /// - `Self` - Updated style.
368 #[must_use]
369 pub fn margin(mut self, margin: Edges) -> Self {
370 self.get_mut_layout().set_margin(margin);
371 self
372 }
373
374 /// Sets overflow behavior.
375 ///
376 /// # Arguments
377 ///
378 /// - `Self` - Source style.
379 /// - `Overflow` - Target overflow behavior.
380 ///
381 /// # Returns
382 ///
383 /// - `Self` - Updated style.
384 #[must_use]
385 pub fn overflow(mut self, overflow: Overflow) -> Self {
386 self.get_mut_layout().set_overflow(overflow);
387 self
388 }
389
390 /// Sets stacking z-index.
391 ///
392 /// # Arguments
393 ///
394 /// - `Self` - Source style.
395 /// - `i32` - Stacking layer index.
396 ///
397 /// # Returns
398 ///
399 /// - `Self` - Updated style.
400 #[must_use]
401 pub fn z_index(mut self, z_index: i32) -> Self {
402 self.get_mut_layout().set_z_index(z_index);
403 self
404 }
405
406 /// Sets absolute or fixed inset coordinates.
407 ///
408 /// # Arguments
409 ///
410 /// - `Self` - Source style.
411 /// - `Option<f32>` - Top offset.
412 /// - `Option<f32>` - Right offset.
413 /// - `Option<f32>` - Bottom offset.
414 /// - `Option<f32>` - Left offset.
415 ///
416 /// # Returns
417 ///
418 /// - `Self` - Updated style.
419 #[must_use]
420 pub fn inset(
421 mut self,
422 top: Option<f32>,
423 right: Option<f32>,
424 bottom: Option<f32>,
425 left: Option<f32>,
426 ) -> Self {
427 self.get_mut_layout().set_top(top);
428 self.get_mut_layout().set_right(right);
429 self.get_mut_layout().set_bottom(bottom);
430 self.get_mut_layout().set_left(left);
431 self
432 }
433
434 /// Sets solid background fill color.
435 ///
436 /// # Arguments
437 ///
438 /// - `Self` - Source style.
439 /// - `Color` - Background color.
440 ///
441 /// # Returns
442 ///
443 /// - `Self` - Updated style.
444 #[must_use]
445 pub fn background(mut self, color: Color) -> Self {
446 self.get_mut_paint().set_background(Some(color));
447 self
448 }
449
450 /// Sets linear gradient fill.
451 ///
452 /// # Arguments
453 ///
454 /// - `Self` - Source style.
455 /// - `LinearGradient` - Linear gradient specification.
456 ///
457 /// # Returns
458 ///
459 /// - `Self` - Updated style.
460 #[must_use]
461 pub fn gradient(mut self, gradient: LinearGradient) -> Self {
462 self.get_mut_paint().set_gradient(Some(gradient));
463 self
464 }
465
466 /// Sets border stroke width and color.
467 ///
468 /// # Arguments
469 ///
470 /// - `Self` - Source style.
471 /// - `f32` - Border width in logical pixels.
472 /// - `Color` - Border color.
473 ///
474 /// # Returns
475 ///
476 /// - `Self` - Updated style.
477 #[must_use]
478 pub fn border(mut self, width: f32, color: Color) -> Self {
479 self.get_mut_paint()
480 .set_border(Border::new(width.max(0.0), color));
481 self
482 }
483
484 /// Sets uniform corner radius.
485 ///
486 /// # Arguments
487 ///
488 /// - `Self` - Source style.
489 /// - `f32` - Corner radius in logical pixels.
490 ///
491 /// # Returns
492 ///
493 /// - `Self` - Updated style.
494 #[must_use]
495 pub fn radius(mut self, radius: f32) -> Self {
496 self.get_mut_paint()
497 .set_radius(CornerRadius::all(radius.max(0.0)));
498 self
499 }
500
501 /// Sets drop shadow.
502 ///
503 /// # Arguments
504 ///
505 /// - `Self` - Source style.
506 /// - `Shadow` - Shadow definition.
507 ///
508 /// # Returns
509 ///
510 /// - `Self` - Updated style.
511 #[must_use]
512 pub fn shadow(mut self, shadow: Shadow) -> Self {
513 self.get_mut_paint().set_shadow(Some(shadow));
514 self
515 }
516
517 /// Sets focus ring stroke.
518 ///
519 /// # Arguments
520 ///
521 /// - `Self` - Source style.
522 /// - `Border` - Focus ring width and color.
523 ///
524 /// # Returns
525 ///
526 /// - `Self` - Updated style.
527 #[must_use]
528 pub fn focus_ring(mut self, ring: Border) -> Self {
529 self.get_mut_paint().set_focus_ring(Some(ring));
530 self
531 }
532
533 /// Sets opacity in `[0.0, 1.0]`.
534 ///
535 /// # Arguments
536 ///
537 /// - `Self` - Source style.
538 /// - `f32` - Opacity factor.
539 ///
540 /// # Returns
541 ///
542 /// - `Self` - Updated style.
543 #[must_use]
544 pub fn opacity(mut self, opacity: f32) -> Self {
545 self.get_mut_paint().set_opacity(opacity.clamp(0.0, 1.0));
546 self
547 }
548
549 /// Sets cursor icon hint.
550 ///
551 /// # Arguments
552 ///
553 /// - `Self` - Source style.
554 /// - `CursorIcon` - Target cursor icon.
555 ///
556 /// # Returns
557 ///
558 /// - `Self` - Updated style.
559 #[must_use]
560 pub fn cursor(mut self, cursor: CursorIcon) -> Self {
561 self.get_mut_paint().set_cursor(cursor);
562 self
563 }
564
565 /// Sets pointer hit-test participation behavior.
566 ///
567 /// # Arguments
568 ///
569 /// - `Self` - Source style.
570 /// - `PointerEvents` - Target pointer-events mode.
571 ///
572 /// # Returns
573 ///
574 /// - `Self` - Updated style.
575 #[must_use]
576 pub fn pointer_events(mut self, pointer_events: PointerEvents) -> Self {
577 self.get_mut_paint().set_pointer_events(pointer_events);
578 self
579 }
580
581 /// Sets foreground text color.
582 ///
583 /// # Arguments
584 ///
585 /// - `Self` - Source style.
586 /// - `Color` - Text color.
587 ///
588 /// # Returns
589 ///
590 /// - `Self` - Updated style.
591 #[must_use]
592 pub fn color(mut self, color: Color) -> Self {
593 self.get_mut_text().set_color(color);
594 self
595 }
596
597 /// Sets font size in logical pixels.
598 ///
599 /// # Arguments
600 ///
601 /// - `Self` - Source style.
602 /// - `f32` - Font size in pixels.
603 ///
604 /// # Returns
605 ///
606 /// - `Self` - Updated style.
607 #[must_use]
608 pub fn font_size(mut self, size: f32) -> Self {
609 self.get_mut_text().set_font_size(size.max(6.0));
610 self
611 }
612
613 /// Sets font weight.
614 ///
615 /// # Arguments
616 ///
617 /// - `Self` - Source style.
618 /// - `FontWeight` - Target font weight.
619 ///
620 /// # Returns
621 ///
622 /// - `Self` - Updated style.
623 #[must_use]
624 pub fn font_weight(mut self, weight: FontWeight) -> Self {
625 self.get_mut_text().set_weight(weight);
626 self
627 }
628
629 /// Sets font family.
630 ///
631 /// # Arguments
632 ///
633 /// - `Self` - Source style.
634 /// - `FontFamily` - Semantic font family.
635 ///
636 /// # Returns
637 ///
638 /// - `Self` - Updated style.
639 #[must_use]
640 pub fn font_family(mut self, family: FontFamily) -> Self {
641 self.get_mut_text().set_family(family);
642 self
643 }
644
645 /// Sets horizontal text alignment.
646 ///
647 /// # Arguments
648 ///
649 /// - `Self` - Source style.
650 /// - `TextAlign` - Text alignment.
651 ///
652 /// # Returns
653 ///
654 /// - `Self` - Updated style.
655 #[must_use]
656 pub fn text_align(mut self, align: TextAlign) -> Self {
657 self.get_mut_text().set_align(align);
658 self
659 }
660
661 /// Sets text overflow behavior.
662 ///
663 /// # Arguments
664 ///
665 /// - `Self` - Source style.
666 /// - `TextOverflow` - Overflow strategy.
667 ///
668 /// # Returns
669 ///
670 /// - `Self` - Updated style.
671 #[must_use]
672 pub fn text_overflow(mut self, overflow: TextOverflow) -> Self {
673 self.get_mut_text().set_overflow(overflow);
674 self
675 }
676
677 /// Configures whether scroll deltas stop at this node (`true`) or chain/penetrate to parent scrollables (`false`).
678 ///
679 /// # Arguments
680 ///
681 /// - `Self` - Source style.
682 /// - `bool` - `true` blocks scroll penetration to ancestors; `false` permits scroll chaining.
683 ///
684 /// # Returns
685 ///
686 /// - `Self` - Updated style.
687 #[must_use]
688 pub fn stop_scroll_propagation(mut self, stop: bool) -> Self {
689 self.get_mut_paint().set_stop_scroll_propagation(stop);
690 self
691 }
692
693 /// Configures whether click/pointer events stop bubbling at this node (`true`) or bubble to ancestors (`false`).
694 ///
695 /// # Arguments
696 ///
697 /// - `Self` - Source style.
698 /// - `bool` - `true` blocks event bubbling; `false` permits bubbling.
699 ///
700 /// # Returns
701 ///
702 /// - `Self` - Updated style.
703 #[must_use]
704 pub fn stop_event_propagation(mut self, stop: bool) -> Self {
705 self.get_mut_paint().set_stop_event_propagation(stop);
706 self
707 }
708}
709
710/// Resolution helpers for `ResponsiveStyle`.
711impl ResponsiveStyle {
712 /// Resolves the active `Style` for the supplied `Breakpoint`.
713 ///
714 /// # Arguments
715 ///
716 /// - `&Self` - Responsive style definition.
717 /// - `Breakpoint` - Current viewport breakpoint.
718 ///
719 /// # Returns
720 ///
721 /// - `Style` - Resolved concrete style.
722 #[must_use]
723 pub fn resolve(&self, breakpoint: Breakpoint) -> Style {
724 let Self {
725 base,
726 compact,
727 medium,
728 } = *self;
729 match breakpoint {
730 Breakpoint::Compact => compact.unwrap_or(base),
731 Breakpoint::Medium => medium.unwrap_or(base),
732 Breakpoint::Expanded => base,
733 }
734 }
735}
736
737/// `StyleApply` implementation for `Display`.
738impl StyleApply for Display {
739 /// Applies `Display` to `style`.
740 ///
741 /// # Arguments
742 ///
743 /// - `Self` - Target display mode.
744 /// - `Style` - Style accumulator.
745 ///
746 /// # Returns
747 ///
748 /// - `Style` - Updated style.
749 fn apply_to(self, style: Style) -> Style {
750 style.display(self)
751 }
752}
753
754/// `StyleApply` implementation for `Position`.
755impl StyleApply for Position {
756 /// Applies `Position` to `style`.
757 ///
758 /// # Arguments
759 ///
760 /// - `Self` - Target positioning mode.
761 /// - `Style` - Style accumulator.
762 ///
763 /// # Returns
764 ///
765 /// - `Style` - Updated style.
766 fn apply_to(self, style: Style) -> Style {
767 style.position(self)
768 }
769}
770
771/// `StyleApply` implementation for `FlexDirection`.
772impl StyleApply for FlexDirection {
773 /// Applies `FlexDirection` to `style`.
774 ///
775 /// # Arguments
776 ///
777 /// - `Self` - Target flex axis direction.
778 /// - `Style` - Style accumulator.
779 ///
780 /// # Returns
781 ///
782 /// - `Style` - Updated style.
783 fn apply_to(self, style: Style) -> Style {
784 style.direction(self)
785 }
786}
787
788/// `StyleApply` implementation for `FlexWrap`.
789impl StyleApply for FlexWrap {
790 /// Applies `FlexWrap` to `style`.
791 ///
792 /// # Arguments
793 ///
794 /// - `Self` - Target flex wrap mode.
795 /// - `Style` - Style accumulator.
796 ///
797 /// # Returns
798 ///
799 /// - `Style` - Updated style.
800 fn apply_to(self, style: Style) -> Style {
801 style.wrap(self)
802 }
803}
804
805/// `StyleApply` implementation for `JustifyContent`.
806impl StyleApply for JustifyContent {
807 /// Applies `JustifyContent` to `style`.
808 ///
809 /// # Arguments
810 ///
811 /// - `Self` - Target main-axis justification.
812 /// - `Style` - Style accumulator.
813 ///
814 /// # Returns
815 ///
816 /// - `Style` - Updated style.
817 fn apply_to(self, style: Style) -> Style {
818 style.justify(self)
819 }
820}
821
822/// `StyleApply` implementation for `AlignItems`.
823impl StyleApply for AlignItems {
824 /// Applies `AlignItems` to `style`.
825 ///
826 /// # Arguments
827 ///
828 /// - `Self` - Target cross-axis alignment.
829 /// - `Style` - Style accumulator.
830 ///
831 /// # Returns
832 ///
833 /// - `Style` - Updated style.
834 fn apply_to(self, style: Style) -> Style {
835 style.align(self)
836 }
837}
838
839/// `StyleApply` implementation for `Overflow`.
840impl StyleApply for Overflow {
841 /// Applies `Overflow` to `style`.
842 ///
843 /// # Arguments
844 ///
845 /// - `Self` - Target overflow behavior.
846 /// - `Style` - Style accumulator.
847 ///
848 /// # Returns
849 ///
850 /// - `Style` - Updated style.
851 fn apply_to(self, style: Style) -> Style {
852 style.overflow(self)
853 }
854}
855
856/// `StyleApply` implementation for `CursorIcon`.
857impl StyleApply for CursorIcon {
858 /// Applies `CursorIcon` to `style`.
859 ///
860 /// # Arguments
861 ///
862 /// - `Self` - Target cursor hint.
863 /// - `Style` - Style accumulator.
864 ///
865 /// # Returns
866 ///
867 /// - `Style` - Updated style.
868 fn apply_to(self, style: Style) -> Style {
869 style.cursor(self)
870 }
871}
872
873/// `StyleApply` implementation for `PointerEvents`.
874impl StyleApply for PointerEvents {
875 /// Applies `PointerEvents` to `style`.
876 ///
877 /// # Arguments
878 ///
879 /// - `Self` - Target pointer-events mode.
880 /// - `Style` - Style accumulator.
881 ///
882 /// # Returns
883 ///
884 /// - `Style` - Updated style.
885 fn apply_to(self, style: Style) -> Style {
886 style.pointer_events(self)
887 }
888}
889
890/// `StyleApply` implementation for `FontWeight`.
891impl StyleApply for FontWeight {
892 /// Applies `FontWeight` to `style`.
893 ///
894 /// # Arguments
895 ///
896 /// - `Self` - Target font weight.
897 /// - `Style` - Style accumulator.
898 ///
899 /// # Returns
900 ///
901 /// - `Style` - Updated style.
902 fn apply_to(self, style: Style) -> Style {
903 style.font_weight(self)
904 }
905}
906
907/// `StyleApply` implementation for `FontFamily`.
908impl StyleApply for FontFamily {
909 /// Applies `FontFamily` to `style`.
910 ///
911 /// # Arguments
912 ///
913 /// - `Self` - Target font family.
914 /// - `Style` - Style accumulator.
915 ///
916 /// # Returns
917 ///
918 /// - `Style` - Updated style.
919 fn apply_to(self, style: Style) -> Style {
920 style.font_family(self)
921 }
922}
923
924/// `StyleApply` implementation for `TextAlign`.
925impl StyleApply for TextAlign {
926 /// Applies `TextAlign` to `style`.
927 ///
928 /// # Arguments
929 ///
930 /// - `Self` - Target horizontal text alignment.
931 /// - `Style` - Style accumulator.
932 ///
933 /// # Returns
934 ///
935 /// - `Style` - Updated style.
936 fn apply_to(self, style: Style) -> Style {
937 style.text_align(self)
938 }
939}
940
941/// `StyleApply` implementation for `TextOverflow`.
942impl StyleApply for TextOverflow {
943 /// Applies `TextOverflow` to `style`.
944 ///
945 /// # Arguments
946 ///
947 /// - `Self` - Target text overflow strategy.
948 /// - `Style` - Style accumulator.
949 ///
950 /// # Returns
951 ///
952 /// - `Style` - Updated style.
953 fn apply_to(self, style: Style) -> Style {
954 style.text_overflow(self)
955 }
956}
957
958/// `StyleApply` implementation for `Shadow`.
959impl StyleApply for Shadow {
960 /// Applies `Shadow` to `style`.
961 ///
962 /// # Arguments
963 ///
964 /// - `Self` - Drop shadow specification.
965 /// - `Style` - Style accumulator.
966 ///
967 /// # Returns
968 ///
969 /// - `Style` - Updated style.
970 fn apply_to(self, style: Style) -> Style {
971 style.shadow(self)
972 }
973}
974
975/// `StyleApply` implementation for `LinearGradient`.
976impl StyleApply for LinearGradient {
977 /// Applies `LinearGradient` to `style`.
978 ///
979 /// # Arguments
980 ///
981 /// - `Self` - Linear gradient fill.
982 /// - `Style` - Style accumulator.
983 ///
984 /// # Returns
985 ///
986 /// - `Style` - Updated style.
987 fn apply_to(self, style: Style) -> Style {
988 style.gradient(self)
989 }
990}
991
992/// `StyleApply` implementation for `CornerRadius`.
993impl StyleApply for CornerRadius {
994 /// Applies `CornerRadius` to `style`.
995 ///
996 /// # Arguments
997 ///
998 /// - `Self` - Corner radius specification.
999 /// - `Style` - Style accumulator.
1000 ///
1001 /// # Returns
1002 ///
1003 /// - `Style` - Updated style.
1004 fn apply_to(self, style: Style) -> Style {
1005 let mut out: Style = style;
1006 out.get_mut_paint().set_radius(self);
1007 out
1008 }
1009}
1010
1011/// `StyleApply` implementation for `Style` allowing base-style merging inside `style! { base_style; ... }`.
1012impl StyleApply for Style {
1013 /// Replaces `style` with `self` as a base preset inside `style!`.
1014 ///
1015 /// # Arguments
1016 ///
1017 /// - `Self` - Base style preset.
1018 /// - `Style` - Previous accumulator.
1019 ///
1020 /// # Returns
1021 ///
1022 /// - `Style` - Base style value.
1023 fn apply_to(self, _style: Style) -> Style {
1024 self
1025 }
1026}