Skip to main content

euv_core/style/layout_prop/
impl.rs

1use super::*;
2
3/// Default layout style matching standard Flexbox defaults.
4impl Default for LayoutStyle {
5    /// Creates default layout properties (`Flex`, `Row`, `flex_shrink: 1.0`).
6    ///
7    /// # Returns
8    ///
9    /// - `Self` - Default `LayoutStyle`.
10    #[inline(always)]
11    fn default() -> Self {
12        Self {
13            flags: 0,
14            length_tags: 0,
15            length_vals: [0.0; 7],
16            flex_grow: 0.0,
17            flex_shrink: 1.0,
18            margin: Edges::default(),
19            padding: Edges::default(),
20            row_gap: 0.0,
21            column_gap: 0.0,
22            top_val: f32::NAN,
23            right_val: f32::NAN,
24            bottom_val: f32::NAN,
25            left_val: f32::NAN,
26            aspect_ratio_val: f32::NAN,
27            z_index: 0,
28            grid_columns: 1,
29        }
30    }
31}
32
33/// Sentinel-aware value equality for compact `LayoutStyle`.
34impl PartialEq for LayoutStyle {
35    /// Compares two `LayoutStyle` values treating matching `f32::NAN` sentinels as equal `None` options.
36    ///
37    /// # Arguments
38    ///
39    /// - `&Self` - Left-hand layout style.
40    /// - `&Self` - Right-hand layout style.
41    ///
42    /// # Returns
43    ///
44    /// - `bool` - `true` when all layout properties match identically.
45    #[inline]
46    fn eq(&self, other: &Self) -> bool {
47        self.get_flags() == other.get_flags()
48            && self.get_length_tags() == other.get_length_tags()
49            && self.get_length_vals() == other.get_length_vals()
50            && self.get_flex_grow() == other.get_flex_grow()
51            && self.get_flex_shrink() == other.get_flex_shrink()
52            && self.get_margin() == other.get_margin()
53            && self.get_padding() == other.get_padding()
54            && self.get_row_gap() == other.get_row_gap()
55            && self.get_column_gap() == other.get_column_gap()
56            && Self::opt_f32_eq(self.get_top_val(), other.get_top_val())
57            && Self::opt_f32_eq(self.get_right_val(), other.get_right_val())
58            && Self::opt_f32_eq(self.get_bottom_val(), other.get_bottom_val())
59            && Self::opt_f32_eq(self.get_left_val(), other.get_left_val())
60            && Self::opt_f32_eq(self.get_aspect_ratio_val(), other.get_aspect_ratio_val())
61            && self.get_z_index() == other.get_z_index()
62            && self.get_grid_columns() == other.get_grid_columns()
63    }
64}
65
66/// Breakpoint classification helpers.
67impl Breakpoint {
68    /// Classifies a logical viewport width into its canonical responsive breakpoint.
69    ///
70    /// # Arguments
71    ///
72    /// - `f32` - Logical viewport width in pixels.
73    ///
74    /// # Returns
75    ///
76    /// - `Self` - Matching `Breakpoint`.
77    #[must_use]
78    #[inline(always)]
79    pub fn from_width(width: f32) -> Self {
80        if width < 768.0 {
81            Self::Compact
82        } else if width < 1024.0 {
83            Self::Medium
84        } else {
85            Self::Expanded
86        }
87    }
88
89    /// Returns true when the viewport is compact mobile width (`< 768px`).
90    ///
91    /// # Arguments
92    ///
93    /// - `&Self` - Breakpoint value.
94    ///
95    /// # Returns
96    ///
97    /// - `bool` - True for `Compact`.
98    #[must_use]
99    #[inline(always)]
100    pub fn is_compact(&self) -> bool {
101        *self == Self::Compact
102    }
103}
104
105/// Packed enum, tagged length, and sentinel offset accessors for `LayoutStyle`.
106impl LayoutStyle {
107    /// Compares two `f32::NAN`-sentinel optional floats where two `NaN`s represent equal `None` values.
108    ///
109    /// # Arguments
110    ///
111    /// - `f32` - First sentinel-encoded float.
112    /// - `f32` - Second sentinel-encoded float.
113    ///
114    /// # Returns
115    ///
116    /// - `bool` - `true` when both are `NaN` or numerically equal.
117    #[must_use]
118    #[inline(always)]
119    fn opt_f32_eq(a: f32, b: f32) -> bool {
120        (a.is_nan() && b.is_nan()) || a == b
121    }
122
123    /// Decodes a `f32::NAN`-sentinel float back into `Option<f32>`.
124    ///
125    /// # Arguments
126    ///
127    /// - `f32` - Sentinel-encoded float.
128    ///
129    /// # Returns
130    ///
131    /// - `Option<f32>` - `None` for `NaN`, otherwise `Some(val)`.
132    #[must_use]
133    #[inline(always)]
134    fn decode_opt_f32(val: f32) -> Option<f32> {
135        if val.is_nan() { None } else { Some(val) }
136    }
137
138    /// Encodes `Option<f32>` into a `f32::NAN`-sentinel float.
139    ///
140    /// # Arguments
141    ///
142    /// - `Option<f32>` - Optional float value.
143    ///
144    /// # Returns
145    ///
146    /// - `f32` - Underlying float or `f32::NAN` for `None`.
147    #[must_use]
148    #[inline(always)]
149    fn encode_opt_f32(val: Option<f32>) -> f32 {
150        val.unwrap_or(f32::NAN)
151    }
152
153    /// Reads a packed `Length` slot from `length_tags` and `length_vals`.
154    ///
155    /// # Arguments
156    ///
157    /// - `&Self` - Layout style reference.
158    /// - `usize` - Slot index in `0..7`.
159    ///
160    /// # Returns
161    ///
162    /// - `Length` - Decoded length unit and value.
163    #[must_use]
164    #[inline(always)]
165    fn read_length(&self, slot: usize) -> Length {
166        let shift: u32 = (slot as u32) * LENGTH_TAG_BITS;
167        let tag: u32 = (self.get_length_tags() >> shift) & LENGTH_TAG_MASK;
168        let val: f32 = self.get_length_vals()[slot];
169        match tag {
170            1 => Length::Px(val),
171            2 => Length::Percent(val),
172            3 => Length::Fraction(val),
173            4 => Length::ViewportWidth(val),
174            5 => Length::ViewportHeight(val),
175            _ => Length::Auto,
176        }
177    }
178
179    /// Writes a packed `Length` slot into `length_tags` and `length_vals`.
180    ///
181    /// # Arguments
182    ///
183    /// - `&Self` - Mutable layout style.
184    /// - `usize` - Slot index in `0..7`.
185    /// - `Length` - Replacement length value.
186    #[inline(always)]
187    fn write_length(&mut self, slot: usize, length: Length) {
188        let (tag, val): (u32, f32) = match length {
189            Length::Auto => (0, 0.0),
190            Length::Px(v) => (1, v),
191            Length::Percent(v) => (2, v),
192            Length::Fraction(v) => (3, v),
193            Length::ViewportWidth(v) => (4, v),
194            Length::ViewportHeight(v) => (5, v),
195        };
196        let shift: u32 = (slot as u32) * LENGTH_TAG_BITS;
197        let cleared: u32 = self.get_length_tags() & !(LENGTH_TAG_MASK << shift);
198        let _: &mut Self = self.set_length_tags(cleared | (tag << shift));
199        self.get_mut_length_vals()[slot] = val;
200    }
201
202    /// Writes a bit-packed enum field into `flags`.
203    ///
204    /// # Arguments
205    ///
206    /// - `&Self` - Mutable layout style.
207    /// - `u32` - Bit shift inside `flags`.
208    /// - `u32` - Unshifted bit mask.
209    /// - `u32` - Encoded enum discriminant.
210    #[inline(always)]
211    fn write_flag_bits(&mut self, shift: u32, mask: u32, bits: u32) {
212        let cleared: u32 = self.get_flags() & !(mask << shift);
213        let _: &mut Self = self.set_flags(cleared | ((bits & mask) << shift));
214    }
215
216    /// Returns the box `Display` mode.
217    ///
218    /// # Arguments
219    ///
220    /// - `&Self` - Layout style reference.
221    ///
222    /// # Returns
223    ///
224    /// - `Display` - Active display mode.
225    #[must_use]
226    #[inline(always)]
227    pub fn get_display(&self) -> Display {
228        match (self.get_flags() >> LAYOUT_DISPLAY_SHIFT) & LAYOUT_FLAG_MASK_2 {
229            1 => Display::Block,
230            2 => Display::Grid,
231            3 => Display::None,
232            _ => Display::Flex,
233        }
234    }
235
236    /// Sets the box `Display` mode.
237    ///
238    /// # Arguments
239    ///
240    /// - `&Self` - Mutable layout style.
241    /// - `Display` - Replacement display mode.
242    ///
243    /// # Returns
244    ///
245    /// - `&mut Self` - Mutable layout style for chaining.
246    #[inline(always)]
247    pub fn set_display(&mut self, value: Display) -> &mut Self {
248        let bits: u32 = match value {
249            Display::Flex => 0,
250            Display::Block => 1,
251            Display::Grid => 2,
252            Display::None => 3,
253        };
254        self.write_flag_bits(LAYOUT_DISPLAY_SHIFT, LAYOUT_FLAG_MASK_2, bits);
255        self
256    }
257
258    /// Returns the positioning strategy (`Relative`, `Absolute`, `Fixed`).
259    ///
260    /// # Arguments
261    ///
262    /// - `&Self` - Layout style reference.
263    ///
264    /// # Returns
265    ///
266    /// - `Position` - Active positioning mode.
267    #[must_use]
268    #[inline(always)]
269    pub fn get_position(&self) -> Position {
270        match (self.get_flags() >> LAYOUT_POSITION_SHIFT) & LAYOUT_FLAG_MASK_2 {
271            1 => Position::Absolute,
272            2 => Position::Fixed,
273            _ => Position::Relative,
274        }
275    }
276
277    /// Sets the positioning strategy.
278    ///
279    /// # Arguments
280    ///
281    /// - `&Self` - Mutable layout style.
282    /// - `Position` - Replacement positioning mode.
283    ///
284    /// # Returns
285    ///
286    /// - `&mut Self` - Mutable layout style for chaining.
287    #[inline(always)]
288    pub fn set_position(&mut self, value: Position) -> &mut Self {
289        let bits: u32 = match value {
290            Position::Relative => 0,
291            Position::Absolute => 1,
292            Position::Fixed => 2,
293        };
294        self.write_flag_bits(LAYOUT_POSITION_SHIFT, LAYOUT_FLAG_MASK_2, bits);
295        self
296    }
297
298    /// Returns the flex main-axis direction.
299    ///
300    /// # Arguments
301    ///
302    /// - `&Self` - Layout style reference.
303    ///
304    /// # Returns
305    ///
306    /// - `FlexDirection` - Active flex direction.
307    #[must_use]
308    #[inline(always)]
309    pub fn get_flex_direction(&self) -> FlexDirection {
310        match (self.get_flags() >> LAYOUT_FLEX_DIR_SHIFT) & LAYOUT_FLAG_MASK_2 {
311            1 => FlexDirection::Column,
312            2 => FlexDirection::RowReverse,
313            3 => FlexDirection::ColumnReverse,
314            _ => FlexDirection::Row,
315        }
316    }
317
318    /// Sets the flex main-axis direction.
319    ///
320    /// # Arguments
321    ///
322    /// - `&Self` - Mutable layout style.
323    /// - `FlexDirection` - Replacement flex direction.
324    ///
325    /// # Returns
326    ///
327    /// - `&mut Self` - Mutable layout style for chaining.
328    #[inline(always)]
329    pub fn set_flex_direction(&mut self, value: FlexDirection) -> &mut Self {
330        let bits: u32 = match value {
331            FlexDirection::Row => 0,
332            FlexDirection::Column => 1,
333            FlexDirection::RowReverse => 2,
334            FlexDirection::ColumnReverse => 3,
335        };
336        self.write_flag_bits(LAYOUT_FLEX_DIR_SHIFT, LAYOUT_FLAG_MASK_2, bits);
337        self
338    }
339
340    /// Returns the flex wrapping mode.
341    ///
342    /// # Arguments
343    ///
344    /// - `&Self` - Layout style reference.
345    ///
346    /// # Returns
347    ///
348    /// - `FlexWrap` - Active flex wrap mode.
349    #[must_use]
350    #[inline(always)]
351    pub fn get_flex_wrap(&self) -> FlexWrap {
352        match (self.get_flags() >> LAYOUT_FLEX_WRAP_SHIFT) & LAYOUT_FLAG_MASK_2 {
353            1 => FlexWrap::Wrap,
354            _ => FlexWrap::NoWrap,
355        }
356    }
357
358    /// Sets the flex wrapping mode.
359    ///
360    /// # Arguments
361    ///
362    /// - `&Self` - Mutable layout style.
363    /// - `FlexWrap` - Replacement flex wrap mode.
364    ///
365    /// # Returns
366    ///
367    /// - `&mut Self` - Mutable layout style for chaining.
368    #[inline(always)]
369    pub fn set_flex_wrap(&mut self, value: FlexWrap) -> &mut Self {
370        let bits: u32 = match value {
371            FlexWrap::NoWrap => 0,
372            FlexWrap::Wrap => 1,
373        };
374        self.write_flag_bits(LAYOUT_FLEX_WRAP_SHIFT, LAYOUT_FLAG_MASK_2, bits);
375        self
376    }
377
378    /// Returns main-axis content justification.
379    ///
380    /// # Arguments
381    ///
382    /// - `&Self` - Layout style reference.
383    ///
384    /// # Returns
385    ///
386    /// - `JustifyContent` - Active justification mode.
387    #[must_use]
388    #[inline(always)]
389    pub fn get_justify_content(&self) -> JustifyContent {
390        match (self.get_flags() >> LAYOUT_JUSTIFY_SHIFT) & LAYOUT_FLAG_MASK_3 {
391            1 => JustifyContent::Center,
392            2 => JustifyContent::End,
393            3 => JustifyContent::SpaceBetween,
394            4 => JustifyContent::SpaceAround,
395            5 => JustifyContent::SpaceEvenly,
396            _ => JustifyContent::Start,
397        }
398    }
399
400    /// Sets main-axis content justification.
401    ///
402    /// # Arguments
403    ///
404    /// - `&Self` - Mutable layout style.
405    /// - `JustifyContent` - Replacement justification mode.
406    ///
407    /// # Returns
408    ///
409    /// - `&mut Self` - Mutable layout style for chaining.
410    #[inline(always)]
411    pub fn set_justify_content(&mut self, value: JustifyContent) -> &mut Self {
412        let bits: u32 = match value {
413            JustifyContent::Start => 0,
414            JustifyContent::Center => 1,
415            JustifyContent::End => 2,
416            JustifyContent::SpaceBetween => 3,
417            JustifyContent::SpaceAround => 4,
418            JustifyContent::SpaceEvenly => 5,
419        };
420        self.write_flag_bits(LAYOUT_JUSTIFY_SHIFT, LAYOUT_FLAG_MASK_3, bits);
421        self
422    }
423
424    /// Returns cross-axis alignment for children.
425    ///
426    /// # Arguments
427    ///
428    /// - `&Self` - Layout style reference.
429    ///
430    /// # Returns
431    ///
432    /// - `AlignItems` - Active cross-axis alignment.
433    #[must_use]
434    #[inline(always)]
435    pub fn get_align_items(&self) -> AlignItems {
436        match (self.get_flags() >> LAYOUT_ALIGN_ITEMS_SHIFT) & LAYOUT_FLAG_MASK_3 {
437            1 => AlignItems::Start,
438            2 => AlignItems::Center,
439            3 => AlignItems::End,
440            _ => AlignItems::Stretch,
441        }
442    }
443
444    /// Sets cross-axis alignment for children.
445    ///
446    /// # Arguments
447    ///
448    /// - `&Self` - Mutable layout style.
449    /// - `AlignItems` - Replacement cross-axis alignment.
450    ///
451    /// # Returns
452    ///
453    /// - `&mut Self` - Mutable layout style for chaining.
454    #[inline(always)]
455    pub fn set_align_items(&mut self, value: AlignItems) -> &mut Self {
456        let bits: u32 = match value {
457            AlignItems::Stretch => 0,
458            AlignItems::Start => 1,
459            AlignItems::Center => 2,
460            AlignItems::End => 3,
461        };
462        self.write_flag_bits(LAYOUT_ALIGN_ITEMS_SHIFT, LAYOUT_FLAG_MASK_3, bits);
463        self
464    }
465
466    /// Returns per-item cross-axis alignment override.
467    ///
468    /// # Arguments
469    ///
470    /// - `&Self` - Layout style reference.
471    ///
472    /// # Returns
473    ///
474    /// - `AlignSelf` - Active self-alignment override.
475    #[must_use]
476    #[inline(always)]
477    pub fn get_align_self(&self) -> AlignSelf {
478        match (self.get_flags() >> LAYOUT_ALIGN_SELF_SHIFT) & LAYOUT_FLAG_MASK_3 {
479            1 => AlignSelf::Stretch,
480            2 => AlignSelf::Start,
481            3 => AlignSelf::Center,
482            4 => AlignSelf::End,
483            _ => AlignSelf::Auto,
484        }
485    }
486
487    /// Sets per-item cross-axis alignment override.
488    ///
489    /// # Arguments
490    ///
491    /// - `&Self` - Mutable layout style.
492    /// - `AlignSelf` - Replacement self-alignment override.
493    ///
494    /// # Returns
495    ///
496    /// - `&mut Self` - Mutable layout style for chaining.
497    #[inline(always)]
498    pub fn set_align_self(&mut self, value: AlignSelf) -> &mut Self {
499        let bits: u32 = match value {
500            AlignSelf::Auto => 0,
501            AlignSelf::Stretch => 1,
502            AlignSelf::Start => 2,
503            AlignSelf::Center => 3,
504            AlignSelf::End => 4,
505        };
506        self.write_flag_bits(LAYOUT_ALIGN_SELF_SHIFT, LAYOUT_FLAG_MASK_3, bits);
507        self
508    }
509
510    /// Returns overflow clipping and scrolling behavior.
511    ///
512    /// # Arguments
513    ///
514    /// - `&Self` - Layout style reference.
515    ///
516    /// # Returns
517    ///
518    /// - `Overflow` - Active overflow policy.
519    #[must_use]
520    #[inline(always)]
521    pub fn get_overflow(&self) -> Overflow {
522        match (self.get_flags() >> LAYOUT_OVERFLOW_SHIFT) & LAYOUT_FLAG_MASK_2 {
523            1 => Overflow::Hidden,
524            2 => Overflow::Scroll,
525            _ => Overflow::Visible,
526        }
527    }
528
529    /// Sets overflow clipping and scrolling behavior.
530    ///
531    /// # Arguments
532    ///
533    /// - `&Self` - Mutable layout style.
534    /// - `Overflow` - Replacement overflow policy.
535    ///
536    /// # Returns
537    ///
538    /// - `&mut Self` - Mutable layout style for chaining.
539    #[inline(always)]
540    pub fn set_overflow(&mut self, value: Overflow) -> &mut Self {
541        let bits: u32 = match value {
542            Overflow::Visible => 0,
543            Overflow::Hidden => 1,
544            Overflow::Scroll => 2,
545        };
546        self.write_flag_bits(LAYOUT_OVERFLOW_SHIFT, LAYOUT_FLAG_MASK_2, bits);
547        self
548    }
549
550    /// Returns the flex basis length.
551    ///
552    /// # Arguments
553    ///
554    /// - `&Self` - Layout style reference.
555    ///
556    /// # Returns
557    ///
558    /// - `Length` - Flex basis length.
559    #[must_use]
560    #[inline(always)]
561    pub fn get_flex_basis(&self) -> Length {
562        self.read_length(LENGTH_SLOT_FLEX_BASIS)
563    }
564
565    /// Sets the flex basis length.
566    ///
567    /// # Arguments
568    ///
569    /// - `&Self` - Mutable layout style.
570    /// - `Length` - Replacement flex basis.
571    ///
572    /// # Returns
573    ///
574    /// - `&mut Self` - Mutable layout style for chaining.
575    #[inline(always)]
576    pub fn set_flex_basis(&mut self, value: Length) -> &mut Self {
577        self.write_length(LENGTH_SLOT_FLEX_BASIS, value);
578        self
579    }
580
581    /// Returns the width length specification.
582    ///
583    /// # Arguments
584    ///
585    /// - `&Self` - Layout style reference.
586    ///
587    /// # Returns
588    ///
589    /// - `Length` - Width specification.
590    #[must_use]
591    #[inline(always)]
592    pub fn get_width(&self) -> Length {
593        self.read_length(LENGTH_SLOT_WIDTH)
594    }
595
596    /// Sets the width length specification.
597    ///
598    /// # Arguments
599    ///
600    /// - `&Self` - Mutable layout style.
601    /// - `Length` - Replacement width.
602    ///
603    /// # Returns
604    ///
605    /// - `&mut Self` - Mutable layout style for chaining.
606    #[inline(always)]
607    pub fn set_width(&mut self, value: Length) -> &mut Self {
608        self.write_length(LENGTH_SLOT_WIDTH, value);
609        self
610    }
611
612    /// Returns the height length specification.
613    ///
614    /// # Arguments
615    ///
616    /// - `&Self` - Layout style reference.
617    ///
618    /// # Returns
619    ///
620    /// - `Length` - Height specification.
621    #[must_use]
622    #[inline(always)]
623    pub fn get_height(&self) -> Length {
624        self.read_length(LENGTH_SLOT_HEIGHT)
625    }
626
627    /// Sets the height length specification.
628    ///
629    /// # Arguments
630    ///
631    /// - `&Self` - Mutable layout style.
632    /// - `Length` - Replacement height.
633    ///
634    /// # Returns
635    ///
636    /// - `&mut Self` - Mutable layout style for chaining.
637    #[inline(always)]
638    pub fn set_height(&mut self, value: Length) -> &mut Self {
639        self.write_length(LENGTH_SLOT_HEIGHT, value);
640        self
641    }
642
643    /// Returns the minimum width constraint.
644    ///
645    /// # Arguments
646    ///
647    /// - `&Self` - Layout style reference.
648    ///
649    /// # Returns
650    ///
651    /// - `Length` - Minimum width constraint.
652    #[must_use]
653    #[inline(always)]
654    pub fn get_min_width(&self) -> Length {
655        self.read_length(LENGTH_SLOT_MIN_WIDTH)
656    }
657
658    /// Sets the minimum width constraint.
659    ///
660    /// # Arguments
661    ///
662    /// - `&Self` - Mutable layout style.
663    /// - `Length` - Replacement minimum width.
664    ///
665    /// # Returns
666    ///
667    /// - `&mut Self` - Mutable layout style for chaining.
668    #[inline(always)]
669    pub fn set_min_width(&mut self, value: Length) -> &mut Self {
670        self.write_length(LENGTH_SLOT_MIN_WIDTH, value);
671        self
672    }
673
674    /// Returns the minimum height constraint.
675    ///
676    /// # Arguments
677    ///
678    /// - `&Self` - Layout style reference.
679    ///
680    /// # Returns
681    ///
682    /// - `Length` - Minimum height constraint.
683    #[must_use]
684    #[inline(always)]
685    pub fn get_min_height(&self) -> Length {
686        self.read_length(LENGTH_SLOT_MIN_HEIGHT)
687    }
688
689    /// Sets the minimum height constraint.
690    ///
691    /// # Arguments
692    ///
693    /// - `&Self` - Mutable layout style.
694    /// - `Length` - Replacement minimum height.
695    ///
696    /// # Returns
697    ///
698    /// - `&mut Self` - Mutable layout style for chaining.
699    #[inline(always)]
700    pub fn set_min_height(&mut self, value: Length) -> &mut Self {
701        self.write_length(LENGTH_SLOT_MIN_HEIGHT, value);
702        self
703    }
704
705    /// Returns the maximum width constraint.
706    ///
707    /// # Arguments
708    ///
709    /// - `&Self` - Layout style reference.
710    ///
711    /// # Returns
712    ///
713    /// - `Length` - Maximum width constraint.
714    #[must_use]
715    #[inline(always)]
716    pub fn get_max_width(&self) -> Length {
717        self.read_length(LENGTH_SLOT_MAX_WIDTH)
718    }
719
720    /// Sets the maximum width constraint.
721    ///
722    /// # Arguments
723    ///
724    /// - `&Self` - Mutable layout style.
725    /// - `Length` - Replacement maximum width.
726    ///
727    /// # Returns
728    ///
729    /// - `&mut Self` - Mutable layout style for chaining.
730    #[inline(always)]
731    pub fn set_max_width(&mut self, value: Length) -> &mut Self {
732        self.write_length(LENGTH_SLOT_MAX_WIDTH, value);
733        self
734    }
735
736    /// Returns the maximum height constraint.
737    ///
738    /// # Arguments
739    ///
740    /// - `&Self` - Layout style reference.
741    ///
742    /// # Returns
743    ///
744    /// - `Length` - Maximum height constraint.
745    #[must_use]
746    #[inline(always)]
747    pub fn get_max_height(&self) -> Length {
748        self.read_length(LENGTH_SLOT_MAX_HEIGHT)
749    }
750
751    /// Sets the maximum height constraint.
752    ///
753    /// # Arguments
754    ///
755    /// - `&Self` - Mutable layout style.
756    /// - `Length` - Replacement maximum height.
757    ///
758    /// # Returns
759    ///
760    /// - `&mut Self` - Mutable layout style for chaining.
761    #[inline(always)]
762    pub fn set_max_height(&mut self, value: Length) -> &mut Self {
763        self.write_length(LENGTH_SLOT_MAX_HEIGHT, value);
764        self
765    }
766
767    /// Returns the optional `top` offset.
768    ///
769    /// # Arguments
770    ///
771    /// - `&Self` - Layout style.
772    ///
773    /// # Returns
774    ///
775    /// - `Option<f32>` - Top offset if specified.
776    #[must_use]
777    #[inline(always)]
778    pub fn top_offset(&self) -> Option<f32> {
779        Self::decode_opt_f32(self.get_top_val())
780    }
781
782    /// Sets the optional `top` offset.
783    ///
784    /// # Arguments
785    ///
786    /// - `&Self` - Mutable layout style.
787    /// - `Option<f32>` - Top offset or `None` to clear.
788    ///
789    /// # Returns
790    ///
791    /// - `&mut Self` - Mutable layout style for chaining.
792    #[inline(always)]
793    pub fn set_top(&mut self, value: Option<f32>) -> &mut Self {
794        self.set_top_val(Self::encode_opt_f32(value))
795    }
796
797    /// Returns the optional `right` offset.
798    ///
799    /// # Arguments
800    ///
801    /// - `&Self` - Layout style.
802    ///
803    /// # Returns
804    ///
805    /// - `Option<f32>` - Right offset if specified.
806    #[must_use]
807    #[inline(always)]
808    pub fn right_offset(&self) -> Option<f32> {
809        Self::decode_opt_f32(self.get_right_val())
810    }
811
812    /// Sets the optional `right` offset.
813    ///
814    /// # Arguments
815    ///
816    /// - `&Self` - Mutable layout style.
817    /// - `Option<f32>` - Right offset or `None` to clear.
818    ///
819    /// # Returns
820    ///
821    /// - `&mut Self` - Mutable layout style for chaining.
822    #[inline(always)]
823    pub fn set_right(&mut self, value: Option<f32>) -> &mut Self {
824        self.set_right_val(Self::encode_opt_f32(value))
825    }
826
827    /// Returns the optional `bottom` offset.
828    ///
829    /// # Arguments
830    ///
831    /// - `&Self` - Layout style.
832    ///
833    /// # Returns
834    ///
835    /// - `Option<f32>` - Bottom offset if specified.
836    #[must_use]
837    #[inline(always)]
838    pub fn bottom_offset(&self) -> Option<f32> {
839        Self::decode_opt_f32(self.get_bottom_val())
840    }
841
842    /// Sets the optional `bottom` offset.
843    ///
844    /// # Arguments
845    ///
846    /// - `&Self` - Mutable layout style.
847    /// - `Option<f32>` - Bottom offset or `None` to clear.
848    ///
849    /// # Returns
850    ///
851    /// - `&mut Self` - Mutable layout style for chaining.
852    #[inline(always)]
853    pub fn set_bottom(&mut self, value: Option<f32>) -> &mut Self {
854        self.set_bottom_val(Self::encode_opt_f32(value))
855    }
856
857    /// Returns the optional `left` offset.
858    ///
859    /// # Arguments
860    ///
861    /// - `&Self` - Layout style.
862    ///
863    /// # Returns
864    ///
865    /// - `Option<f32>` - Left offset if specified.
866    #[must_use]
867    #[inline(always)]
868    pub fn left_offset(&self) -> Option<f32> {
869        Self::decode_opt_f32(self.get_left_val())
870    }
871
872    /// Sets the optional `left` offset.
873    ///
874    /// # Arguments
875    ///
876    /// - `&Self` - Mutable layout style.
877    /// - `Option<f32>` - Left offset or `None` to clear.
878    ///
879    /// # Returns
880    ///
881    /// - `&mut Self` - Mutable layout style for chaining.
882    #[inline(always)]
883    pub fn set_left(&mut self, value: Option<f32>) -> &mut Self {
884        self.set_left_val(Self::encode_opt_f32(value))
885    }
886
887    /// Returns the optional aspect ratio (`width / height`).
888    ///
889    /// # Arguments
890    ///
891    /// - `&Self` - Layout style.
892    ///
893    /// # Returns
894    ///
895    /// - `Option<f32>` - Aspect ratio if specified.
896    #[must_use]
897    #[inline(always)]
898    pub fn aspect_ratio_value(&self) -> Option<f32> {
899        Self::decode_opt_f32(self.get_aspect_ratio_val())
900    }
901
902    /// Sets the optional aspect ratio (`width / height`).
903    ///
904    /// # Arguments
905    ///
906    /// - `&Self` - Mutable layout style.
907    /// - `Option<f32>` - Positive aspect ratio or `None` to clear.
908    ///
909    /// # Returns
910    ///
911    /// - `&mut Self` - Mutable layout style for chaining.
912    #[inline(always)]
913    pub fn set_aspect_ratio(&mut self, value: Option<f32>) -> &mut Self {
914        self.set_aspect_ratio_val(Self::encode_opt_f32(value))
915    }
916}