Skip to main content

euv_core/style/sheet/
impl.rs

1use super::*;
2
3/// Fluent zero-allocation builder methods for `Style`.
4impl Style {
5    /// Returns a shared reference to the embedded `LayoutStyle` without copying by value.
6    ///
7    /// # Arguments
8    ///
9    /// - `&Self` - Style reference.
10    ///
11    /// # Returns
12    ///
13    /// - `&LayoutStyle` - Borrowed layout style reference.
14    #[must_use]
15    #[inline(always)]
16    pub fn layout_ref(&self) -> &LayoutStyle {
17        let Self { layout, .. } = self;
18        layout
19    }
20
21    /// Returns a shared reference to the embedded `PaintStyle` without copying by value.
22    ///
23    /// # Arguments
24    ///
25    /// - `&Self` - Style reference.
26    ///
27    /// # Returns
28    ///
29    /// - `&PaintStyle` - Borrowed paint style reference.
30    #[must_use]
31    #[inline(always)]
32    pub fn paint_ref(&self) -> &PaintStyle {
33        let Self { paint, .. } = self;
34        paint
35    }
36
37    /// Returns a shared reference to the embedded `TextStyle` without copying by value.
38    ///
39    /// # Arguments
40    ///
41    /// - `&Self` - Style reference.
42    ///
43    /// # Returns
44    ///
45    /// - `&TextStyle` - Borrowed typography style reference.
46    #[must_use]
47    #[inline(always)]
48    pub fn text_ref(&self) -> &TextStyle {
49        let Self { text, .. } = self;
50        text
51    }
52
53    /// Mutates the embedded `LayoutStyle` directly in place without copying `Style` by value.
54    ///
55    /// # Arguments
56    ///
57    /// - `&Self` - Mutable style reference.
58    /// - `CallbackFn` - In-place mutation closure receiving `&mut LayoutStyle`.
59    ///
60    /// # Returns
61    ///
62    /// - `&mut Self` - Mutable style reference for chaining.
63    #[inline(always)]
64    pub fn mutate_layout<CallbackFn>(&mut self, update: CallbackFn) -> &mut Self
65    where
66        CallbackFn: FnOnce(&mut LayoutStyle),
67    {
68        update(self.get_mut_layout());
69        self
70    }
71
72    /// Mutates the embedded `PaintStyle` directly in place without copying `Style` by value.
73    ///
74    /// # Arguments
75    ///
76    /// - `&Self` - Mutable style reference.
77    /// - `CallbackFn` - In-place mutation closure receiving `&mut PaintStyle`.
78    ///
79    /// # Returns
80    ///
81    /// - `&mut Self` - Mutable style reference for chaining.
82    #[inline(always)]
83    pub fn mutate_paint<CallbackFn>(&mut self, update: CallbackFn) -> &mut Self
84    where
85        CallbackFn: FnOnce(&mut PaintStyle),
86    {
87        update(self.get_mut_paint());
88        self
89    }
90
91    /// Mutates the embedded `TextStyle` directly in place without copying `Style` by value.
92    ///
93    /// # Arguments
94    ///
95    /// - `&Self` - Mutable style reference.
96    /// - `CallbackFn` - In-place mutation closure receiving `&mut TextStyle`.
97    ///
98    /// # Returns
99    ///
100    /// - `&mut Self` - Mutable style reference for chaining.
101    #[inline(always)]
102    pub fn mutate_text<CallbackFn>(&mut self, update: CallbackFn) -> &mut Self
103    where
104        CallbackFn: FnOnce(&mut TextStyle),
105    {
106        update(self.get_mut_text());
107        self
108    }
109
110    /// Sets the flex container axis direction directly in place without copying `Style`.
111    ///
112    /// # Arguments
113    ///
114    /// - `&Self` - Mutable style reference.
115    /// - `FlexDirection` - Target flex axis direction.
116    ///
117    /// # Returns
118    ///
119    /// - `&mut Self` - Mutable style reference for chaining.
120    #[inline(always)]
121    pub fn set_direction_in_place(&mut self, direction: FlexDirection) -> &mut Self {
122        let layout: &mut LayoutStyle = self.get_mut_layout();
123        if layout.get_display() != Display::None {
124            layout.set_display(Display::Flex);
125        }
126        layout.set_flex_direction(direction);
127        self
128    }
129
130    /// Configures a horizontal flex row directly in place without copying `Style`.
131    ///
132    /// # Arguments
133    ///
134    /// - `&Self` - Mutable style reference.
135    ///
136    /// # Returns
137    ///
138    /// - `&mut Self` - Mutable style reference for chaining.
139    #[inline(always)]
140    pub fn set_row_in_place(&mut self) -> &mut Self {
141        self.set_direction_in_place(FlexDirection::Row)
142    }
143
144    /// Configures a vertical flex column directly in place without copying `Style`.
145    ///
146    /// # Arguments
147    ///
148    /// - `&Self` - Mutable style reference.
149    ///
150    /// # Returns
151    ///
152    /// - `&mut Self` - Mutable style reference for chaining.
153    #[inline(always)]
154    pub fn set_column_in_place(&mut self) -> &mut Self {
155        self.set_direction_in_place(FlexDirection::Column)
156    }
157
158    /// Configures a grid layout directly in place without copying `Style`.
159    ///
160    /// # Arguments
161    ///
162    /// - `&Self` - Mutable style reference.
163    /// - `u16` - Number of grid columns (clamped to at least 1).
164    ///
165    /// # Returns
166    ///
167    /// - `&mut Self` - Mutable style reference for chaining.
168    #[inline(always)]
169    pub fn set_grid_in_place(&mut self, columns: u16) -> &mut Self {
170        let layout: &mut LayoutStyle = self.get_mut_layout();
171        if layout.get_display() != Display::None {
172            layout.set_display(Display::Grid);
173        }
174        layout.set_grid_columns(columns.max(1));
175        self
176    }
177
178    /// Sets uniform row and column gaps directly in place without copying `Style`.
179    ///
180    /// # Arguments
181    ///
182    /// - `&Self` - Mutable style reference.
183    /// - `f32` - Gap in logical pixels.
184    ///
185    /// # Returns
186    ///
187    /// - `&mut Self` - Mutable style reference for chaining.
188    #[inline(always)]
189    pub fn set_gap_in_place(&mut self, gap: f32) -> &mut Self {
190        let clamped: f32 = gap.max(0.0);
191        let layout: &mut LayoutStyle = self.get_mut_layout();
192        layout.set_row_gap(clamped);
193        layout.set_column_gap(clamped);
194        self
195    }
196
197    /// Sets solid background fill color directly in place without copying `Style`.
198    ///
199    /// # Arguments
200    ///
201    /// - `&Self` - Mutable style reference.
202    /// - `Color` - Background color.
203    ///
204    /// # Returns
205    ///
206    /// - `&mut Self` - Mutable style reference for chaining.
207    #[inline(always)]
208    pub fn set_background_in_place(&mut self, color: Color) -> &mut Self {
209        self.get_mut_paint().set_background(Some(color));
210        self
211    }
212
213    /// Sets border stroke width and color directly in place without copying `Style`.
214    ///
215    /// # Arguments
216    ///
217    /// - `&Self` - Mutable style reference.
218    /// - `f32` - Border width in logical pixels.
219    /// - `Color` - Border color.
220    ///
221    /// # Returns
222    ///
223    /// - `&mut Self` - Mutable style reference for chaining.
224    #[inline(always)]
225    pub fn set_border_in_place(&mut self, width: f32, color: Color) -> &mut Self {
226        self.get_mut_paint()
227            .set_border(Border::new(width.max(0.0), color));
228        self
229    }
230
231    /// Sets uniform corner radius directly in place without copying `Style`.
232    ///
233    /// # Arguments
234    ///
235    /// - `&Self` - Mutable style reference.
236    /// - `f32` - Corner radius in logical pixels.
237    ///
238    /// # Returns
239    ///
240    /// - `&mut Self` - Mutable style reference for chaining.
241    #[inline(always)]
242    pub fn set_radius_in_place(&mut self, radius: f32) -> &mut Self {
243        self.get_mut_paint()
244            .set_radius(CornerRadius::all(radius.max(0.0)));
245        self
246    }
247
248    /// Sets opacity in `[0.0, 1.0]` directly in place without copying `Style`.
249    ///
250    /// # Arguments
251    ///
252    /// - `&Self` - Mutable style reference.
253    /// - `f32` - Opacity factor.
254    ///
255    /// # Returns
256    ///
257    /// - `&mut Self` - Mutable style reference for chaining.
258    #[inline(always)]
259    pub fn set_opacity_in_place(&mut self, opacity: f32) -> &mut Self {
260        self.get_mut_paint().set_opacity(opacity.clamp(0.0, 1.0));
261        self
262    }
263
264    /// Sets foreground text color directly in place without copying `Style`.
265    ///
266    /// # Arguments
267    ///
268    /// - `&Self` - Mutable style reference.
269    /// - `Color` - Text color.
270    ///
271    /// # Returns
272    ///
273    /// - `&mut Self` - Mutable style reference for chaining.
274    #[inline(always)]
275    pub fn set_color_in_place(&mut self, color: Color) -> &mut Self {
276        self.get_mut_text().set_color(color);
277        self
278    }
279
280    /// Sets font size in logical pixels directly in place without copying `Style`.
281    ///
282    /// # Arguments
283    ///
284    /// - `&Self` - Mutable style reference.
285    /// - `f32` - Font size in pixels.
286    ///
287    /// # Returns
288    ///
289    /// - `&mut Self` - Mutable style reference for chaining.
290    #[inline(always)]
291    pub fn set_font_size_in_place(&mut self, size: f32) -> &mut Self {
292        self.get_mut_text().set_font_size(size.max(6.0));
293        self
294    }
295
296    /// Applies any strongly-typed `StyleApply` value (e.g. `AlignItems::Center`, `Overflow::Hidden`, `Shadow`) to this style.
297    ///
298    /// # Arguments
299    ///
300    /// - `Self` - Source style.
301    /// - `ValueType` - Typed property implementing `StyleApply`.
302    ///
303    /// # Returns
304    ///
305    /// - `Self` - Updated style.
306    #[must_use]
307    #[inline(always)]
308    pub fn apply<ValueType>(self, prop: ValueType) -> Self
309    where
310        ValueType: StyleApply,
311    {
312        prop.apply_to(self)
313    }
314
315    /// Sets the flex container axis direction (`FlexDirection::Row` or `FlexDirection::Column`).
316    ///
317    /// # Arguments
318    ///
319    /// - `Self` - Source style.
320    /// - `FlexDirection` - Target flex axis direction.
321    ///
322    /// # Returns
323    ///
324    /// - `Self` - Updated style.
325    #[must_use]
326    #[inline(always)]
327    pub fn direction(mut self, direction: FlexDirection) -> Self {
328        let _: &mut Self = self.set_direction_in_place(direction);
329        self
330    }
331
332    /// Sets the box display mode.
333    ///
334    /// # Arguments
335    ///
336    /// - `Self` - Source style.
337    /// - `Display` - Target display mode.
338    ///
339    /// # Returns
340    ///
341    /// - `Self` - Updated style.
342    #[must_use]
343    #[inline(always)]
344    pub fn display(mut self, display: Display) -> Self {
345        self.get_mut_layout().set_display(display);
346        self
347    }
348
349    /// Sets the positioning mode.
350    ///
351    /// # Arguments
352    ///
353    /// - `Self` - Source style.
354    /// - `Position` - Target position mode.
355    ///
356    /// # Returns
357    ///
358    /// - `Self` - Updated style.
359    #[must_use]
360    #[inline(always)]
361    pub fn position(mut self, position: Position) -> Self {
362        self.get_mut_layout().set_position(position);
363        self
364    }
365
366    /// Configures a horizontal flex row.
367    ///
368    /// # Arguments
369    ///
370    /// - `Self` - Source style.
371    ///
372    /// # Returns
373    ///
374    /// - `Self` - Updated style.
375    #[must_use]
376    #[inline(always)]
377    pub fn row(mut self) -> Self {
378        let _: &mut Self = self.set_row_in_place();
379        self
380    }
381
382    /// Configures a vertical flex column.
383    ///
384    /// # Arguments
385    ///
386    /// - `Self` - Source style.
387    ///
388    /// # Returns
389    ///
390    /// - `Self` - Updated style.
391    #[must_use]
392    #[inline(always)]
393    pub fn column(mut self) -> Self {
394        let _: &mut Self = self.set_column_in_place();
395        self
396    }
397
398    /// Configures a grid layout with `columns` equal-width columns.
399    ///
400    /// # Arguments
401    ///
402    /// - `Self` - Source style.
403    /// - `u16` - Number of grid columns (clamped to at least 1).
404    ///
405    /// # Returns
406    ///
407    /// - `Self` - Updated style.
408    #[must_use]
409    #[inline(always)]
410    pub fn grid(mut self, columns: u16) -> Self {
411        let _: &mut Self = self.set_grid_in_place(columns);
412        self
413    }
414
415    /// Sets flex wrapping behavior.
416    ///
417    /// # Arguments
418    ///
419    /// - `Self` - Source style.
420    /// - `FlexWrap` - Wrap mode.
421    ///
422    /// # Returns
423    ///
424    /// - `Self` - Updated style.
425    #[must_use]
426    #[inline(always)]
427    pub fn wrap(mut self, wrap: FlexWrap) -> Self {
428        self.get_mut_layout().set_flex_wrap(wrap);
429        self
430    }
431
432    /// Sets main-axis justification.
433    ///
434    /// # Arguments
435    ///
436    /// - `Self` - Source style.
437    /// - `JustifyContent` - Justification mode.
438    ///
439    /// # Returns
440    ///
441    /// - `Self` - Updated style.
442    #[must_use]
443    #[inline(always)]
444    pub fn justify(mut self, justify: JustifyContent) -> Self {
445        self.get_mut_layout().set_justify_content(justify);
446        self
447    }
448
449    /// Sets cross-axis alignment.
450    ///
451    /// # Arguments
452    ///
453    /// - `Self` - Source style.
454    /// - `AlignItems` - Cross-axis alignment.
455    ///
456    /// # Returns
457    ///
458    /// - `Self` - Updated style.
459    #[must_use]
460    #[inline(always)]
461    pub fn align(mut self, align: AlignItems) -> Self {
462        self.get_mut_layout().set_align_items(align);
463        self
464    }
465
466    /// Sets flex grow factor.
467    ///
468    /// # Arguments
469    ///
470    /// - `Self` - Source style.
471    /// - `f32` - Flex grow factor.
472    ///
473    /// # Returns
474    ///
475    /// - `Self` - Updated style.
476    #[must_use]
477    #[inline(always)]
478    pub fn flex_grow(mut self, grow: f32) -> Self {
479        self.get_mut_layout().set_flex_grow(grow.max(0.0));
480        self
481    }
482
483    /// Sets flex shrink factor.
484    ///
485    /// # Arguments
486    ///
487    /// - `Self` - Source style.
488    /// - `f32` - Flex shrink factor.
489    ///
490    /// # Returns
491    ///
492    /// - `Self` - Updated style.
493    #[must_use]
494    #[inline(always)]
495    pub fn flex_shrink(mut self, shrink: f32) -> Self {
496        self.get_mut_layout().set_flex_shrink(shrink.max(0.0));
497        self
498    }
499
500    /// Sets width length.
501    ///
502    /// # Arguments
503    ///
504    /// - `Self` - Source style.
505    /// - `Length` - Target width.
506    ///
507    /// # Returns
508    ///
509    /// - `Self` - Updated style.
510    #[must_use]
511    #[inline(always)]
512    pub fn width(mut self, width: Length) -> Self {
513        self.get_mut_layout().set_width(width);
514        self
515    }
516
517    /// Sets height length.
518    ///
519    /// # Arguments
520    ///
521    /// - `Self` - Source style.
522    /// - `Length` - Target height.
523    ///
524    /// # Returns
525    ///
526    /// - `Self` - Updated style.
527    #[must_use]
528    #[inline(always)]
529    pub fn height(mut self, height: Length) -> Self {
530        self.get_mut_layout().set_height(height);
531        self
532    }
533
534    /// Sets minimum width constraint.
535    ///
536    /// # Arguments
537    ///
538    /// - `Self` - Source style.
539    /// - `Length` - Minimum width.
540    ///
541    /// # Returns
542    ///
543    /// - `Self` - Updated style.
544    #[must_use]
545    #[inline(always)]
546    pub fn min_width(mut self, min_width: Length) -> Self {
547        self.get_mut_layout().set_min_width(min_width);
548        self
549    }
550
551    /// Sets minimum height constraint.
552    ///
553    /// # Arguments
554    ///
555    /// - `Self` - Source style.
556    /// - `Length` - Minimum height.
557    ///
558    /// # Returns
559    ///
560    /// - `Self` - Updated style.
561    #[must_use]
562    #[inline(always)]
563    pub fn min_height(mut self, min_height: Length) -> Self {
564        self.get_mut_layout().set_min_height(min_height);
565        self
566    }
567
568    /// Sets maximum width constraint.
569    ///
570    /// # Arguments
571    ///
572    /// - `Self` - Source style.
573    /// - `Length` - Maximum width.
574    ///
575    /// # Returns
576    ///
577    /// - `Self` - Updated style.
578    #[must_use]
579    #[inline(always)]
580    pub fn max_width(mut self, max_width: Length) -> Self {
581        self.get_mut_layout().set_max_width(max_width);
582        self
583    }
584
585    /// Sets maximum height constraint.
586    ///
587    /// # Arguments
588    ///
589    /// - `Self` - Source style.
590    /// - `Length` - Maximum height.
591    ///
592    /// # Returns
593    ///
594    /// - `Self` - Updated style.
595    #[must_use]
596    #[inline(always)]
597    pub fn max_height(mut self, max_height: Length) -> Self {
598        self.get_mut_layout().set_max_height(max_height);
599        self
600    }
601
602    /// Sets an explicit width-to-height aspect ratio constraint.
603    ///
604    /// # Arguments
605    ///
606    /// - `Self` - Source style.
607    /// - `f32` - Positive aspect ratio (`width / height`).
608    ///
609    /// # Returns
610    ///
611    /// - `Self` - Updated style.
612    #[must_use]
613    #[inline(always)]
614    pub fn aspect_ratio(mut self, ratio: f32) -> Self {
615        if ratio > 0.0 && ratio.is_finite() {
616            self.get_mut_layout().set_aspect_ratio(Some(ratio));
617        }
618        self
619    }
620
621    /// Sets uniform gap along both row and column axes.
622    ///
623    /// # Arguments
624    ///
625    /// - `Self` - Source style.
626    /// - `f32` - Gap in logical pixels.
627    ///
628    /// # Returns
629    ///
630    /// - `Self` - Updated style.
631    #[must_use]
632    #[inline(always)]
633    pub fn gap(mut self, gap: f32) -> Self {
634        let _: &mut Self = self.set_gap_in_place(gap);
635        self
636    }
637
638    /// Sets inner padding edges.
639    ///
640    /// # Arguments
641    ///
642    /// - `Self` - Source style.
643    /// - `Edges` - Inner padding insets.
644    ///
645    /// # Returns
646    ///
647    /// - `Self` - Updated style.
648    #[must_use]
649    #[inline(always)]
650    pub fn padding(mut self, padding: Edges) -> Self {
651        self.get_mut_layout().set_padding(padding);
652        self
653    }
654
655    /// Sets outer margin edges.
656    ///
657    /// # Arguments
658    ///
659    /// - `Self` - Source style.
660    /// - `Edges` - Outer margin insets.
661    ///
662    /// # Returns
663    ///
664    /// - `Self` - Updated style.
665    #[must_use]
666    #[inline(always)]
667    pub fn margin(mut self, margin: Edges) -> Self {
668        self.get_mut_layout().set_margin(margin);
669        self
670    }
671
672    /// Sets overflow behavior.
673    ///
674    /// # Arguments
675    ///
676    /// - `Self` - Source style.
677    /// - `Overflow` - Target overflow behavior.
678    ///
679    /// # Returns
680    ///
681    /// - `Self` - Updated style.
682    #[must_use]
683    #[inline(always)]
684    pub fn overflow(mut self, overflow: Overflow) -> Self {
685        self.get_mut_layout().set_overflow(overflow);
686        self
687    }
688
689    /// Sets stacking z-index.
690    ///
691    /// # Arguments
692    ///
693    /// - `Self` - Source style.
694    /// - `i32` - Stacking layer index.
695    ///
696    /// # Returns
697    ///
698    /// - `Self` - Updated style.
699    #[must_use]
700    #[inline(always)]
701    pub fn z_index(mut self, z_index: i32) -> Self {
702        self.get_mut_layout().set_z_index(z_index);
703        self
704    }
705
706    /// Sets absolute or fixed inset coordinates.
707    ///
708    /// # Arguments
709    ///
710    /// - `Self` - Source style.
711    /// - `Option<f32>` - Top offset.
712    /// - `Option<f32>` - Right offset.
713    /// - `Option<f32>` - Bottom offset.
714    /// - `Option<f32>` - Left offset.
715    ///
716    /// # Returns
717    ///
718    /// - `Self` - Updated style.
719    #[must_use]
720    #[inline(always)]
721    pub fn inset(
722        mut self,
723        top: Option<f32>,
724        right: Option<f32>,
725        bottom: Option<f32>,
726        left: Option<f32>,
727    ) -> Self {
728        self.get_mut_layout().set_top(top);
729        self.get_mut_layout().set_right(right);
730        self.get_mut_layout().set_bottom(bottom);
731        self.get_mut_layout().set_left(left);
732        self
733    }
734
735    /// Sets solid background fill color.
736    ///
737    /// # Arguments
738    ///
739    /// - `Self` - Source style.
740    /// - `Color` - Background color.
741    ///
742    /// # Returns
743    ///
744    /// - `Self` - Updated style.
745    #[must_use]
746    #[inline(always)]
747    pub fn background(mut self, color: Color) -> Self {
748        let _: &mut Self = self.set_background_in_place(color);
749        self
750    }
751
752    /// Sets linear gradient fill.
753    ///
754    /// # Arguments
755    ///
756    /// - `Self` - Source style.
757    /// - `LinearGradient` - Linear gradient specification.
758    ///
759    /// # Returns
760    ///
761    /// - `Self` - Updated style.
762    #[must_use]
763    #[inline(always)]
764    pub fn gradient(mut self, gradient: LinearGradient) -> Self {
765        self.get_mut_paint().set_gradient(Some(gradient));
766        self
767    }
768
769    /// Sets border stroke width and color.
770    ///
771    /// # Arguments
772    ///
773    /// - `Self` - Source style.
774    /// - `f32` - Border width in logical pixels.
775    /// - `Color` - Border color.
776    ///
777    /// # Returns
778    ///
779    /// - `Self` - Updated style.
780    #[must_use]
781    #[inline(always)]
782    pub fn border(mut self, width: f32, color: Color) -> Self {
783        let _: &mut Self = self.set_border_in_place(width, color);
784        self
785    }
786
787    /// Sets uniform corner radius.
788    ///
789    /// # Arguments
790    ///
791    /// - `Self` - Source style.
792    /// - `f32` - Corner radius in logical pixels.
793    ///
794    /// # Returns
795    ///
796    /// - `Self` - Updated style.
797    #[must_use]
798    #[inline(always)]
799    pub fn radius(mut self, radius: f32) -> Self {
800        let _: &mut Self = self.set_radius_in_place(radius);
801        self
802    }
803
804    /// Sets drop shadow.
805    ///
806    /// # Arguments
807    ///
808    /// - `Self` - Source style.
809    /// - `Shadow` - Shadow definition.
810    ///
811    /// # Returns
812    ///
813    /// - `Self` - Updated style.
814    #[must_use]
815    #[inline(always)]
816    pub fn shadow(mut self, shadow: Shadow) -> Self {
817        self.get_mut_paint().set_shadow(Some(shadow));
818        self
819    }
820
821    /// Sets focus ring stroke.
822    ///
823    /// # Arguments
824    ///
825    /// - `Self` - Source style.
826    /// - `Border` - Focus ring width and color.
827    ///
828    /// # Returns
829    ///
830    /// - `Self` - Updated style.
831    #[must_use]
832    #[inline(always)]
833    pub fn focus_ring(mut self, ring: Border) -> Self {
834        self.get_mut_paint().set_focus_ring(Some(ring));
835        self
836    }
837
838    /// Sets opacity in `[0.0, 1.0]`.
839    ///
840    /// # Arguments
841    ///
842    /// - `Self` - Source style.
843    /// - `f32` - Opacity factor.
844    ///
845    /// # Returns
846    ///
847    /// - `Self` - Updated style.
848    #[must_use]
849    #[inline(always)]
850    pub fn opacity(mut self, opacity: f32) -> Self {
851        let _: &mut Self = self.set_opacity_in_place(opacity);
852        self
853    }
854
855    /// Sets cursor icon hint.
856    ///
857    /// # Arguments
858    ///
859    /// - `Self` - Source style.
860    /// - `CursorIcon` - Target cursor icon.
861    ///
862    /// # Returns
863    ///
864    /// - `Self` - Updated style.
865    #[must_use]
866    #[inline(always)]
867    pub fn cursor(mut self, cursor: CursorIcon) -> Self {
868        self.get_mut_paint().set_cursor(cursor);
869        self
870    }
871
872    /// Sets pointer hit-test participation behavior.
873    ///
874    /// # Arguments
875    ///
876    /// - `Self` - Source style.
877    /// - `PointerEvents` - Target pointer-events mode.
878    ///
879    /// # Returns
880    ///
881    /// - `Self` - Updated style.
882    #[must_use]
883    #[inline(always)]
884    pub fn pointer_events(mut self, pointer_events: PointerEvents) -> Self {
885        self.get_mut_paint().set_pointer_events(pointer_events);
886        self
887    }
888
889    /// Sets foreground text color.
890    ///
891    /// # Arguments
892    ///
893    /// - `Self` - Source style.
894    /// - `Color` - Text color.
895    ///
896    /// # Returns
897    ///
898    /// - `Self` - Updated style.
899    #[must_use]
900    #[inline(always)]
901    pub fn color(mut self, color: Color) -> Self {
902        let _: &mut Self = self.set_color_in_place(color);
903        self
904    }
905
906    /// Sets font size in logical pixels.
907    ///
908    /// # Arguments
909    ///
910    /// - `Self` - Source style.
911    /// - `f32` - Font size in pixels.
912    ///
913    /// # Returns
914    ///
915    /// - `Self` - Updated style.
916    #[must_use]
917    #[inline(always)]
918    pub fn font_size(mut self, size: f32) -> Self {
919        let _: &mut Self = self.set_font_size_in_place(size);
920        self
921    }
922
923    /// Sets font weight.
924    ///
925    /// # Arguments
926    ///
927    /// - `Self` - Source style.
928    /// - `FontWeight` - Target font weight.
929    ///
930    /// # Returns
931    ///
932    /// - `Self` - Updated style.
933    #[must_use]
934    #[inline(always)]
935    pub fn font_weight(mut self, weight: FontWeight) -> Self {
936        self.get_mut_text().set_weight(weight);
937        self
938    }
939
940    /// Sets font family.
941    ///
942    /// # Arguments
943    ///
944    /// - `Self` - Source style.
945    /// - `FontFamily` - Semantic font family.
946    ///
947    /// # Returns
948    ///
949    /// - `Self` - Updated style.
950    #[must_use]
951    #[inline(always)]
952    pub fn font_family(mut self, family: FontFamily) -> Self {
953        self.get_mut_text().set_family(family);
954        self
955    }
956
957    /// Sets italic font slant.
958    ///
959    /// # Arguments
960    ///
961    /// - `Self` - Source style.
962    /// - `bool` - Whether italic slant is active.
963    ///
964    /// # Returns
965    ///
966    /// - `Self` - Updated style.
967    #[must_use]
968    #[inline(always)]
969    pub fn italic(mut self, italic: bool) -> Self {
970        self.get_mut_text().set_italic(italic);
971        self
972    }
973
974    /// Sets horizontal text alignment.
975    ///
976    /// # Arguments
977    ///
978    /// - `Self` - Source style.
979    /// - `TextAlign` - Text alignment.
980    ///
981    /// # Returns
982    ///
983    /// - `Self` - Updated style.
984    #[must_use]
985    #[inline(always)]
986    pub fn text_align(mut self, align: TextAlign) -> Self {
987        self.get_mut_text().set_align(align);
988        self
989    }
990
991    /// Sets text overflow behavior.
992    ///
993    /// # Arguments
994    ///
995    /// - `Self` - Source style.
996    /// - `TextOverflow` - Overflow strategy.
997    ///
998    /// # Returns
999    ///
1000    /// - `Self` - Updated style.
1001    #[must_use]
1002    #[inline(always)]
1003    pub fn text_overflow(mut self, overflow: TextOverflow) -> Self {
1004        self.get_mut_text().set_overflow(overflow);
1005        self
1006    }
1007
1008    /// Configures interactive text selection and copy mode on this node and its descendant text subtree.
1009    ///
1010    /// # Arguments
1011    ///
1012    /// - `Self` - Source style.
1013    /// - `TextSelectMode` - Selection mode (`None` disables and opts out, `SelectAndCopy` enables drag selection, `All` selects full block on click).
1014    ///
1015    /// # Returns
1016    ///
1017    /// - `Self` - Updated style.
1018    #[must_use]
1019    #[inline(always)]
1020    pub fn text_select(mut self, mode: TextSelectMode) -> Self {
1021        self.get_mut_text().set_text_select(Some(mode));
1022        self
1023    }
1024
1025    /// Enables or disables native text selection on this node and its descendant text subtree.
1026    ///
1027    /// # Arguments
1028    ///
1029    /// - `Self` - Source style.
1030    /// - `bool` - Whether native text selection is enabled (`true`) or explicitly disabled (`false`).
1031    ///
1032    /// # Returns
1033    ///
1034    /// - `Self` - Updated style.
1035    #[must_use]
1036    #[inline(always)]
1037    pub fn selectable(self, selectable: bool) -> Self {
1038        let mode: TextSelectMode = if selectable {
1039            TextSelectMode::SelectAndCopy
1040        } else {
1041            TextSelectMode::None
1042        };
1043        self.text_select(mode)
1044    }
1045
1046    /// Sets the translucent highlight fill color used when rendering selected text ranges.
1047    ///
1048    /// # Arguments
1049    ///
1050    /// - `Self` - Source style.
1051    /// - `Color` - Selection highlight color.
1052    ///
1053    /// # Returns
1054    ///
1055    /// - `Self` - Updated style.
1056    #[must_use]
1057    #[inline(always)]
1058    pub fn selection_color(mut self, color: Color) -> Self {
1059        self.get_mut_text().set_selection_color(Some(color));
1060        self
1061    }
1062
1063    /// Configures whether scroll deltas stop at this node (`true`) or chain/penetrate to parent scrollables (`false`).
1064    ///
1065    /// # Arguments
1066    ///
1067    /// - `Self` - Source style.
1068    /// - `bool` - `true` blocks scroll penetration to ancestors; `false` permits scroll chaining.
1069    ///
1070    /// # Returns
1071    ///
1072    /// - `Self` - Updated style.
1073    #[must_use]
1074    #[inline(always)]
1075    pub fn stop_scroll_propagation(mut self, stop: bool) -> Self {
1076        self.get_mut_paint().set_stop_scroll_propagation(stop);
1077        self
1078    }
1079
1080    /// Configures whether click/pointer events stop bubbling at this node (`true`) or bubble to ancestors (`false`).
1081    ///
1082    /// # Arguments
1083    ///
1084    /// - `Self` - Source style.
1085    /// - `bool` - `true` blocks event bubbling; `false` permits bubbling.
1086    ///
1087    /// # Returns
1088    ///
1089    /// - `Self` - Updated style.
1090    #[must_use]
1091    #[inline(always)]
1092    pub fn stop_event_propagation(mut self, stop: bool) -> Self {
1093        self.get_mut_paint().set_stop_event_propagation(stop);
1094        self
1095    }
1096
1097    /// Merges all non-default layout, paint, and text properties from `overrides` onto `self`.
1098    ///
1099    /// # Arguments
1100    ///
1101    /// - `Self` - Base component or element style.
1102    /// - `&Self` - Override style whose non-default fields replace base fields.
1103    ///
1104    /// # Returns
1105    ///
1106    /// - `Self` - Combined style with overrides applied.
1107    #[must_use]
1108    pub fn merge_overrides(mut self, overrides: &Self) -> Self {
1109        let def: Self = Self::default();
1110        let ol: LayoutStyle = overrides.get_layout();
1111        let layout_style: LayoutStyle = def.get_layout();
1112        let ml: &mut LayoutStyle = self.get_mut_layout();
1113        if ol.get_display() != layout_style.get_display() {
1114            let _: &mut LayoutStyle = ml.set_display(ol.get_display());
1115        }
1116        if ol.get_position() != layout_style.get_position() {
1117            let _: &mut LayoutStyle = ml.set_position(ol.get_position());
1118        }
1119        if ol.get_flex_direction() != layout_style.get_flex_direction() {
1120            let _: &mut LayoutStyle = ml.set_flex_direction(ol.get_flex_direction());
1121        }
1122        if ol.get_flex_wrap() != layout_style.get_flex_wrap() {
1123            let _: &mut LayoutStyle = ml.set_flex_wrap(ol.get_flex_wrap());
1124        }
1125        if ol.get_justify_content() != layout_style.get_justify_content() {
1126            let _: &mut LayoutStyle = ml.set_justify_content(ol.get_justify_content());
1127        }
1128        if ol.get_align_items() != layout_style.get_align_items() {
1129            let _: &mut LayoutStyle = ml.set_align_items(ol.get_align_items());
1130        }
1131        if ol.get_align_self() != layout_style.get_align_self() {
1132            let _: &mut LayoutStyle = ml.set_align_self(ol.get_align_self());
1133        }
1134        if ol.get_overflow() != layout_style.get_overflow() {
1135            let _: &mut LayoutStyle = ml.set_overflow(ol.get_overflow());
1136        }
1137        if ol.get_flex_basis() != layout_style.get_flex_basis() {
1138            let _: &mut LayoutStyle = ml.set_flex_basis(ol.get_flex_basis());
1139        }
1140        if ol.get_width() != layout_style.get_width() {
1141            let _: &mut LayoutStyle = ml.set_width(ol.get_width());
1142        }
1143        if ol.get_height() != layout_style.get_height() {
1144            let _: &mut LayoutStyle = ml.set_height(ol.get_height());
1145        }
1146        if ol.get_min_width() != layout_style.get_min_width() {
1147            let _: &mut LayoutStyle = ml.set_min_width(ol.get_min_width());
1148        }
1149        if ol.get_min_height() != layout_style.get_min_height() {
1150            let _: &mut LayoutStyle = ml.set_min_height(ol.get_min_height());
1151        }
1152        if ol.get_max_width() != layout_style.get_max_width() {
1153            let _: &mut LayoutStyle = ml.set_max_width(ol.get_max_width());
1154        }
1155        if ol.get_max_height() != layout_style.get_max_height() {
1156            let _: &mut LayoutStyle = ml.set_max_height(ol.get_max_height());
1157        }
1158        if ol.get_flex_grow() != layout_style.get_flex_grow() {
1159            let _: &mut LayoutStyle = ml.set_flex_grow(ol.get_flex_grow());
1160        }
1161        if ol.get_flex_shrink() != layout_style.get_flex_shrink() {
1162            let _: &mut LayoutStyle = ml.set_flex_shrink(ol.get_flex_shrink());
1163        }
1164        if ol.get_margin() != layout_style.get_margin() {
1165            let _: &mut LayoutStyle = ml.set_margin(ol.get_margin());
1166        }
1167        if ol.get_padding() != layout_style.get_padding() {
1168            let _: &mut LayoutStyle = ml.set_padding(ol.get_padding());
1169        }
1170        if ol.get_row_gap() != layout_style.get_row_gap() {
1171            let _: &mut LayoutStyle = ml.set_row_gap(ol.get_row_gap());
1172        }
1173        if ol.get_column_gap() != layout_style.get_column_gap() {
1174            let _: &mut LayoutStyle = ml.set_column_gap(ol.get_column_gap());
1175        }
1176        if let Some(top) = ol.top_offset() {
1177            let _: &mut LayoutStyle = ml.set_top(Some(top));
1178        }
1179        if let Some(right) = ol.right_offset() {
1180            let _: &mut LayoutStyle = ml.set_right(Some(right));
1181        }
1182        if let Some(bottom) = ol.bottom_offset() {
1183            let _: &mut LayoutStyle = ml.set_bottom(Some(bottom));
1184        }
1185        if let Some(left) = ol.left_offset() {
1186            let _: &mut LayoutStyle = ml.set_left(Some(left));
1187        }
1188        if let Some(ratio) = ol.aspect_ratio_value() {
1189            let _: &mut LayoutStyle = ml.set_aspect_ratio(Some(ratio));
1190        }
1191        if ol.get_z_index() != layout_style.get_z_index() {
1192            let _: &mut LayoutStyle = ml.set_z_index(ol.get_z_index());
1193        }
1194        if ol.get_grid_columns() != layout_style.get_grid_columns() {
1195            let _: &mut LayoutStyle = ml.set_grid_columns(ol.get_grid_columns());
1196        }
1197        let op: PaintStyle = overrides.get_paint();
1198        let dp: PaintStyle = def.get_paint();
1199        let mp: &mut PaintStyle = self.get_mut_paint();
1200        if let Some(bg) = op.background_color() {
1201            let _: &mut PaintStyle = mp.set_background(Some(bg));
1202        }
1203        if let Some(grad) = op.background_gradient() {
1204            let _: &mut PaintStyle = mp.set_gradient(Some(grad));
1205        }
1206        if op.get_border() != dp.get_border() {
1207            let _: &mut PaintStyle = mp.set_border(op.get_border());
1208        }
1209        if op.get_radius() != dp.get_radius() {
1210            let _: &mut PaintStyle = mp.set_radius(op.get_radius());
1211        }
1212        if let Some(shadow) = op.box_shadow() {
1213            let _: &mut PaintStyle = mp.set_shadow(Some(shadow));
1214        }
1215        if let Some(ring) = op.focus_ring_border() {
1216            let _: &mut PaintStyle = mp.set_focus_ring(Some(ring));
1217        }
1218        if op.get_opacity() != dp.get_opacity() {
1219            let _: &mut PaintStyle = mp.set_opacity(op.get_opacity());
1220        }
1221        if op.get_transform() != dp.get_transform() {
1222            let _: &mut PaintStyle = mp.set_transform(op.get_transform());
1223        }
1224        if op.get_cursor() != dp.get_cursor() {
1225            let _: &mut PaintStyle = mp.set_cursor(op.get_cursor());
1226        }
1227        if op.get_pointer_events() != dp.get_pointer_events() {
1228            let _: &mut PaintStyle = mp.set_pointer_events(op.get_pointer_events());
1229        }
1230        if op.get_stop_scroll_propagation() != dp.get_stop_scroll_propagation() {
1231            let _: &mut PaintStyle =
1232                mp.set_stop_scroll_propagation(op.get_stop_scroll_propagation());
1233        }
1234        if op.get_stop_event_propagation() != dp.get_stop_event_propagation() {
1235            let _: &mut PaintStyle = mp.set_stop_event_propagation(op.get_stop_event_propagation());
1236        }
1237        let ot: TextStyle = overrides.get_text();
1238        let dt: TextStyle = def.get_text();
1239        let mt: &mut TextStyle = self.get_mut_text();
1240        if ot.get_family() != dt.get_family() {
1241            let _: &mut TextStyle = mt.set_family(ot.get_family());
1242        }
1243        if ot.get_font_size() != dt.get_font_size() {
1244            let _: &mut TextStyle = mt.set_font_size(ot.get_font_size());
1245        }
1246        if ot.get_weight() != dt.get_weight() {
1247            let _: &mut TextStyle = mt.set_weight(ot.get_weight());
1248        }
1249        if ot.get_line_height() != dt.get_line_height() {
1250            let _: &mut TextStyle = mt.set_line_height(ot.get_line_height());
1251        }
1252        if ot.get_letter_spacing() != dt.get_letter_spacing() {
1253            let _: &mut TextStyle = mt.set_letter_spacing(ot.get_letter_spacing());
1254        }
1255        if ot.get_align() != dt.get_align() {
1256            let _: &mut TextStyle = mt.set_align(ot.get_align());
1257        }
1258        if ot.get_overflow() != dt.get_overflow() {
1259            let _: &mut TextStyle = mt.set_overflow(ot.get_overflow());
1260        }
1261        if ot.get_color() != dt.get_color() {
1262            let _: &mut TextStyle = mt.set_color(ot.get_color());
1263        }
1264        if ot.get_italic() != dt.get_italic() {
1265            let _: &mut TextStyle = mt.set_italic(ot.get_italic());
1266        }
1267        if ot.get_underline() != dt.get_underline() {
1268            let _: &mut TextStyle = mt.set_underline(ot.get_underline());
1269        }
1270        if ot.get_strikethrough() != dt.get_strikethrough() {
1271            let _: &mut TextStyle = mt.set_strikethrough(ot.get_strikethrough());
1272        }
1273        if let Some(mode) = ot.text_select_mode() {
1274            let _: &mut TextStyle = mt.set_text_select(Some(mode));
1275        }
1276        if let Some(sel_color) = ot.selection_color() {
1277            let _: &mut TextStyle = mt.set_selection_color(Some(sel_color));
1278        }
1279        self
1280    }
1281
1282    /// Applies an optional override `Style` on top of `self` when present.
1283    ///
1284    /// # Arguments
1285    ///
1286    /// - `Self` - Base style.
1287    /// - `Option<Self>` - Optional override style.
1288    ///
1289    /// # Returns
1290    ///
1291    /// - `Self` - Combined style if `overrides` is `Some`, otherwise `self`.
1292    #[must_use]
1293    #[inline(always)]
1294    pub fn with_overrides(self, overrides: Option<Self>) -> Self {
1295        match overrides {
1296            Some(extra) => self.merge_overrides(&extra),
1297            None => self,
1298        }
1299    }
1300}
1301
1302/// Resolution helpers for `ResponsiveStyle`.
1303impl ResponsiveStyle {
1304    /// Resolves the active `Style` for the supplied `Breakpoint`.
1305    ///
1306    /// # Arguments
1307    ///
1308    /// - `&Self` - Responsive style definition.
1309    /// - `Breakpoint` - Current viewport breakpoint.
1310    ///
1311    /// # Returns
1312    ///
1313    /// - `Style` - Resolved concrete style.
1314    #[must_use]
1315    #[inline(always)]
1316    pub fn resolve(&self, breakpoint: Breakpoint) -> Style {
1317        let Self {
1318            base,
1319            compact,
1320            medium,
1321        } = *self;
1322        match breakpoint {
1323            Breakpoint::Compact => compact.unwrap_or(base),
1324            Breakpoint::Medium => medium.unwrap_or(base),
1325            Breakpoint::Expanded => base,
1326        }
1327    }
1328}
1329
1330/// `StyleApply` implementation for `Display`.
1331impl StyleApply for Display {
1332    /// Applies `Display` directly in place onto `style`.
1333    ///
1334    /// # Arguments
1335    ///
1336    /// - `Self` - Target display mode.
1337    /// - `&mut Style` - Style accumulator mutated in place.
1338    #[inline(always)]
1339    fn apply_in_place(self, style: &mut Style) {
1340        let _: &mut LayoutStyle = style.get_mut_layout().set_display(self);
1341    }
1342}
1343
1344/// `StyleApply` implementation for `Position`.
1345impl StyleApply for Position {
1346    /// Applies `Position` directly in place onto `style`.
1347    ///
1348    /// # Arguments
1349    ///
1350    /// - `Self` - Target positioning mode.
1351    /// - `&mut Style` - Style accumulator mutated in place.
1352    #[inline(always)]
1353    fn apply_in_place(self, style: &mut Style) {
1354        let _: &mut LayoutStyle = style.get_mut_layout().set_position(self);
1355    }
1356}
1357
1358/// `StyleApply` implementation for `FlexDirection`.
1359impl StyleApply for FlexDirection {
1360    /// Applies `FlexDirection` directly in place onto `style`.
1361    ///
1362    /// # Arguments
1363    ///
1364    /// - `Self` - Target flex axis direction.
1365    /// - `&mut Style` - Style accumulator mutated in place.
1366    #[inline(always)]
1367    fn apply_in_place(self, style: &mut Style) {
1368        let _: &mut Style = style.set_direction_in_place(self);
1369    }
1370}
1371
1372/// `StyleApply` implementation for `FlexWrap`.
1373impl StyleApply for FlexWrap {
1374    /// Applies `FlexWrap` directly in place onto `style`.
1375    ///
1376    /// # Arguments
1377    ///
1378    /// - `Self` - Target flex wrap mode.
1379    /// - `&mut Style` - Style accumulator mutated in place.
1380    #[inline(always)]
1381    fn apply_in_place(self, style: &mut Style) {
1382        let _: &mut LayoutStyle = style.get_mut_layout().set_flex_wrap(self);
1383    }
1384}
1385
1386/// `StyleApply` implementation for `JustifyContent`.
1387impl StyleApply for JustifyContent {
1388    /// Applies `JustifyContent` directly in place onto `style`.
1389    ///
1390    /// # Arguments
1391    ///
1392    /// - `Self` - Target main-axis justification.
1393    /// - `&mut Style` - Style accumulator mutated in place.
1394    #[inline(always)]
1395    fn apply_in_place(self, style: &mut Style) {
1396        let _: &mut LayoutStyle = style.get_mut_layout().set_justify_content(self);
1397    }
1398}
1399
1400/// `StyleApply` implementation for `AlignItems`.
1401impl StyleApply for AlignItems {
1402    /// Applies `AlignItems` directly in place onto `style`.
1403    ///
1404    /// # Arguments
1405    ///
1406    /// - `Self` - Target cross-axis alignment.
1407    /// - `&mut Style` - Style accumulator mutated in place.
1408    #[inline(always)]
1409    fn apply_in_place(self, style: &mut Style) {
1410        let _: &mut LayoutStyle = style.get_mut_layout().set_align_items(self);
1411    }
1412}
1413
1414/// `StyleApply` implementation for `AlignSelf`.
1415impl StyleApply for AlignSelf {
1416    /// Applies `AlignSelf` directly in place onto `style`.
1417    ///
1418    /// # Arguments
1419    ///
1420    /// - `Self` - Target self alignment override.
1421    /// - `&mut Style` - Style accumulator mutated in place.
1422    #[inline(always)]
1423    fn apply_in_place(self, style: &mut Style) {
1424        let _: &mut LayoutStyle = style.get_mut_layout().set_align_self(self);
1425    }
1426}
1427
1428/// `StyleApply` implementation for `Overflow`.
1429impl StyleApply for Overflow {
1430    /// Applies `Overflow` directly in place onto `style`.
1431    ///
1432    /// # Arguments
1433    ///
1434    /// - `Self` - Target overflow behavior.
1435    /// - `&mut Style` - Style accumulator mutated in place.
1436    #[inline(always)]
1437    fn apply_in_place(self, style: &mut Style) {
1438        let _: &mut LayoutStyle = style.get_mut_layout().set_overflow(self);
1439    }
1440}
1441
1442/// `StyleApply` implementation for `CursorIcon`.
1443impl StyleApply for CursorIcon {
1444    /// Applies `CursorIcon` directly in place onto `style`.
1445    ///
1446    /// # Arguments
1447    ///
1448    /// - `Self` - Target cursor hint.
1449    /// - `&mut Style` - Style accumulator mutated in place.
1450    #[inline(always)]
1451    fn apply_in_place(self, style: &mut Style) {
1452        let _: &mut PaintStyle = style.get_mut_paint().set_cursor(self);
1453    }
1454}
1455
1456/// `StyleApply` implementation for `PointerEvents`.
1457impl StyleApply for PointerEvents {
1458    /// Applies `PointerEvents` directly in place onto `style`.
1459    ///
1460    /// # Arguments
1461    ///
1462    /// - `Self` - Target pointer-events mode.
1463    /// - `&mut Style` - Style accumulator mutated in place.
1464    #[inline(always)]
1465    fn apply_in_place(self, style: &mut Style) {
1466        let _: &mut PaintStyle = style.get_mut_paint().set_pointer_events(self);
1467    }
1468}
1469
1470/// `StyleApply` implementation for `FontWeight`.
1471impl StyleApply for FontWeight {
1472    /// Applies `FontWeight` directly in place onto `style`.
1473    ///
1474    /// # Arguments
1475    ///
1476    /// - `Self` - Target font weight.
1477    /// - `&mut Style` - Style accumulator mutated in place.
1478    #[inline(always)]
1479    fn apply_in_place(self, style: &mut Style) {
1480        let _: &mut TextStyle = style.get_mut_text().set_weight(self);
1481    }
1482}
1483
1484/// `StyleApply` implementation for `FontFamily`.
1485impl StyleApply for FontFamily {
1486    /// Applies `FontFamily` directly in place onto `style`.
1487    ///
1488    /// # Arguments
1489    ///
1490    /// - `Self` - Target font family.
1491    /// - `&mut Style` - Style accumulator mutated in place.
1492    #[inline(always)]
1493    fn apply_in_place(self, style: &mut Style) {
1494        let _: &mut TextStyle = style.get_mut_text().set_family(self);
1495    }
1496}
1497
1498/// `StyleApply` implementation for `TextAlign`.
1499impl StyleApply for TextAlign {
1500    /// Applies `TextAlign` directly in place onto `style`.
1501    ///
1502    /// # Arguments
1503    ///
1504    /// - `Self` - Target horizontal text alignment.
1505    /// - `&mut Style` - Style accumulator mutated in place.
1506    #[inline(always)]
1507    fn apply_in_place(self, style: &mut Style) {
1508        let _: &mut TextStyle = style.get_mut_text().set_align(self);
1509    }
1510}
1511
1512/// `StyleApply` implementation for `TextOverflow`.
1513impl StyleApply for TextOverflow {
1514    /// Applies `TextOverflow` directly in place onto `style`.
1515    ///
1516    /// # Arguments
1517    ///
1518    /// - `Self` - Target text overflow strategy.
1519    /// - `&mut Style` - Style accumulator mutated in place.
1520    #[inline(always)]
1521    fn apply_in_place(self, style: &mut Style) {
1522        let _: &mut TextStyle = style.get_mut_text().set_overflow(self);
1523    }
1524}
1525
1526/// `StyleApply` implementation for `TextSelectMode`.
1527impl StyleApply for TextSelectMode {
1528    /// Applies `TextSelectMode` directly in place onto `style`.
1529    ///
1530    /// # Arguments
1531    ///
1532    /// - `Self` - Target text selection mode.
1533    /// - `&mut Style` - Style accumulator mutated in place.
1534    #[inline(always)]
1535    fn apply_in_place(self, style: &mut Style) {
1536        let _: &mut TextStyle = style.get_mut_text().set_text_select(Some(self));
1537    }
1538}
1539
1540/// `StyleApply` implementation for `Border`.
1541impl StyleApply for Border {
1542    /// Applies `Border` directly in place onto `style`.
1543    ///
1544    /// # Arguments
1545    ///
1546    /// - `Self` - Stroke width and color.
1547    /// - `&mut Style` - Style accumulator mutated in place.
1548    #[inline(always)]
1549    fn apply_in_place(self, style: &mut Style) {
1550        let _: &mut PaintStyle = style.get_mut_paint().set_border(self);
1551    }
1552}
1553
1554/// `StyleApply` implementation for `Shadow`.
1555impl StyleApply for Shadow {
1556    /// Applies `Shadow` directly in place onto `style`.
1557    ///
1558    /// # Arguments
1559    ///
1560    /// - `Self` - Drop shadow specification.
1561    /// - `&mut Style` - Style accumulator mutated in place.
1562    #[inline(always)]
1563    fn apply_in_place(self, style: &mut Style) {
1564        let _: &mut PaintStyle = style.get_mut_paint().set_shadow(Some(self));
1565    }
1566}
1567
1568/// `StyleApply` implementation for `LinearGradient`.
1569impl StyleApply for LinearGradient {
1570    /// Applies `LinearGradient` directly in place onto `style`.
1571    ///
1572    /// # Arguments
1573    ///
1574    /// - `Self` - Linear gradient fill.
1575    /// - `&mut Style` - Style accumulator mutated in place.
1576    #[inline(always)]
1577    fn apply_in_place(self, style: &mut Style) {
1578        let _: &mut PaintStyle = style.get_mut_paint().set_gradient(Some(self));
1579    }
1580}
1581
1582/// `StyleApply` implementation for `CornerRadius`.
1583impl StyleApply for CornerRadius {
1584    /// Applies `CornerRadius` directly in place onto `style`.
1585    ///
1586    /// # Arguments
1587    ///
1588    /// - `Self` - Corner radius specification.
1589    /// - `&mut Style` - Style accumulator mutated in place.
1590    #[inline(always)]
1591    fn apply_in_place(self, style: &mut Style) {
1592        let _: &mut PaintStyle = style.get_mut_paint().set_radius(self);
1593    }
1594}
1595
1596/// `StyleApply` implementation for `Transform2D`.
1597impl StyleApply for Transform2D {
1598    /// Applies `Transform2D` directly in place onto `style`.
1599    ///
1600    /// # Arguments
1601    ///
1602    /// - `Self` - 2D affine transform.
1603    /// - `&mut Style` - Style accumulator mutated in place.
1604    #[inline(always)]
1605    fn apply_in_place(self, style: &mut Style) {
1606        let _: &mut PaintStyle = style.get_mut_paint().set_transform(self);
1607    }
1608}
1609
1610/// `StyleApply` implementation for `Style` allowing base-style presets inside `style!` blocks.
1611impl StyleApply for Style {
1612    /// Replaces `style` in place with `self` as a base preset inside `style!`.
1613    ///
1614    /// # Arguments
1615    ///
1616    /// - `Self` - Base style preset.
1617    /// - `&mut Style` - Style accumulator overwritten in place.
1618    #[inline(always)]
1619    fn apply_in_place(self, style: &mut Style) {
1620        *style = self;
1621    }
1622
1623    /// Returns `self` directly as the initial `Style` without allocating or zeroing `Style::default()`.
1624    ///
1625    /// # Arguments
1626    ///
1627    /// - `Self` - Base style preset.
1628    ///
1629    /// # Returns
1630    ///
1631    /// - `Style` - Unmodified base style.
1632    #[inline(always)]
1633    fn into_base_style(self) -> Style {
1634        self
1635    }
1636}
1637
1638/// `StyleApply` implementation for `Option<Style>` merging optional component style overrides inside `style!`.
1639impl StyleApply for Option<Style> {
1640    /// Merges `Some(overrides)` onto `style` in place when present.
1641    ///
1642    /// # Arguments
1643    ///
1644    /// - `Self` - Optional override style.
1645    /// - `&mut Style` - Style accumulator mutated in place.
1646    #[inline(always)]
1647    fn apply_in_place(self, style: &mut Style) {
1648        if let Some(extra) = self {
1649            *style = (*style).merge_overrides(&extra);
1650        }
1651    }
1652}
1653
1654/// `StyleApply` implementation for `Width`.
1655impl StyleApply for Width {
1656    /// Applies `Width` directly in place onto `style`.
1657    ///
1658    /// # Arguments
1659    ///
1660    /// - `Self` - Target width wrapper.
1661    /// - `&mut Style` - Style accumulator mutated in place.
1662    #[inline(always)]
1663    fn apply_in_place(self, style: &mut Style) {
1664        let _: &mut LayoutStyle = style.get_mut_layout().set_width(self.0);
1665    }
1666}
1667
1668/// `StyleApply` implementation for `Height`.
1669impl StyleApply for Height {
1670    /// Applies `Height` directly in place onto `style`.
1671    ///
1672    /// # Arguments
1673    ///
1674    /// - `Self` - Target height wrapper.
1675    /// - `&mut Style` - Style accumulator mutated in place.
1676    #[inline(always)]
1677    fn apply_in_place(self, style: &mut Style) {
1678        let _: &mut LayoutStyle = style.get_mut_layout().set_height(self.0);
1679    }
1680}
1681
1682/// `StyleApply` implementation for `MinWidth`.
1683impl StyleApply for MinWidth {
1684    /// Applies `MinWidth` directly in place onto `style`.
1685    ///
1686    /// # Arguments
1687    ///
1688    /// - `Self` - Minimum width wrapper.
1689    /// - `&mut Style` - Style accumulator mutated in place.
1690    #[inline(always)]
1691    fn apply_in_place(self, style: &mut Style) {
1692        let _: &mut LayoutStyle = style.get_mut_layout().set_min_width(self.0);
1693    }
1694}
1695
1696/// `StyleApply` implementation for `MinHeight`.
1697impl StyleApply for MinHeight {
1698    /// Applies `MinHeight` directly in place onto `style`.
1699    ///
1700    /// # Arguments
1701    ///
1702    /// - `Self` - Minimum height wrapper.
1703    /// - `&mut Style` - Style accumulator mutated in place.
1704    #[inline(always)]
1705    fn apply_in_place(self, style: &mut Style) {
1706        let _: &mut LayoutStyle = style.get_mut_layout().set_min_height(self.0);
1707    }
1708}
1709
1710/// `StyleApply` implementation for `MaxWidth`.
1711impl StyleApply for MaxWidth {
1712    /// Applies `MaxWidth` directly in place onto `style`.
1713    ///
1714    /// # Arguments
1715    ///
1716    /// - `Self` - Maximum width wrapper.
1717    /// - `&mut Style` - Style accumulator mutated in place.
1718    #[inline(always)]
1719    fn apply_in_place(self, style: &mut Style) {
1720        let _: &mut LayoutStyle = style.get_mut_layout().set_max_width(self.0);
1721    }
1722}
1723
1724/// `StyleApply` implementation for `MaxHeight`.
1725impl StyleApply for MaxHeight {
1726    /// Applies `MaxHeight` directly in place onto `style`.
1727    ///
1728    /// # Arguments
1729    ///
1730    /// - `Self` - Maximum height wrapper.
1731    /// - `&mut Style` - Style accumulator mutated in place.
1732    #[inline(always)]
1733    fn apply_in_place(self, style: &mut Style) {
1734        let _: &mut LayoutStyle = style.get_mut_layout().set_max_height(self.0);
1735    }
1736}
1737
1738/// `StyleApply` implementation for `FlexBasis`.
1739impl StyleApply for FlexBasis {
1740    /// Applies `FlexBasis` directly in place onto `style`.
1741    ///
1742    /// # Arguments
1743    ///
1744    /// - `Self` - Flex basis length wrapper.
1745    /// - `&mut Style` - Style accumulator mutated in place.
1746    #[inline(always)]
1747    fn apply_in_place(self, style: &mut Style) {
1748        let _: &mut LayoutStyle = style.get_mut_layout().set_flex_basis(self.0);
1749    }
1750}
1751
1752/// `StyleApply` implementation for `AspectRatio`.
1753impl StyleApply for AspectRatio {
1754    /// Applies `AspectRatio` directly in place onto `style`.
1755    ///
1756    /// # Arguments
1757    ///
1758    /// - `Self` - Positive aspect ratio wrapper.
1759    /// - `&mut Style` - Style accumulator mutated in place.
1760    #[inline(always)]
1761    fn apply_in_place(self, style: &mut Style) {
1762        if self.0 > 0.0 && self.0.is_finite() {
1763            let _: &mut LayoutStyle = style.get_mut_layout().set_aspect_ratio(Some(self.0));
1764        }
1765    }
1766}
1767
1768/// `StyleApply` implementation for `Padding`.
1769impl StyleApply for Padding {
1770    /// Applies `Padding` directly in place onto `style`.
1771    ///
1772    /// # Arguments
1773    ///
1774    /// - `Self` - Inner padding wrapper.
1775    /// - `&mut Style` - Style accumulator mutated in place.
1776    #[inline(always)]
1777    fn apply_in_place(self, style: &mut Style) {
1778        let _: &mut LayoutStyle = style.get_mut_layout().set_padding(self.0);
1779    }
1780}
1781
1782/// `StyleApply` implementation for `Margin`.
1783impl StyleApply for Margin {
1784    /// Applies `Margin` directly in place onto `style`.
1785    ///
1786    /// # Arguments
1787    ///
1788    /// - `Self` - Outer margin wrapper.
1789    /// - `&mut Style` - Style accumulator mutated in place.
1790    #[inline(always)]
1791    fn apply_in_place(self, style: &mut Style) {
1792        let _: &mut LayoutStyle = style.get_mut_layout().set_margin(self.0);
1793    }
1794}
1795
1796/// `StyleApply` implementation for `Gap`.
1797impl StyleApply for Gap {
1798    /// Applies uniform `Gap` directly in place onto `style`.
1799    ///
1800    /// # Arguments
1801    ///
1802    /// - `Self` - Uniform gap wrapper.
1803    /// - `&mut Style` - Style accumulator mutated in place.
1804    #[inline(always)]
1805    fn apply_in_place(self, style: &mut Style) {
1806        let _: &mut Style = style.set_gap_in_place(self.0);
1807    }
1808}
1809
1810/// `StyleApply` implementation for `RowGap`.
1811impl StyleApply for RowGap {
1812    /// Applies `RowGap` directly in place onto `style`.
1813    ///
1814    /// # Arguments
1815    ///
1816    /// - `Self` - Vertical row gap wrapper.
1817    /// - `&mut Style` - Style accumulator mutated in place.
1818    #[inline(always)]
1819    fn apply_in_place(self, style: &mut Style) {
1820        let _: &mut LayoutStyle = style.get_mut_layout().set_row_gap(self.0.max(0.0));
1821    }
1822}
1823
1824/// `StyleApply` implementation for `ColumnGap`.
1825impl StyleApply for ColumnGap {
1826    /// Applies `ColumnGap` directly in place onto `style`.
1827    ///
1828    /// # Arguments
1829    ///
1830    /// - `Self` - Horizontal column gap wrapper.
1831    /// - `&mut Style` - Style accumulator mutated in place.
1832    #[inline(always)]
1833    fn apply_in_place(self, style: &mut Style) {
1834        let _: &mut LayoutStyle = style.get_mut_layout().set_column_gap(self.0.max(0.0));
1835    }
1836}
1837
1838/// `StyleApply` implementation for `FlexGrow`.
1839impl StyleApply for FlexGrow {
1840    /// Applies `FlexGrow` directly in place onto `style`.
1841    ///
1842    /// # Arguments
1843    ///
1844    /// - `Self` - Flex grow factor wrapper.
1845    /// - `&mut Style` - Style accumulator mutated in place.
1846    #[inline(always)]
1847    fn apply_in_place(self, style: &mut Style) {
1848        let _: &mut LayoutStyle = style.get_mut_layout().set_flex_grow(self.0.max(0.0));
1849    }
1850}
1851
1852/// `StyleApply` implementation for `FlexShrink`.
1853impl StyleApply for FlexShrink {
1854    /// Applies `FlexShrink` directly in place onto `style`.
1855    ///
1856    /// # Arguments
1857    ///
1858    /// - `Self` - Flex shrink factor wrapper.
1859    /// - `&mut Style` - Style accumulator mutated in place.
1860    #[inline(always)]
1861    fn apply_in_place(self, style: &mut Style) {
1862        let _: &mut LayoutStyle = style.get_mut_layout().set_flex_shrink(self.0.max(0.0));
1863    }
1864}
1865
1866/// `StyleApply` implementation for `ZIndex`.
1867impl StyleApply for ZIndex {
1868    /// Applies `ZIndex` directly in place onto `style`.
1869    ///
1870    /// # Arguments
1871    ///
1872    /// - `Self` - Stacking order wrapper.
1873    /// - `&mut Style` - Style accumulator mutated in place.
1874    #[inline(always)]
1875    fn apply_in_place(self, style: &mut Style) {
1876        let _: &mut LayoutStyle = style.get_mut_layout().set_z_index(self.0);
1877    }
1878}
1879
1880/// `StyleApply` implementation for `GridColumns`.
1881impl StyleApply for GridColumns {
1882    /// Applies `GridColumns` directly in place onto `style`.
1883    ///
1884    /// # Arguments
1885    ///
1886    /// - `Self` - Grid column count wrapper.
1887    /// - `&mut Style` - Style accumulator mutated in place.
1888    #[inline(always)]
1889    fn apply_in_place(self, style: &mut Style) {
1890        let _: &mut Style = style.set_grid_in_place(self.0);
1891    }
1892}
1893
1894/// `StyleApply` implementation for `Inset`.
1895impl StyleApply for Inset {
1896    /// Applies `Inset(top, right, bottom, left)` directly in place onto `style`.
1897    ///
1898    /// # Arguments
1899    ///
1900    /// - `Self` - Four-edge inset wrapper.
1901    /// - `&mut Style` - Style accumulator mutated in place.
1902    #[inline(always)]
1903    fn apply_in_place(self, style: &mut Style) {
1904        let _: &mut LayoutStyle = style
1905            .get_mut_layout()
1906            .set_top(self.0)
1907            .set_right(self.1)
1908            .set_bottom(self.2)
1909            .set_left(self.3);
1910    }
1911}
1912
1913/// `StyleApply` implementation for `Background`.
1914impl StyleApply for Background {
1915    /// Applies `Background` directly in place onto `style`.
1916    ///
1917    /// # Arguments
1918    ///
1919    /// - `Self` - Solid background fill color wrapper.
1920    /// - `&mut Style` - Style accumulator mutated in place.
1921    #[inline(always)]
1922    fn apply_in_place(self, style: &mut Style) {
1923        let _: &mut Style = style.set_background_in_place(self.0);
1924    }
1925}
1926
1927/// `StyleApply` implementation for `Radius`.
1928impl StyleApply for Radius {
1929    /// Applies uniform `Radius` directly in place onto `style`.
1930    ///
1931    /// # Arguments
1932    ///
1933    /// - `Self` - Uniform corner radius wrapper.
1934    /// - `&mut Style` - Style accumulator mutated in place.
1935    #[inline(always)]
1936    fn apply_in_place(self, style: &mut Style) {
1937        let _: &mut Style = style.set_radius_in_place(self.0);
1938    }
1939}
1940
1941/// `StyleApply` implementation for `FocusRing`.
1942impl StyleApply for FocusRing {
1943    /// Applies `FocusRing` directly in place onto `style`.
1944    ///
1945    /// # Arguments
1946    ///
1947    /// - `Self` - Focus ring border wrapper.
1948    /// - `&mut Style` - Style accumulator mutated in place.
1949    #[inline(always)]
1950    fn apply_in_place(self, style: &mut Style) {
1951        let _: &mut PaintStyle = style.get_mut_paint().set_focus_ring(Some(self.0));
1952    }
1953}
1954
1955/// `StyleApply` implementation for `Opacity`.
1956impl StyleApply for Opacity {
1957    /// Applies `Opacity` directly in place onto `style`.
1958    ///
1959    /// # Arguments
1960    ///
1961    /// - `Self` - Opacity factor wrapper.
1962    /// - `&mut Style` - Style accumulator mutated in place.
1963    #[inline(always)]
1964    fn apply_in_place(self, style: &mut Style) {
1965        let _: &mut Style = style.set_opacity_in_place(self.0);
1966    }
1967}
1968
1969/// `StyleApply` implementation for `StopScrollPropagation`.
1970impl StyleApply for StopScrollPropagation {
1971    /// Applies `StopScrollPropagation` directly in place onto `style`.
1972    ///
1973    /// # Arguments
1974    ///
1975    /// - `Self` - Scroll propagation blocking wrapper.
1976    /// - `&mut Style` - Style accumulator mutated in place.
1977    #[inline(always)]
1978    fn apply_in_place(self, style: &mut Style) {
1979        let _: &mut PaintStyle = style.get_mut_paint().set_stop_scroll_propagation(self.0);
1980    }
1981}
1982
1983/// `StyleApply` implementation for `StopEventPropagation`.
1984impl StyleApply for StopEventPropagation {
1985    /// Applies `StopEventPropagation` directly in place onto `style`.
1986    ///
1987    /// # Arguments
1988    ///
1989    /// - `Self` - Event propagation blocking wrapper.
1990    /// - `&mut Style` - Style accumulator mutated in place.
1991    #[inline(always)]
1992    fn apply_in_place(self, style: &mut Style) {
1993        let _: &mut PaintStyle = style.get_mut_paint().set_stop_event_propagation(self.0);
1994    }
1995}
1996
1997/// `StyleApply` implementation for `TextColor`.
1998impl StyleApply for TextColor {
1999    /// Applies `TextColor` directly in place onto `style`.
2000    ///
2001    /// # Arguments
2002    ///
2003    /// - `Self` - Foreground text color wrapper.
2004    /// - `&mut Style` - Style accumulator mutated in place.
2005    #[inline(always)]
2006    fn apply_in_place(self, style: &mut Style) {
2007        let _: &mut Style = style.set_color_in_place(self.0);
2008    }
2009}
2010
2011/// `StyleApply` implementation for `FontSize`.
2012impl StyleApply for FontSize {
2013    /// Applies `FontSize` directly in place onto `style`.
2014    ///
2015    /// # Arguments
2016    ///
2017    /// - `Self` - Font size wrapper in logical pixels.
2018    /// - `&mut Style` - Style accumulator mutated in place.
2019    #[inline(always)]
2020    fn apply_in_place(self, style: &mut Style) {
2021        let _: &mut Style = style.set_font_size_in_place(self.0);
2022    }
2023}
2024
2025/// `StyleApply` implementation for `LineHeight`.
2026impl StyleApply for LineHeight {
2027    /// Applies `LineHeight` directly in place onto `style`.
2028    ///
2029    /// # Arguments
2030    ///
2031    /// - `Self` - Line-height multiplier wrapper.
2032    /// - `&mut Style` - Style accumulator mutated in place.
2033    #[inline(always)]
2034    fn apply_in_place(self, style: &mut Style) {
2035        let _: &mut TextStyle = style.get_mut_text().set_line_height(self.0.max(0.5));
2036    }
2037}
2038
2039/// `StyleApply` implementation for `LetterSpacing`.
2040impl StyleApply for LetterSpacing {
2041    /// Applies `LetterSpacing` directly in place onto `style`.
2042    ///
2043    /// # Arguments
2044    ///
2045    /// - `Self` - Inter-glyph letter spacing wrapper.
2046    /// - `&mut Style` - Style accumulator mutated in place.
2047    #[inline(always)]
2048    fn apply_in_place(self, style: &mut Style) {
2049        let _: &mut TextStyle = style.get_mut_text().set_letter_spacing(self.0);
2050    }
2051}
2052
2053/// `StyleApply` implementation for `Italic`.
2054impl StyleApply for Italic {
2055    /// Applies `Italic` directly in place onto `style`.
2056    ///
2057    /// # Arguments
2058    ///
2059    /// - `Self` - Italic slant wrapper.
2060    /// - `&mut Style` - Style accumulator mutated in place.
2061    #[inline(always)]
2062    fn apply_in_place(self, style: &mut Style) {
2063        let _: &mut TextStyle = style.get_mut_text().set_italic(self.0);
2064    }
2065}
2066
2067/// `StyleApply` implementation for `Underline`.
2068impl StyleApply for Underline {
2069    /// Applies `Underline` directly in place onto `style`.
2070    ///
2071    /// # Arguments
2072    ///
2073    /// - `Self` - Underline decoration wrapper.
2074    /// - `&mut Style` - Style accumulator mutated in place.
2075    #[inline(always)]
2076    fn apply_in_place(self, style: &mut Style) {
2077        let _: &mut TextStyle = style.get_mut_text().set_underline(self.0);
2078    }
2079}
2080
2081/// `StyleApply` implementation for `Strikethrough`.
2082impl StyleApply for Strikethrough {
2083    /// Applies `Strikethrough` directly in place onto `style`.
2084    ///
2085    /// # Arguments
2086    ///
2087    /// - `Self` - Strikethrough decoration wrapper.
2088    /// - `&mut Style` - Style accumulator mutated in place.
2089    #[inline(always)]
2090    fn apply_in_place(self, style: &mut Style) {
2091        let _: &mut TextStyle = style.get_mut_text().set_strikethrough(self.0);
2092    }
2093}
2094
2095/// `StyleApply` implementation for `Selectable`.
2096impl StyleApply for Selectable {
2097    /// Applies `Selectable` directly in place onto `style`.
2098    ///
2099    /// # Arguments
2100    ///
2101    /// - `Self` - Interactive text selection boolean wrapper.
2102    /// - `&mut Style` - Style accumulator mutated in place.
2103    #[inline(always)]
2104    fn apply_in_place(self, style: &mut Style) {
2105        let mode: TextSelectMode = if self.0 {
2106            TextSelectMode::SelectAndCopy
2107        } else {
2108            TextSelectMode::None
2109        };
2110        let _: &mut TextStyle = style.get_mut_text().set_text_select(Some(mode));
2111    }
2112}
2113
2114/// `StyleApply` implementation for `SelectionColor`.
2115impl StyleApply for SelectionColor {
2116    /// Applies `SelectionColor` directly in place onto `style`.
2117    ///
2118    /// # Arguments
2119    ///
2120    /// - `Self` - Text selection tint color wrapper.
2121    /// - `&mut Style` - Style accumulator mutated in place.
2122    #[inline(always)]
2123    fn apply_in_place(self, style: &mut Style) {
2124        let _: &mut TextStyle = style.get_mut_text().set_selection_color(Some(self.0));
2125    }
2126}