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    /// - `F` - 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<F>(&mut self, update: F) -> &mut Self
65    where
66        F: 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    /// - `F` - 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<F>(&mut self, update: F) -> &mut Self
84    where
85        F: 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    /// - `F` - 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<F>(&mut self, update: F) -> &mut Self
103    where
104        F: 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    /// - `T` - Typed property implementing `StyleApply`.
302    ///
303    /// # Returns
304    ///
305    /// - `Self` - Updated style.
306    #[must_use]
307    #[inline(always)]
308    pub fn apply<T>(self, prop: T) -> Self
309    where
310        T: 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    /// Enables or disables native text selection on this node and its descendant text subtree.
1009    ///
1010    /// # Arguments
1011    ///
1012    /// - `Self` - Source style.
1013    /// - `bool` - Whether native text selection is enabled (`true`) or explicitly disabled (`false`).
1014    ///
1015    /// # Returns
1016    ///
1017    /// - `Self` - Updated style.
1018    #[must_use]
1019    #[inline(always)]
1020    pub fn selectable(mut self, selectable: bool) -> Self {
1021        self.get_mut_text()
1022            .set_selectable(selectable)
1023            .set_selectable_explicit(true);
1024        self
1025    }
1026
1027    /// Sets the translucent highlight fill color used when rendering selected text ranges.
1028    ///
1029    /// # Arguments
1030    ///
1031    /// - `Self` - Source style.
1032    /// - `Color` - Selection highlight color.
1033    ///
1034    /// # Returns
1035    ///
1036    /// - `Self` - Updated style.
1037    #[must_use]
1038    #[inline(always)]
1039    pub fn selection_color(mut self, color: Color) -> Self {
1040        self.get_mut_text().set_selection_color(Some(color));
1041        self
1042    }
1043
1044    /// Configures whether scroll deltas stop at this node (`true`) or chain/penetrate to parent scrollables (`false`).
1045    ///
1046    /// # Arguments
1047    ///
1048    /// - `Self` - Source style.
1049    /// - `bool` - `true` blocks scroll penetration to ancestors; `false` permits scroll chaining.
1050    ///
1051    /// # Returns
1052    ///
1053    /// - `Self` - Updated style.
1054    #[must_use]
1055    #[inline(always)]
1056    pub fn stop_scroll_propagation(mut self, stop: bool) -> Self {
1057        self.get_mut_paint().set_stop_scroll_propagation(stop);
1058        self
1059    }
1060
1061    /// Configures whether click/pointer events stop bubbling at this node (`true`) or bubble to ancestors (`false`).
1062    ///
1063    /// # Arguments
1064    ///
1065    /// - `Self` - Source style.
1066    /// - `bool` - `true` blocks event bubbling; `false` permits bubbling.
1067    ///
1068    /// # Returns
1069    ///
1070    /// - `Self` - Updated style.
1071    #[must_use]
1072    #[inline(always)]
1073    pub fn stop_event_propagation(mut self, stop: bool) -> Self {
1074        self.get_mut_paint().set_stop_event_propagation(stop);
1075        self
1076    }
1077}
1078
1079/// Resolution helpers for `ResponsiveStyle`.
1080impl ResponsiveStyle {
1081    /// Resolves the active `Style` for the supplied `Breakpoint`.
1082    ///
1083    /// # Arguments
1084    ///
1085    /// - `&Self` - Responsive style definition.
1086    /// - `Breakpoint` - Current viewport breakpoint.
1087    ///
1088    /// # Returns
1089    ///
1090    /// - `Style` - Resolved concrete style.
1091    #[must_use]
1092    #[inline(always)]
1093    pub fn resolve(&self, breakpoint: Breakpoint) -> Style {
1094        let Self {
1095            base,
1096            compact,
1097            medium,
1098        } = *self;
1099        match breakpoint {
1100            Breakpoint::Compact => compact.unwrap_or(base),
1101            Breakpoint::Medium => medium.unwrap_or(base),
1102            Breakpoint::Expanded => base,
1103        }
1104    }
1105}
1106
1107/// `StyleApply` implementation for `Display`.
1108impl StyleApply for Display {
1109    /// Applies `Display` to `style`.
1110    ///
1111    /// # Arguments
1112    ///
1113    /// - `Self` - Target display mode.
1114    /// - `Style` - Style accumulator.
1115    ///
1116    /// # Returns
1117    ///
1118    /// - `Style` - Updated style.
1119    #[inline(always)]
1120    fn apply_to(self, style: Style) -> Style {
1121        style.display(self)
1122    }
1123}
1124
1125/// `StyleApply` implementation for `Position`.
1126impl StyleApply for Position {
1127    /// Applies `Position` to `style`.
1128    ///
1129    /// # Arguments
1130    ///
1131    /// - `Self` - Target positioning mode.
1132    /// - `Style` - Style accumulator.
1133    ///
1134    /// # Returns
1135    ///
1136    /// - `Style` - Updated style.
1137    #[inline(always)]
1138    fn apply_to(self, style: Style) -> Style {
1139        style.position(self)
1140    }
1141}
1142
1143/// `StyleApply` implementation for `FlexDirection`.
1144impl StyleApply for FlexDirection {
1145    /// Applies `FlexDirection` to `style`.
1146    ///
1147    /// # Arguments
1148    ///
1149    /// - `Self` - Target flex axis direction.
1150    /// - `Style` - Style accumulator.
1151    ///
1152    /// # Returns
1153    ///
1154    /// - `Style` - Updated style.
1155    #[inline(always)]
1156    fn apply_to(self, style: Style) -> Style {
1157        style.direction(self)
1158    }
1159}
1160
1161/// `StyleApply` implementation for `FlexWrap`.
1162impl StyleApply for FlexWrap {
1163    /// Applies `FlexWrap` to `style`.
1164    ///
1165    /// # Arguments
1166    ///
1167    /// - `Self` - Target flex wrap mode.
1168    /// - `Style` - Style accumulator.
1169    ///
1170    /// # Returns
1171    ///
1172    /// - `Style` - Updated style.
1173    #[inline(always)]
1174    fn apply_to(self, style: Style) -> Style {
1175        style.wrap(self)
1176    }
1177}
1178
1179/// `StyleApply` implementation for `JustifyContent`.
1180impl StyleApply for JustifyContent {
1181    /// Applies `JustifyContent` to `style`.
1182    ///
1183    /// # Arguments
1184    ///
1185    /// - `Self` - Target main-axis justification.
1186    /// - `Style` - Style accumulator.
1187    ///
1188    /// # Returns
1189    ///
1190    /// - `Style` - Updated style.
1191    #[inline(always)]
1192    fn apply_to(self, style: Style) -> Style {
1193        style.justify(self)
1194    }
1195}
1196
1197/// `StyleApply` implementation for `AlignItems`.
1198impl StyleApply for AlignItems {
1199    /// Applies `AlignItems` to `style`.
1200    ///
1201    /// # Arguments
1202    ///
1203    /// - `Self` - Target cross-axis alignment.
1204    /// - `Style` - Style accumulator.
1205    ///
1206    /// # Returns
1207    ///
1208    /// - `Style` - Updated style.
1209    #[inline(always)]
1210    fn apply_to(self, style: Style) -> Style {
1211        style.align(self)
1212    }
1213}
1214
1215/// `StyleApply` implementation for `Overflow`.
1216impl StyleApply for Overflow {
1217    /// Applies `Overflow` to `style`.
1218    ///
1219    /// # Arguments
1220    ///
1221    /// - `Self` - Target overflow behavior.
1222    /// - `Style` - Style accumulator.
1223    ///
1224    /// # Returns
1225    ///
1226    /// - `Style` - Updated style.
1227    #[inline(always)]
1228    fn apply_to(self, style: Style) -> Style {
1229        style.overflow(self)
1230    }
1231}
1232
1233/// `StyleApply` implementation for `CursorIcon`.
1234impl StyleApply for CursorIcon {
1235    /// Applies `CursorIcon` to `style`.
1236    ///
1237    /// # Arguments
1238    ///
1239    /// - `Self` - Target cursor hint.
1240    /// - `Style` - Style accumulator.
1241    ///
1242    /// # Returns
1243    ///
1244    /// - `Style` - Updated style.
1245    #[inline(always)]
1246    fn apply_to(self, style: Style) -> Style {
1247        style.cursor(self)
1248    }
1249}
1250
1251/// `StyleApply` implementation for `PointerEvents`.
1252impl StyleApply for PointerEvents {
1253    /// Applies `PointerEvents` to `style`.
1254    ///
1255    /// # Arguments
1256    ///
1257    /// - `Self` - Target pointer-events mode.
1258    /// - `Style` - Style accumulator.
1259    ///
1260    /// # Returns
1261    ///
1262    /// - `Style` - Updated style.
1263    #[inline(always)]
1264    fn apply_to(self, style: Style) -> Style {
1265        style.pointer_events(self)
1266    }
1267}
1268
1269/// `StyleApply` implementation for `FontWeight`.
1270impl StyleApply for FontWeight {
1271    /// Applies `FontWeight` to `style`.
1272    ///
1273    /// # Arguments
1274    ///
1275    /// - `Self` - Target font weight.
1276    /// - `Style` - Style accumulator.
1277    ///
1278    /// # Returns
1279    ///
1280    /// - `Style` - Updated style.
1281    #[inline(always)]
1282    fn apply_to(self, style: Style) -> Style {
1283        style.font_weight(self)
1284    }
1285}
1286
1287/// `StyleApply` implementation for `FontFamily`.
1288impl StyleApply for FontFamily {
1289    /// Applies `FontFamily` to `style`.
1290    ///
1291    /// # Arguments
1292    ///
1293    /// - `Self` - Target font family.
1294    /// - `Style` - Style accumulator.
1295    ///
1296    /// # Returns
1297    ///
1298    /// - `Style` - Updated style.
1299    #[inline(always)]
1300    fn apply_to(self, style: Style) -> Style {
1301        style.font_family(self)
1302    }
1303}
1304
1305/// `StyleApply` implementation for `TextAlign`.
1306impl StyleApply for TextAlign {
1307    /// Applies `TextAlign` to `style`.
1308    ///
1309    /// # Arguments
1310    ///
1311    /// - `Self` - Target horizontal text alignment.
1312    /// - `Style` - Style accumulator.
1313    ///
1314    /// # Returns
1315    ///
1316    /// - `Style` - Updated style.
1317    #[inline(always)]
1318    fn apply_to(self, style: Style) -> Style {
1319        style.text_align(self)
1320    }
1321}
1322
1323/// `StyleApply` implementation for `TextOverflow`.
1324impl StyleApply for TextOverflow {
1325    /// Applies `TextOverflow` to `style`.
1326    ///
1327    /// # Arguments
1328    ///
1329    /// - `Self` - Target text overflow strategy.
1330    /// - `Style` - Style accumulator.
1331    ///
1332    /// # Returns
1333    ///
1334    /// - `Style` - Updated style.
1335    #[inline(always)]
1336    fn apply_to(self, style: Style) -> Style {
1337        style.text_overflow(self)
1338    }
1339}
1340
1341/// `StyleApply` implementation for `Shadow`.
1342impl StyleApply for Shadow {
1343    /// Applies `Shadow` to `style`.
1344    ///
1345    /// # Arguments
1346    ///
1347    /// - `Self` - Drop shadow specification.
1348    /// - `Style` - Style accumulator.
1349    ///
1350    /// # Returns
1351    ///
1352    /// - `Style` - Updated style.
1353    #[inline(always)]
1354    fn apply_to(self, style: Style) -> Style {
1355        style.shadow(self)
1356    }
1357}
1358
1359/// `StyleApply` implementation for `LinearGradient`.
1360impl StyleApply for LinearGradient {
1361    /// Applies `LinearGradient` to `style`.
1362    ///
1363    /// # Arguments
1364    ///
1365    /// - `Self` - Linear gradient fill.
1366    /// - `Style` - Style accumulator.
1367    ///
1368    /// # Returns
1369    ///
1370    /// - `Style` - Updated style.
1371    #[inline(always)]
1372    fn apply_to(self, style: Style) -> Style {
1373        style.gradient(self)
1374    }
1375}
1376
1377/// `StyleApply` implementation for `CornerRadius`.
1378impl StyleApply for CornerRadius {
1379    /// Applies `CornerRadius` to `style`.
1380    ///
1381    /// # Arguments
1382    ///
1383    /// - `Self` - Corner radius specification.
1384    /// - `Style` - Style accumulator.
1385    ///
1386    /// # Returns
1387    ///
1388    /// - `Style` - Updated style.
1389    #[inline(always)]
1390    fn apply_to(self, style: Style) -> Style {
1391        let mut out: Style = style;
1392        out.get_mut_paint().set_radius(self);
1393        out
1394    }
1395}
1396
1397/// `StyleApply` implementation for `Style` allowing base-style merging inside newline-separated `style!` blocks.
1398impl StyleApply for Style {
1399    /// Replaces `style` with `self` as a base preset inside `style!`.
1400    ///
1401    /// # Arguments
1402    ///
1403    /// - `Self` - Base style preset.
1404    /// - `Style` - Previous accumulator.
1405    ///
1406    /// # Returns
1407    ///
1408    /// - `Style` - Base style value.
1409    #[inline(always)]
1410    fn apply_to(self, _style: Style) -> Style {
1411        self
1412    }
1413}