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 display: Display::Flex,
14 position: Position::Relative,
15 flex_direction: FlexDirection::Row,
16 flex_wrap: FlexWrap::NoWrap,
17 justify_content: JustifyContent::Start,
18 align_items: AlignItems::Stretch,
19 align_self: AlignSelf::Auto,
20 overflow: Overflow::Visible,
21 flex_grow: 0.0,
22 flex_shrink: 1.0,
23 flex_basis: Length::Auto,
24 grid_columns: 1,
25 width: Length::Auto,
26 height: Length::Auto,
27 min_width: Length::Auto,
28 min_height: Length::Auto,
29 max_width: Length::Auto,
30 max_height: Length::Auto,
31 margin: Edges::default(),
32 padding: Edges::default(),
33 row_gap: 0.0,
34 column_gap: 0.0,
35 top: None,
36 right: None,
37 bottom: None,
38 left: None,
39 z_index: 0,
40 aspect_ratio: None,
41 }
42 }
43}
44
45/// Breakpoint classification helpers.
46impl Breakpoint {
47 /// Classifies a logical viewport width into its canonical responsive breakpoint.
48 ///
49 /// # Arguments
50 ///
51 /// - `f32` - Logical viewport width in pixels.
52 ///
53 /// # Returns
54 ///
55 /// - `Self` - Matching `Breakpoint`.
56 #[must_use]
57 #[inline(always)]
58 pub fn from_width(width: f32) -> Self {
59 if width < 768.0 {
60 Self::Compact
61 } else if width < 1024.0 {
62 Self::Medium
63 } else {
64 Self::Expanded
65 }
66 }
67
68 /// Returns true when the viewport is compact mobile width (`< 768px`).
69 ///
70 /// # Arguments
71 ///
72 /// - `&Self` - Breakpoint value.
73 ///
74 /// # Returns
75 ///
76 /// - `bool` - True for `Compact`.
77 #[must_use]
78 #[inline(always)]
79 pub fn is_compact(&self) -> bool {
80 *self == Self::Compact
81 }
82}
83
84/// Non-panicking optional offset readers for `LayoutStyle`.
85impl LayoutStyle {
86 /// Returns the optional `top` offset.
87 ///
88 /// # Arguments
89 ///
90 /// - `&Self` - Layout style.
91 ///
92 /// # Returns
93 ///
94 /// - `Option<f32>` - Top offset if specified.
95 #[must_use]
96 #[inline(always)]
97 pub fn top_offset(&self) -> Option<f32> {
98 let Self { top, .. } = *self;
99 top
100 }
101
102 /// Returns the optional `right` offset.
103 ///
104 /// # Arguments
105 ///
106 /// - `&Self` - Layout style.
107 ///
108 /// # Returns
109 ///
110 /// - `Option<f32>` - Right offset if specified.
111 #[must_use]
112 #[inline(always)]
113 pub fn right_offset(&self) -> Option<f32> {
114 let Self { right, .. } = *self;
115 right
116 }
117
118 /// Returns the optional `bottom` offset.
119 ///
120 /// # Arguments
121 ///
122 /// - `&Self` - Layout style.
123 ///
124 /// # Returns
125 ///
126 /// - `Option<f32>` - Bottom offset if specified.
127 #[must_use]
128 #[inline(always)]
129 pub fn bottom_offset(&self) -> Option<f32> {
130 let Self { bottom, .. } = *self;
131 bottom
132 }
133
134 /// Returns the optional `left` offset.
135 ///
136 /// # Arguments
137 ///
138 /// - `&Self` - Layout style.
139 ///
140 /// # Returns
141 ///
142 /// - `Option<f32>` - Left offset if specified.
143 #[must_use]
144 #[inline(always)]
145 pub fn left_offset(&self) -> Option<f32> {
146 let Self { left, .. } = *self;
147 left
148 }
149
150 /// Returns the optional aspect ratio (`width / height`).
151 ///
152 /// # Arguments
153 ///
154 /// - `&Self` - Layout style.
155 ///
156 /// # Returns
157 ///
158 /// - `Option<f32>` - Aspect ratio if specified.
159 #[must_use]
160 #[inline(always)]
161 pub fn aspect_ratio_value(&self) -> Option<f32> {
162 let Self { aspect_ratio, .. } = *self;
163 aspect_ratio
164 }
165}