⎇ f60ac6d66a6ef25060b5a053b541ed3b7de8e3af
taffy_stylo/src/arc.rs
Ñawpa willay
Pi imata llamkarqan
ch'uya
Add borrowed version of taffy_stylo interop
1use servo_arc::Arc;
2use crate::{t2s, stylo};
3
4pub struct TaffyStyloStyle(pub Arc<stylo::ComputedValues>);
5
6impl From<Arc<stylo::ComputedValues>> for TaffyStyloStyle {
7 fn from(value: Arc<stylo::ComputedValues>) -> Self {
8 Self(Arc::clone(&value))
9 }
10}
11
12impl taffy::CoreStyle for TaffyStyloStyle {
13 #[inline]
14 fn box_generation_mode(&self) -> taffy::BoxGenerationMode {
15 t2s::box_generation_mode(self.0.get_box().display)
16 }
17
18 #[inline]
19 fn is_block(&self) -> bool {
20 t2s::is_block(self.0.get_box().display)
21 }
22
23 #[inline]
24 fn overflow(&self) -> taffy::Point<taffy::Overflow> {
25 let box_styles = self.0.get_box();
26 taffy::Point { x: t2s::overflow(box_styles.overflow_x), y: t2s::overflow(box_styles.overflow_y) }
27 }
28
29 #[inline]
30 fn scrollbar_width(&self) -> f32 {
31 0.0
32 }
33
34 #[inline]
35 fn position(&self) -> taffy::Position {
36 t2s::position(self.0.get_box().position)
37 }
38
39 #[inline]
40 fn inset(&self) -> taffy::Rect<taffy::LengthPercentageAuto> {
41 let position_styles = self.0.get_position();
42 taffy::Rect {
43 left: t2s::length_percentage_auto(&position_styles.left),
44 right: t2s::length_percentage_auto(&position_styles.right),
45 top: t2s::length_percentage_auto(&position_styles.top),
46 bottom: t2s::length_percentage_auto(&position_styles.bottom),
47 }
48 }
49
50 #[inline]
51 fn size(&self) -> taffy::Size<taffy::Dimension> {
52 let position_styles = self.0.get_position();
53 taffy::Size { width: t2s::dimension(&position_styles.width), height: t2s::dimension(&position_styles.height) }
54 }
55
56 #[inline]
57 fn min_size(&self) -> taffy::Size<taffy::Dimension> {
58 let position_styles = self.0.get_position();
59 taffy::Size {
60 width: t2s::dimension(&position_styles.min_width),
61 height: t2s::dimension(&position_styles.min_height),
62 }
63 }
64
65 #[inline]
66 fn max_size(&self) -> taffy::Size<taffy::Dimension> {
67 let position_styles = self.0.get_position();
68 taffy::Size {
69 width: t2s::max_size_dimension(&position_styles.max_width),
70 height: t2s::max_size_dimension(&position_styles.max_height),
71 }
72 }
73
74 #[inline]
75 fn aspect_ratio(&self) -> Option<f32> {
76 t2s::aspect_ratio(self.0.get_position().aspect_ratio)
77 }
78
79 #[inline]
80 fn margin(&self) -> taffy::Rect<taffy::LengthPercentageAuto> {
81 let margin_styles = self.0.get_margin();
82 taffy::Rect {
83 left: t2s::length_percentage_auto(&margin_styles.margin_left),
84 right: t2s::length_percentage_auto(&margin_styles.margin_right),
85 top: t2s::length_percentage_auto(&margin_styles.margin_top),
86 bottom: t2s::length_percentage_auto(&margin_styles.margin_bottom),
87 }
88 }
89
90 #[inline]
91 fn padding(&self) -> taffy::Rect<taffy::LengthPercentage> {
92 let padding_styles = self.0.get_padding();
93 taffy::Rect {
94 left: t2s::length_percentage(&padding_styles.padding_left.0),
95 right: t2s::length_percentage(&padding_styles.padding_right.0),
96 top: t2s::length_percentage(&padding_styles.padding_top.0),
97 bottom: t2s::length_percentage(&padding_styles.padding_bottom.0),
98 }
99 }
100
101 #[inline]
102 fn border(&self) -> taffy::Rect<taffy::LengthPercentage> {
103 let border_styles = self.0.get_border();
104 taffy::Rect {
105 left: taffy::LengthPercentage::Length(border_styles.border_left_width.to_f32_px()),
106 right: taffy::LengthPercentage::Length(border_styles.border_right_width.to_f32_px()),
107 top: taffy::LengthPercentage::Length(border_styles.border_top_width.to_f32_px()),
108 bottom: taffy::LengthPercentage::Length(border_styles.border_bottom_width.to_f32_px()),
109 }
110 }
111}
112
113impl taffy::FlexboxContainerStyle for TaffyStyloStyle {
114 #[inline]
115 fn flex_direction(&self) -> taffy::FlexDirection {
116 t2s::flex_direction(self.0.get_position().flex_direction)
117 }
118
119 #[inline]
120 fn flex_wrap(&self) -> taffy::FlexWrap {
121 t2s::flex_wrap(self.0.get_position().flex_wrap)
122 }
123
124 #[inline]
125 fn gap(&self) -> taffy::Size<taffy::LengthPercentage> {
126 let position_styles = self.0.get_position();
127 taffy::Size {
128 width: t2s::gap(&position_styles.column_gap),
129 height: taffy::LengthPercentage::Length(0.0), // TODO: enable row_gap in stylo
130 }
131 }
132
133 #[inline]
134 fn align_content(&self) -> Option<taffy::AlignContent> {
135 t2s::align_content(self.0.get_position().align_content)
136 }
137
138 #[inline]
139 fn align_items(&self) -> Option<taffy::AlignItems> {
140 t2s::align_items(self.0.get_position().align_items)
141 }
142
143 #[inline]
144 fn justify_content(&self) -> Option<taffy::JustifyContent> {
145 t2s::justify_content(self.0.get_position().justify_content)
146 }
147}
148
149impl taffy::FlexboxItemStyle for TaffyStyloStyle {
150 #[inline]
151 fn flex_basis(&self) -> taffy::Dimension {
152 t2s::flex_basis(&self.0.get_position().flex_basis)
153 }
154
155 #[inline]
156 fn flex_grow(&self) -> f32 {
157 self.0.get_position().flex_grow.0
158 }
159
160 #[inline]
161 fn flex_shrink(&self) -> f32 {
162 self.0.get_position().flex_grow.0
163 }
164
165 #[inline]
166 fn align_self(&self) -> Option<taffy::AlignSelf> {
167 t2s::align_self(self.0.get_position().align_self)
168 }
169}