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 /// 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
1098/// Resolution helpers for `ResponsiveStyle`.
1099impl ResponsiveStyle {
1100 /// Resolves the active `Style` for the supplied `Breakpoint`.
1101 ///
1102 /// # Arguments
1103 ///
1104 /// - `&Self` - Responsive style definition.
1105 /// - `Breakpoint` - Current viewport breakpoint.
1106 ///
1107 /// # Returns
1108 ///
1109 /// - `Style` - Resolved concrete style.
1110 #[must_use]
1111 #[inline(always)]
1112 pub fn resolve(&self, breakpoint: Breakpoint) -> Style {
1113 let Self {
1114 base,
1115 compact,
1116 medium,
1117 } = *self;
1118 match breakpoint {
1119 Breakpoint::Compact => compact.unwrap_or(base),
1120 Breakpoint::Medium => medium.unwrap_or(base),
1121 Breakpoint::Expanded => base,
1122 }
1123 }
1124}
1125
1126/// `StyleApply` implementation for `Display`.
1127impl StyleApply for Display {
1128 /// Applies `Display` to `style`.
1129 ///
1130 /// # Arguments
1131 ///
1132 /// - `Self` - Target display mode.
1133 /// - `Style` - Style accumulator.
1134 ///
1135 /// # Returns
1136 ///
1137 /// - `Style` - Updated style.
1138 #[inline(always)]
1139 fn apply_to(self, style: Style) -> Style {
1140 style.display(self)
1141 }
1142}
1143
1144/// `StyleApply` implementation for `Position`.
1145impl StyleApply for Position {
1146 /// Applies `Position` to `style`.
1147 ///
1148 /// # Arguments
1149 ///
1150 /// - `Self` - Target positioning mode.
1151 /// - `Style` - Style accumulator.
1152 ///
1153 /// # Returns
1154 ///
1155 /// - `Style` - Updated style.
1156 #[inline(always)]
1157 fn apply_to(self, style: Style) -> Style {
1158 style.position(self)
1159 }
1160}
1161
1162/// `StyleApply` implementation for `FlexDirection`.
1163impl StyleApply for FlexDirection {
1164 /// Applies `FlexDirection` to `style`.
1165 ///
1166 /// # Arguments
1167 ///
1168 /// - `Self` - Target flex axis direction.
1169 /// - `Style` - Style accumulator.
1170 ///
1171 /// # Returns
1172 ///
1173 /// - `Style` - Updated style.
1174 #[inline(always)]
1175 fn apply_to(self, style: Style) -> Style {
1176 style.direction(self)
1177 }
1178}
1179
1180/// `StyleApply` implementation for `FlexWrap`.
1181impl StyleApply for FlexWrap {
1182 /// Applies `FlexWrap` to `style`.
1183 ///
1184 /// # Arguments
1185 ///
1186 /// - `Self` - Target flex wrap mode.
1187 /// - `Style` - Style accumulator.
1188 ///
1189 /// # Returns
1190 ///
1191 /// - `Style` - Updated style.
1192 #[inline(always)]
1193 fn apply_to(self, style: Style) -> Style {
1194 style.wrap(self)
1195 }
1196}
1197
1198/// `StyleApply` implementation for `JustifyContent`.
1199impl StyleApply for JustifyContent {
1200 /// Applies `JustifyContent` to `style`.
1201 ///
1202 /// # Arguments
1203 ///
1204 /// - `Self` - Target main-axis justification.
1205 /// - `Style` - Style accumulator.
1206 ///
1207 /// # Returns
1208 ///
1209 /// - `Style` - Updated style.
1210 #[inline(always)]
1211 fn apply_to(self, style: Style) -> Style {
1212 style.justify(self)
1213 }
1214}
1215
1216/// `StyleApply` implementation for `AlignItems`.
1217impl StyleApply for AlignItems {
1218 /// Applies `AlignItems` to `style`.
1219 ///
1220 /// # Arguments
1221 ///
1222 /// - `Self` - Target cross-axis alignment.
1223 /// - `Style` - Style accumulator.
1224 ///
1225 /// # Returns
1226 ///
1227 /// - `Style` - Updated style.
1228 #[inline(always)]
1229 fn apply_to(self, style: Style) -> Style {
1230 style.align(self)
1231 }
1232}
1233
1234/// `StyleApply` implementation for `Overflow`.
1235impl StyleApply for Overflow {
1236 /// Applies `Overflow` to `style`.
1237 ///
1238 /// # Arguments
1239 ///
1240 /// - `Self` - Target overflow behavior.
1241 /// - `Style` - Style accumulator.
1242 ///
1243 /// # Returns
1244 ///
1245 /// - `Style` - Updated style.
1246 #[inline(always)]
1247 fn apply_to(self, style: Style) -> Style {
1248 style.overflow(self)
1249 }
1250}
1251
1252/// `StyleApply` implementation for `CursorIcon`.
1253impl StyleApply for CursorIcon {
1254 /// Applies `CursorIcon` to `style`.
1255 ///
1256 /// # Arguments
1257 ///
1258 /// - `Self` - Target cursor hint.
1259 /// - `Style` - Style accumulator.
1260 ///
1261 /// # Returns
1262 ///
1263 /// - `Style` - Updated style.
1264 #[inline(always)]
1265 fn apply_to(self, style: Style) -> Style {
1266 style.cursor(self)
1267 }
1268}
1269
1270/// `StyleApply` implementation for `PointerEvents`.
1271impl StyleApply for PointerEvents {
1272 /// Applies `PointerEvents` to `style`.
1273 ///
1274 /// # Arguments
1275 ///
1276 /// - `Self` - Target pointer-events mode.
1277 /// - `Style` - Style accumulator.
1278 ///
1279 /// # Returns
1280 ///
1281 /// - `Style` - Updated style.
1282 #[inline(always)]
1283 fn apply_to(self, style: Style) -> Style {
1284 style.pointer_events(self)
1285 }
1286}
1287
1288/// `StyleApply` implementation for `FontWeight`.
1289impl StyleApply for FontWeight {
1290 /// Applies `FontWeight` to `style`.
1291 ///
1292 /// # Arguments
1293 ///
1294 /// - `Self` - Target font weight.
1295 /// - `Style` - Style accumulator.
1296 ///
1297 /// # Returns
1298 ///
1299 /// - `Style` - Updated style.
1300 #[inline(always)]
1301 fn apply_to(self, style: Style) -> Style {
1302 style.font_weight(self)
1303 }
1304}
1305
1306/// `StyleApply` implementation for `FontFamily`.
1307impl StyleApply for FontFamily {
1308 /// Applies `FontFamily` to `style`.
1309 ///
1310 /// # Arguments
1311 ///
1312 /// - `Self` - Target font family.
1313 /// - `Style` - Style accumulator.
1314 ///
1315 /// # Returns
1316 ///
1317 /// - `Style` - Updated style.
1318 #[inline(always)]
1319 fn apply_to(self, style: Style) -> Style {
1320 style.font_family(self)
1321 }
1322}
1323
1324/// `StyleApply` implementation for `TextAlign`.
1325impl StyleApply for TextAlign {
1326 /// Applies `TextAlign` to `style`.
1327 ///
1328 /// # Arguments
1329 ///
1330 /// - `Self` - Target horizontal text alignment.
1331 /// - `Style` - Style accumulator.
1332 ///
1333 /// # Returns
1334 ///
1335 /// - `Style` - Updated style.
1336 #[inline(always)]
1337 fn apply_to(self, style: Style) -> Style {
1338 style.text_align(self)
1339 }
1340}
1341
1342/// `StyleApply` implementation for `TextOverflow`.
1343impl StyleApply for TextOverflow {
1344 /// Applies `TextOverflow` to `style`.
1345 ///
1346 /// # Arguments
1347 ///
1348 /// - `Self` - Target text overflow strategy.
1349 /// - `Style` - Style accumulator.
1350 ///
1351 /// # Returns
1352 ///
1353 /// - `Style` - Updated style.
1354 #[inline(always)]
1355 fn apply_to(self, style: Style) -> Style {
1356 style.text_overflow(self)
1357 }
1358}
1359
1360/// `StyleApply` implementation for `Shadow`.
1361impl StyleApply for Shadow {
1362 /// Applies `Shadow` to `style`.
1363 ///
1364 /// # Arguments
1365 ///
1366 /// - `Self` - Drop shadow specification.
1367 /// - `Style` - Style accumulator.
1368 ///
1369 /// # Returns
1370 ///
1371 /// - `Style` - Updated style.
1372 #[inline(always)]
1373 fn apply_to(self, style: Style) -> Style {
1374 style.shadow(self)
1375 }
1376}
1377
1378/// `StyleApply` implementation for `LinearGradient`.
1379impl StyleApply for LinearGradient {
1380 /// Applies `LinearGradient` to `style`.
1381 ///
1382 /// # Arguments
1383 ///
1384 /// - `Self` - Linear gradient fill.
1385 /// - `Style` - Style accumulator.
1386 ///
1387 /// # Returns
1388 ///
1389 /// - `Style` - Updated style.
1390 #[inline(always)]
1391 fn apply_to(self, style: Style) -> Style {
1392 style.gradient(self)
1393 }
1394}
1395
1396/// `StyleApply` implementation for `CornerRadius`.
1397impl StyleApply for CornerRadius {
1398 /// Applies `CornerRadius` to `style`.
1399 ///
1400 /// # Arguments
1401 ///
1402 /// - `Self` - Corner radius specification.
1403 /// - `Style` - Style accumulator.
1404 ///
1405 /// # Returns
1406 ///
1407 /// - `Style` - Updated style.
1408 #[inline(always)]
1409 fn apply_to(self, style: Style) -> Style {
1410 let mut out: Style = style;
1411 out.get_mut_paint().set_radius(self);
1412 out
1413 }
1414}
1415
1416/// `StyleApply` implementation for `Style` allowing base-style merging inside newline-separated `style!` blocks.
1417impl StyleApply for Style {
1418 /// Replaces `style` with `self` as a base preset inside `style!`.
1419 ///
1420 /// # Arguments
1421 ///
1422 /// - `Self` - Base style preset.
1423 /// - `Style` - Previous accumulator.
1424 ///
1425 /// # Returns
1426 ///
1427 /// - `Style` - Base style value.
1428 #[inline(always)]
1429 fn apply_to(self, _style: Style) -> Style {
1430 self
1431 }
1432}