tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Definiciones

⎇ 2e032b67d382d8e965baab8cfc6431d4492fc048 taffy_stylo/src/borrowed.rs Rust · 266 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 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>
178        = Vec<taffy::TrackSizingFunction>
179    where
180        Self: 'a;
181    type AutoTrackList<'a>
182        = Vec<taffy::NonRepeatedTrackSizingFunction>
183    where
184        Self: 'a;
185
186    #[inline]
187    fn grid_template_rows(&self) -> Self::TemplateTrackList<'_> {
188        convert::grid_template_tracks(&self.0.get_position().grid_template_rows)
189    }
190
191    #[inline]
192    fn grid_template_columns(&self) -> Self::TemplateTrackList<'_> {
193        convert::grid_template_tracks(&self.0.get_position().grid_template_columns)
194    }
195
196    #[inline]
197    fn grid_auto_rows(&self) -> Self::AutoTrackList<'_> {
198        convert::grid_auto_tracks(&self.0.get_position().grid_auto_rows)
199    }
200
201    #[inline]
202    fn grid_auto_columns(&self) -> Self::AutoTrackList<'_> {
203        convert::grid_auto_tracks(&self.0.get_position().grid_auto_columns)
204    }
205
206    #[inline]
207    fn grid_auto_flow(&self) -> taffy::GridAutoFlow {
208        convert::grid_auto_flow(self.0.get_position().grid_auto_flow)
209    }
210
211    #[inline]
212    fn gap(&self) -> taffy::Size<taffy::LengthPercentage> {
213        let position_styles = self.0.get_position();
214        taffy::Size { width: convert::gap(&position_styles.column_gap), height: convert::gap(&position_styles.row_gap) }
215    }
216
217    #[inline]
218    fn align_content(&self) -> Option<taffy::AlignContent> {
219        convert::content_alignment(self.0.get_position().align_content.0)
220    }
221
222    #[inline]
223    fn justify_content(&self) -> Option<taffy::JustifyContent> {
224        convert::content_alignment(self.0.get_position().justify_content.0)
225    }
226
227    #[inline]
228    fn align_items(&self) -> Option<taffy::AlignItems> {
229        convert::item_alignment(self.0.get_position().align_items.0)
230    }
231
232    #[inline]
233    fn justify_items(&self) -> Option<taffy::AlignItems> {
234        convert::item_alignment(self.0.get_position().justify_items.computed.0)
235    }
236}
237
238impl taffy::GridItemStyle for TaffyStyloStyleRef<'_> {
239    #[inline]
240    fn grid_row(&self) -> taffy::Line<taffy::GridPlacement> {
241        let position_styles = self.0.get_position();
242        taffy::Line {
243            start: convert::grid_line(&position_styles.grid_row_start),
244            end: convert::grid_line(&position_styles.grid_row_end),
245        }
246    }
247
248    #[inline]
249    fn grid_column(&self) -> taffy::Line<taffy::GridPlacement> {
250        let position_styles = self.0.get_position();
251        taffy::Line {
252            start: convert::grid_line(&position_styles.grid_column_start),
253            end: convert::grid_line(&position_styles.grid_column_end),
254        }
255    }
256
257    #[inline]
258    fn align_self(&self) -> Option<taffy::AlignSelf> {
259        convert::item_alignment(self.0.get_position().align_self.0 .0)
260    }
261
262    #[inline]
263    fn justify_self(&self) -> Option<taffy::AlignSelf> {
264        convert::item_alignment(self.0.get_position().justify_self.0 .0)
265    }
266}