tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 1124HTML 550Markdown 11TOML 63099 Definiciones

⎇ e8674f92096988bc8777b52c6eb4a717c842dab3 taffy_stylo/src/arc.rs Rust · 267 líneas · 8.5 KB Historia Quién tocó qué crudo

Update to latest rustfmt (format associated types with GATs) (#737) e8674f920 · Nico Burns ·

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