⎇ 9915b967e9809dc57f210de8fe5f7510e66806d6
taffy_stylo/src/borrowed.rs
Historia
Quién tocó qué
crudo
1use crate::convert;
2use style::properties::generated::ComputedValues;
3
4pub struct TaffyStyloStyleRef<'a>(pub &'a ComputedValues);
5
6impl<'a> From<&'a ComputedValues> for TaffyStyloStyleRef<'a> {
7 fn from(value: &'a ComputedValues) -> Self {
8 Self(value)
9 }
10}
11
12impl taffy::CoreStyle for TaffyStyloStyleRef<'_> {
13 #[inline]
14 fn box_generation_mode(&self) -> taffy::BoxGenerationMode {
15 convert::box_generation_mode(self.0.get_box().display)
16 }
17
18 #[inline]
19 fn is_block(&self) -> bool {
20 convert::is_block(self.0.get_box().display)
21 }
22
23 #[inline]
24 fn box_sizing(&self) -> taffy::BoxSizing {
25 convert::box_sizing(self.0.get_position().box_sizing)
26 }
27
28 #[inline]
29 fn overflow(&self) -> taffy::Point<taffy::Overflow> {
30 let box_styles = self.0.get_box();
31 taffy::Point { x: convert::overflow(box_styles.overflow_x), y: convert::overflow(box_styles.overflow_y) }
32 }
33
34 #[inline]
35 fn scrollbar_width(&self) -> f32 {
36 0.0
37 }
38
39 #[inline]
40 fn position(&self) -> taffy::Position {
41 convert::position(self.0.get_box().position)
42 }
43
44 #[inline]
45 fn inset(&self) -> taffy::Rect<taffy::LengthPercentageAuto> {
46 let position_styles = self.0.get_position();
47 taffy::Rect {
48 left: convert::length_percentage_auto(&position_styles.left),
49 right: convert::length_percentage_auto(&position_styles.right),
50 top: convert::length_percentage_auto(&position_styles.top),
51 bottom: convert::length_percentage_auto(&position_styles.bottom),
52 }
53 }
54
55 #[inline]
56 fn size(&self) -> taffy::Size<taffy::Dimension> {
57 let position_styles = self.0.get_position();
58 taffy::Size {
59 width: convert::dimension(&position_styles.width),
60 height: convert::dimension(&position_styles.height),
61 }
62 }
63
64 #[inline]
65 fn min_size(&self) -> taffy::Size<taffy::Dimension> {
66 let position_styles = self.0.get_position();
67 taffy::Size {
68 width: convert::dimension(&position_styles.min_width),
69 height: convert::dimension(&position_styles.min_height),
70 }
71 }
72
73 #[inline]
74 fn max_size(&self) -> taffy::Size<taffy::Dimension> {
75 let position_styles = self.0.get_position();
76 taffy::Size {
77 width: convert::max_size_dimension(&position_styles.max_width),
78 height: convert::max_size_dimension(&position_styles.max_height),
79 }
80 }
81
82 #[inline]
83 fn aspect_ratio(&self) -> Option<f32> {
84 convert::aspect_ratio(self.0.get_position().aspect_ratio)
85 }
86
87 #[inline]
88 fn margin(&self) -> taffy::Rect<taffy::LengthPercentageAuto> {
89 let margin_styles = self.0.get_margin();
90 taffy::Rect {
91 left: convert::length_percentage_auto(&margin_styles.margin_left),
92 right: convert::length_percentage_auto(&margin_styles.margin_right),
93 top: convert::length_percentage_auto(&margin_styles.margin_top),
94 bottom: convert::length_percentage_auto(&margin_styles.margin_bottom),
95 }
96 }
97
98 #[inline]
99 fn padding(&self) -> taffy::Rect<taffy::LengthPercentage> {
100 let padding_styles = self.0.get_padding();
101 taffy::Rect {
102 left: convert::length_percentage(&padding_styles.padding_left.0),
103 right: convert::length_percentage(&padding_styles.padding_right.0),
104 top: convert::length_percentage(&padding_styles.padding_top.0),
105 bottom: convert::length_percentage(&padding_styles.padding_bottom.0),
106 }
107 }
108
109 #[inline]
110 fn border(&self) -> taffy::Rect<taffy::LengthPercentage> {
111 let border_styles = self.0.get_border();
112 taffy::Rect {
113 left: taffy::LengthPercentage::Length(border_styles.border_left_width.to_f32_px()),
114 right: taffy::LengthPercentage::Length(border_styles.border_right_width.to_f32_px()),
115 top: taffy::LengthPercentage::Length(border_styles.border_top_width.to_f32_px()),
116 bottom: taffy::LengthPercentage::Length(border_styles.border_bottom_width.to_f32_px()),
117 }
118 }
119}
120
121impl taffy::FlexboxContainerStyle for TaffyStyloStyleRef<'_> {
122 #[inline]
123 fn flex_direction(&self) -> taffy::FlexDirection {
124 convert::flex_direction(self.0.get_position().flex_direction)
125 }
126
127 #[inline]
128 fn flex_wrap(&self) -> taffy::FlexWrap {
129 convert::flex_wrap(self.0.get_position().flex_wrap)
130 }
131
132 #[inline]
133 fn gap(&self) -> taffy::Size<taffy::LengthPercentage> {
134 let position_styles = self.0.get_position();
135 taffy::Size { width: convert::gap(&position_styles.column_gap), height: convert::gap(&position_styles.row_gap) }
136 }
137
138 #[inline]
139 fn align_content(&self) -> Option<taffy::AlignContent> {
140 convert::content_alignment(self.0.get_position().align_content.0)
141 }
142
143 #[inline]
144 fn align_items(&self) -> Option<taffy::AlignItems> {
145 convert::item_alignment(self.0.get_position().align_items.0)
146 }
147
148 #[inline]
149 fn justify_content(&self) -> Option<taffy::JustifyContent> {
150 convert::content_alignment(self.0.get_position().justify_content.0)
151 }
152}
153
154impl taffy::FlexboxItemStyle for TaffyStyloStyleRef<'_> {
155 #[inline]
156 fn flex_basis(&self) -> taffy::Dimension {
157 convert::flex_basis(&self.0.get_position().flex_basis)
158 }
159
160 #[inline]
161 fn flex_grow(&self) -> f32 {
162 self.0.get_position().flex_grow.0
163 }
164
165 #[inline]
166 fn flex_shrink(&self) -> f32 {
167 self.0.get_position().flex_shrink.0
168 }
169
170 #[inline]
171 fn align_self(&self) -> Option<taffy::AlignSelf> {
172 convert::item_alignment(self.0.get_position().align_self.0 .0)
173 }
174}
175
176impl taffy::GridContainerStyle for TaffyStyloStyleRef<'_> {
177 type TemplateTrackList<'a> = Vec<taffy::TrackSizingFunction> where Self: 'a;
178 type AutoTrackList<'a> = Vec<taffy::NonRepeatedTrackSizingFunction> where Self: 'a;
179
180 #[inline]
181 fn grid_template_rows(&self) -> Self::TemplateTrackList<'_> {
182 convert::grid_template_tracks(&self.0.get_position().grid_template_rows)
183 }
184
185 #[inline]
186 fn grid_template_columns(&self) -> Self::TemplateTrackList<'_> {
187 convert::grid_template_tracks(&self.0.get_position().grid_template_columns)
188 }
189
190 #[inline]
191 fn grid_auto_rows(&self) -> Self::AutoTrackList<'_> {
192 convert::grid_auto_tracks(&self.0.get_position().grid_auto_rows)
193 }
194
195 #[inline]
196 fn grid_auto_columns(&self) -> Self::AutoTrackList<'_> {
197 convert::grid_auto_tracks(&self.0.get_position().grid_auto_columns)
198 }
199
200 #[inline]
201 fn grid_auto_flow(&self) -> taffy::GridAutoFlow {
202 convert::grid_auto_flow(self.0.get_position().grid_auto_flow)
203 }
204
205 #[inline]
206 fn gap(&self) -> taffy::Size<taffy::LengthPercentage> {
207 let position_styles = self.0.get_position();
208 taffy::Size { width: convert::gap(&position_styles.column_gap), height: convert::gap(&position_styles.row_gap) }
209 }
210
211 #[inline]
212 fn align_content(&self) -> Option<taffy::AlignContent> {
213 convert::content_alignment(self.0.get_position().align_content.0)
214 }
215
216 #[inline]
217 fn justify_content(&self) -> Option<taffy::JustifyContent> {
218 convert::content_alignment(self.0.get_position().justify_content.0)
219 }
220
221 #[inline]
222 fn align_items(&self) -> Option<taffy::AlignItems> {
223 convert::item_alignment(self.0.get_position().align_items.0)
224 }
225
226 #[inline]
227 fn justify_items(&self) -> Option<taffy::AlignItems> {
228 convert::item_alignment(self.0.get_position().justify_items.computed.0)
229 }
230}
231
232impl taffy::GridItemStyle for TaffyStyloStyleRef<'_> {
233 #[inline]
234 fn grid_row(&self) -> taffy::Line<taffy::GridPlacement> {
235 let position_styles = self.0.get_position();
236 taffy::Line {
237 start: convert::grid_line(&position_styles.grid_row_start),
238 end: convert::grid_line(&position_styles.grid_row_end),
239 }
240 }
241
242 #[inline]
243 fn grid_column(&self) -> taffy::Line<taffy::GridPlacement> {
244 let position_styles = self.0.get_position();
245 taffy::Line {
246 start: convert::grid_line(&position_styles.grid_column_start),
247 end: convert::grid_line(&position_styles.grid_column_end),
248 }
249 }
250
251 #[inline]
252 fn align_self(&self) -> Option<taffy::AlignSelf> {
253 convert::item_alignment(self.0.get_position().align_self.0 .0)
254 }
255
256 #[inline]
257 fn justify_self(&self) -> Option<taffy::AlignSelf> {
258 convert::item_alignment(self.0.get_position().justify_self.0 .0)
259 }
260}