1#[allow(unused)]
2use crate::*;
3use pax_engine::api::*;
4use pax_engine::*;
5
6const PIXEL_ALIGN_FACTOR: f64 = 1.0;
7
8#[pax]
14#[engine_import_path("pax_engine")]
15#[inlined(
16for i in 0..self._slots {
17 slot(i)
18}
19<Rectangle fill=GREEN/>
20@settings {
21 @mount: on_mount,
22}
23)]
24pub struct Table {
25 pub rows: Property<usize>,
27 pub columns: Property<usize>,
29 pub _slots: Property<usize>,
31}
32
33pub struct TableContext {
35 rows: Property<usize>,
36 columns: Property<usize>,
37}
38
39impl Store for TableContext {}
40
41impl Table {
42 pub fn on_mount(&mut self, ctx: &NodeContext) {
44 ctx.push_local_store(TableContext {
45 rows: self.rows.clone(),
46 columns: self.columns.clone(),
47 });
48 let projected_children = ctx.projected_children_count.clone();
49 let deps = [projected_children.untyped()];
50 self._slots
51 .replace_with(Property::computed(move || projected_children.get(), &deps));
52 }
53}
54
55#[pax]
57#[engine_import_path("pax_engine")]
58#[inlined(
59<Group anchor_y=0% y={self._y_pos} height={self._height} width=100%>
60 for i in 0..self._slots {
61 slot(i)
62 }
63</Group>
64@settings {
65 @mount: on_mount,
66}
67)]
68pub struct Row {
69 pub y: Property<usize>,
71 pub _y_pos: Property<Size>,
73 pub _height: Property<Size>,
75 pub _slots: Property<usize>,
77}
78
79impl Row {
80 pub fn on_mount(&mut self, ctx: &NodeContext) {
82 ctx.peek_local_store(|table_ctx: &mut TableContext| {
83 let rows = table_ctx.rows.clone();
84 let deps = [rows.untyped()];
85 self._height.replace_with(Property::computed(
86 move || Size::Percent((PIXEL_ALIGN_FACTOR * 100.0 / rows.get() as f64).into()),
87 &deps,
88 ));
89 let rows = table_ctx.rows.clone();
90 let y = self.y.clone();
91 let deps = [rows.untyped(), y.untyped()];
92 self._y_pos.replace_with(Property::computed(
93 move || {
94 Size::Percent(
95 (PIXEL_ALIGN_FACTOR * y.get() as f64 * 100.0 / rows.get() as f64).into(),
96 )
97 },
98 &deps,
99 ));
100 })
101 .expect("rows can not exist outside a table");
102 let projected_children = ctx.projected_children_count.clone();
103 let deps = [projected_children.untyped()];
104 self._slots
105 .replace_with(Property::computed(move || projected_children.get(), &deps));
106 }
107}
108
109#[pax]
111#[engine_import_path("pax_engine")]
112#[inlined(
113<Group anchor_x=0% x={self._x_pos} width={self._width} height=100%>
114 for i in 0..self._slots {
115 slot(i)
116 }
117</Group>
118@settings {
119 @mount: on_mount,
120}
121)]
122pub struct Col {
123 pub x: Property<usize>,
125 pub _x_pos: Property<Size>,
127 pub _width: Property<Size>,
129 pub _slots: Property<usize>,
131}
132
133impl Col {
134 pub fn on_mount(&mut self, ctx: &NodeContext) {
136 ctx.peek_local_store(|table_ctx: &mut TableContext| {
137 let columns = table_ctx.columns.clone();
138 let deps = [columns.untyped()];
139 self._width.replace_with(Property::computed(
140 move || Size::Percent((PIXEL_ALIGN_FACTOR * 100.0 / columns.get() as f64).into()),
141 &deps,
142 ));
143 let columns = table_ctx.columns.clone();
144 let x = self.x.clone();
145 let deps = [columns.untyped(), x.untyped()];
146 self._x_pos.replace_with(Property::computed(
147 move || {
148 Size::Percent(
149 (PIXEL_ALIGN_FACTOR * x.get() as f64 * 100.0 / columns.get() as f64).into(),
150 )
151 },
152 &deps,
153 ));
154 })
155 .expect("columns can not exist outside a table");
156 let projected_children = ctx.projected_children_count.clone();
157 let deps = [projected_children.untyped()];
158 self._slots
159 .replace_with(Property::computed(move || projected_children.get(), &deps));
160 }
161}
162
163#[pax]
165#[engine_import_path("pax_engine")]
166#[inlined(
167<Group
168 anchor_x=0%
169 x={self._x_pos}
170 width={self._width}
171 anchor_y=0%
172 y={self._y_pos}
173 height={self._height}>
174
175 for i in 0..self._slots {
176 slot(i)
177 }
178</Group>
179@settings {
180 @mount: on_mount,
181}
182)]
183pub struct Span {
184 pub x: Property<usize>,
186 pub y: Property<usize>,
188 pub w: Property<usize>,
190 pub h: Property<usize>,
192
193 pub _x_pos: Property<Size>,
195 pub _y_pos: Property<Size>,
197 pub _width: Property<Size>,
199 pub _height: Property<Size>,
201 pub _slots: Property<usize>,
203}
204
205impl Span {
206 pub fn on_mount(&mut self, ctx: &NodeContext) {
208 ctx.peek_local_store(|table_ctx: &mut TableContext| {
209 let rows = table_ctx.rows.clone();
210 let h = self.h.clone();
211 let deps = [rows.untyped(), h.untyped()];
212 self._height.replace_with(Property::computed(
213 move || {
214 Size::Percent(
215 (PIXEL_ALIGN_FACTOR * h.get() as f64 * 100.0 / rows.get() as f64).into(),
216 )
217 },
218 &deps,
219 ));
220 let rows = table_ctx.rows.clone();
221 let y = self.y.clone();
222 let deps = [rows.untyped(), y.untyped()];
223 self._y_pos.replace_with(Property::computed(
224 move || {
225 Size::Percent(
226 (PIXEL_ALIGN_FACTOR * y.get() as f64 * 100.0 / rows.get() as f64).into(),
227 )
228 },
229 &deps,
230 ));
231 let columns = table_ctx.columns.clone();
232 let w = self.w.clone();
233 let deps = [columns.untyped(), w.untyped()];
234 self._width.replace_with(Property::computed(
235 move || {
236 Size::Percent(
237 (PIXEL_ALIGN_FACTOR * w.get() as f64 * 100.0 / columns.get() as f64).into(),
238 )
239 },
240 &deps,
241 ));
242 let columns = table_ctx.columns.clone();
243 let x = self.x.clone();
244 let deps = [columns.untyped(), x.untyped()];
245 self._x_pos.replace_with(Property::computed(
246 move || {
247 Size::Percent(
248 (PIXEL_ALIGN_FACTOR * x.get() as f64 * 100.0 / columns.get() as f64).into(),
249 )
250 },
251 &deps,
252 ));
253 })
254 .expect("columns can not exist outside a table");
255 let projected_children = ctx.projected_children_count.clone();
256 let deps = [projected_children.untyped()];
257 self._slots
258 .replace_with(Property::computed(move || projected_children.get(), &deps));
259 }
260}
261
262#[pax]
264#[engine_import_path("pax_engine")]
265#[inlined(
266<Group
267 anchor_x=0%
268 x={self._x_pos}
269 width={self._width}
270 anchor_y=0%
271 y={self._y_pos}
272 height={self._height}>
273
274 for i in 0..self._slots {
275 slot(i)
276 }
277</Group>
278@settings {
279 @mount: on_mount,
280}
281)]
282pub struct Cell {
283 pub x: Property<usize>,
285 pub y: Property<usize>,
287
288 pub _x_pos: Property<Size>,
290 pub _y_pos: Property<Size>,
292 pub _width: Property<Size>,
294 pub _height: Property<Size>,
296 pub _slots: Property<usize>,
298}
299
300impl Cell {
301 pub fn on_mount(&mut self, ctx: &NodeContext) {
303 ctx.peek_local_store(|table_ctx: &mut TableContext| {
304 let rows = table_ctx.rows.clone();
305 let deps = [rows.untyped()];
306 self._height.replace_with(Property::computed(
307 move || Size::Percent((PIXEL_ALIGN_FACTOR * 100.0 / rows.get() as f64).into()),
308 &deps,
309 ));
310 let rows = table_ctx.rows.clone();
311 let y = self.y.clone();
312 let deps = [rows.untyped(), y.untyped()];
313 self._y_pos.replace_with(Property::computed(
314 move || {
315 Size::Percent(
316 (PIXEL_ALIGN_FACTOR * y.get() as f64 * 100.0 / rows.get() as f64).into(),
317 )
318 },
319 &deps,
320 ));
321 let columns = table_ctx.columns.clone();
322 let deps = [columns.untyped()];
323 self._width.replace_with(Property::computed(
324 move || Size::Percent((PIXEL_ALIGN_FACTOR * 100.0 / columns.get() as f64).into()),
325 &deps,
326 ));
327 let columns = table_ctx.columns.clone();
328 let x = self.x.clone();
329 let deps = [columns.untyped(), x.untyped()];
330 self._x_pos.replace_with(Property::computed(
331 move || {
332 Size::Percent(
333 (PIXEL_ALIGN_FACTOR * x.get() as f64 * 100.0 / columns.get() as f64).into(),
334 )
335 },
336 &deps,
337 ));
338 })
339 .expect("columns can not exist outside a table");
340 let projected_children = ctx.projected_children_count.clone();
341 let deps = [projected_children.untyped()];
342 self._slots
343 .replace_with(Property::computed(move || projected_children.get(), &deps));
344 }
345}