1#[allow(unused)]
2use crate::*;
3use pax_engine::api::{Duration, Opacity, Property};
4use pax_engine::pax;
5use pax_runtime::api::NodeContext;
6
7#[pax]
24#[engine_import_path("pax_engine")]
25#[inlined(<Group/>)]
26pub struct Router {}
27
28#[pax]
34#[engine_import_path("pax_engine")]
35#[route_branch(path = "path", default = "default")]
36#[inlined(
37 <Group width=100% height=100% anchor_x=0% anchor_y=0%>
38 for i in 0..self._projected_children_count {
39 slot(i)
40 }
41 </Group>
42
43 @settings {
44 @mount: on_mount
45 }
46)]
47pub struct Route {
48 pub path: Property<String>,
53 pub r#default: Property<bool>,
55 pub _projected_children_count: Property<usize>,
57}
58
59#[pax]
66#[engine_import_path("pax_engine")]
67#[custom(Default)]
68#[route_branch(path = "path", default = "default", modal = true)]
69#[inlined(
70 <Group width=100% height=100% anchor_x=0% anchor_y=0%>
71 <Group width=100% height=100% anchor_x=0% anchor_y=0%>
72 for i in 0..self._projected_children_count {
73 slot(i)
74 }
75 </Group>
76 <EventBlocker
77 width=100%
78 height=100%
79 background=rgba(0, 0, 0, 255)
80 opacity={self.scrim_opacity}
81 @in=@timeline {
82 duration: {self.duration},
83 opacity: {
84 0: 0, Linear,
85 100%: {$base},
86 },
87 }
88 @out=@timeline {
89 duration: {self.duration},
90 opacity: {
91 0: {$base}, Linear,
92 100%: 0,
93 },
94 }
95 />
96 </Group>
97
98 @settings {
99 @mount: on_mount
100 }
101)]
102pub struct RouteModal {
103 pub path: Property<String>,
105 pub r#default: Property<bool>,
107 pub duration: Property<Duration>,
109 pub scrim_opacity: Property<Opacity>,
113 pub _projected_children_count: Property<usize>,
115}
116
117#[pax]
126#[engine_import_path("pax_engine")]
127#[custom(Default)]
128#[route_branch(path = "path", default = "default", modal = true)]
129#[inlined(
130 <Group width=100% height=100% anchor_x=0% anchor_y=0%>
131 <Group
132 id=card_shell
133 width=100%
134 height=100%
135 anchor_x=0%
136 anchor_y=0%
137 @in=@timeline {
138 duration: {self.duration},
139 x: {
140 0: {self.edge == RouteCardEdge::Leading ? $base - 100% : self.edge == RouteCardEdge::Trailing ? $base + 100% : $base}, OutQuad,
141 100%: {$base},
142 },
143 y: {
144 0: {self.edge == RouteCardEdge::Top ? $base - 100% : self.edge == RouteCardEdge::Bottom ? $base + 100% : $base}, OutQuad,
145 100%: {$base},
146 },
147 }
148 @out=@timeline {
149 duration: {self.duration},
150 x: {
151 0: {$base}, OutQuad,
152 100%: {self.edge == RouteCardEdge::Leading ? $base - 100% : self.edge == RouteCardEdge::Trailing ? $base + 100% : $base},
153 },
154 y: {
155 0: {$base}, OutQuad,
156 100%: {self.edge == RouteCardEdge::Top ? $base - 100% : self.edge == RouteCardEdge::Bottom ? $base + 100% : $base},
157 },
158 }
159 >
160 for i in 0..self._projected_children_count {
161 slot(i)
162 }
163 </Group>
164 <EventBlocker
165 width=100%
166 height=100%
167 background=rgba(0, 0, 0, 255)
168 opacity={self.scrim_opacity}
169 @in=@timeline {
170 duration: {self.duration},
171 opacity: {
172 0: 0, Linear,
173 100%: {$base},
174 },
175 }
176 @out=@timeline {
177 duration: {self.duration},
178 opacity: {
179 0: {$base}, Linear,
180 100%: 0,
181 },
182 }
183 />
184 </Group>
185
186 @settings {
187 @mount: on_mount
188 }
189)]
190pub struct RouteCard {
191 pub path: Property<String>,
193 pub r#default: Property<bool>,
195 pub edge: Property<RouteCardEdge>,
197 pub duration: Property<Duration>,
199 pub scrim_opacity: Property<Opacity>,
203 pub curve: Property<RouteCardCurve>,
205 pub _projected_children_count: Property<usize>,
207}
208
209#[pax]
211#[engine_import_path("pax_engine")]
212pub enum RouteCardEdge {
213 Leading,
214 #[default]
215 Trailing,
216 Top,
217 Bottom,
218}
219
220#[pax]
222#[engine_import_path("pax_engine")]
223pub enum RouteCardCurve {
224 Linear,
225 Hold,
226 InQuad,
227 #[default]
228 OutQuad,
229 InOutQuad,
230 InBack,
231 OutBack,
232 InOutBack,
233}
234
235impl Route {
236 pub fn on_mount(&mut self, ctx: &NodeContext) {
237 let projected_children_count = ctx.projected_children_count.clone();
238 let deps = [projected_children_count.untyped()];
239 self._projected_children_count
240 .replace_with(Property::computed(
241 move || projected_children_count.get(),
242 &deps,
243 ));
244 }
245}
246
247impl Default for RouteModal {
248 fn default() -> Self {
249 Self {
250 path: Property::default(),
251 r#default: Property::new(false),
252 duration: Property::new(Duration::Frames(18.into())),
253 scrim_opacity: Property::new(Opacity::Alpha(0.3.into())),
254 _projected_children_count: Property::new(0),
255 }
256 }
257}
258
259impl RouteModal {
260 pub fn on_mount(&mut self, ctx: &NodeContext) {
261 let projected_children_count = ctx.projected_children_count.clone();
262 let deps = [projected_children_count.untyped()];
263 self._projected_children_count
264 .replace_with(Property::computed(
265 move || projected_children_count.get(),
266 &deps,
267 ));
268 }
269}
270
271impl Default for RouteCard {
272 fn default() -> Self {
273 Self {
274 path: Property::default(),
275 r#default: Property::new(false),
276 edge: Property::new(RouteCardEdge::Trailing),
277 duration: Property::new(Duration::Frames(18.into())),
278 scrim_opacity: Property::new(Opacity::Alpha(0.3.into())),
279 curve: Property::new(RouteCardCurve::OutQuad),
280 _projected_children_count: Property::new(0),
281 }
282 }
283}
284
285impl RouteCard {
286 pub fn on_mount(&mut self, ctx: &NodeContext) {
287 let projected_children_count = ctx.projected_children_count.clone();
288 let deps = [projected_children_count.untyped()];
289 self._projected_children_count
290 .replace_with(Property::computed(
291 move || projected_children_count.get(),
292 &deps,
293 ));
294 }
295}