euv_example/pages/lab/
fn.rs1use super::*;
2
3pub(crate) fn mount_lab_architecture_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
14 let nav_items: Vec<(String, String)> = vec![
15 (
16 LAB_NAV_ARCH_LABEL.to_string(),
17 LAB_NAV_ARCH_DESC.to_string(),
18 ),
19 (LAB_NAV_3D_LABEL.to_string(), LAB_NAV_3D_DESC.to_string()),
20 (
21 LAB_NAV_MEDIA_LABEL.to_string(),
22 LAB_NAV_MEDIA_DESC.to_string(),
23 ),
24 ];
25 let chart_data: Vec<EuvChartPoint> = vec![
26 EuvChartPoint::new("Mon".to_string(), 60.0),
27 EuvChartPoint::new("Tue".to_string(), 88.0),
28 EuvChartPoint::new("Wed".to_string(), 118.0),
29 EuvChartPoint::new("Thu".to_string(), 104.0),
30 EuvChartPoint::new("Fri".to_string(), 120.0),
31 EuvChartPoint::new("Sat".to_string(), 116.0),
32 ];
33 let trace_spans: Vec<EuvTraceSpan> = vec![
34 EuvTraceSpan::new(
35 LAB_TRACE_LAYOUT.to_string(),
36 0.14,
37 0.0,
38 0.12,
39 EuvTone::Primary,
40 ),
41 EuvTraceSpan::new(
42 LAB_TRACE_BVH.to_string(),
43 0.88,
44 0.12,
45 0.60,
46 EuvTone::Success,
47 ),
48 EuvTraceSpan::new(
49 LAB_TRACE_TONEMAP.to_string(),
50 0.24,
51 0.72,
52 0.16,
53 EuvTone::Warning,
54 ),
55 EuvTraceSpan::new(
56 LAB_TRACE_BLIT.to_string(),
57 0.16,
58 0.88,
59 0.12,
60 EuvTone::Neutral,
61 ),
62 ];
63 view! {
64 EuvCard {
65 title: LAB_ARCH_TITLE.to_string()
66 tokens: tokens
67 subtitle: LAB_ARCH_SUB
68 row {
69 style: c_action_row()
70 EuvMarker {
71 code: "01".to_string()
72 label: LAB_MARKER_ZERO.to_string()
73 tone: EuvTone::Primary
74 tokens: tokens
75 }
76 EuvMarker {
77 code: "02".to_string()
78 label: LAB_MARKER_FPS.to_string()
79 tone: EuvTone::Success
80 tokens: tokens
81 }
82 EuvMarker {
83 code: "03".to_string()
84 label: LAB_MARKER_FREEZE.to_string()
85 tone: EuvTone::Warning
86 tokens: tokens
87 }
88 }
89 EuvNavigationMenu {
90 items: nav_items
91 active: state.get_lab_nav_menu_active()
92 tokens: tokens
93 }
94 EuvChart {
95 title: LAB_CHART_TITLE.to_string()
96 kind: EuvChartKind::Bar
97 data: chart_data
98 tokens: tokens
99 }
100 EuvTrace {
101 title: LAB_TRACE_TITLE.to_string()
102 spans: trace_spans
103 tokens: tokens
104 }
105 }
106 }
107}
108
109pub(crate) fn mount_lab_scroll_recipe_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
120 let p: ThemePalette = tokens.get_palette();
121 let touches_sig: Signal<Vec<(u64, Point)>> = current_context().get_active_touches();
122 let block_scroll: Signal<bool> = state.get_lab_block_scroll_chain();
123 let stop_bubble: Signal<bool> = state.get_lab_stop_click_bubble();
124 let parent_clicks: Signal<u32> = state.get_lab_parent_clicks();
125 let child_clicks: Signal<u32> = state.get_lab_child_clicks();
126 let clicks_readout = move || -> String {
127 format!(
128 "Inner Clicks: {} | Outer Parent Clicks: {} | Active Touches: {}",
129 child_clicks.get(),
130 parent_clicks.get(),
131 touches_sig.get().len()
132 )
133 };
134 let build_nested_box = move || -> Vec<NodeId> {
135 let live_tok: ThemeTokens = live_tokens_untracked(tokens);
136 let live_p: ThemePalette = live_tok.get_palette();
137 let live_g: ThemeGeometry = live_tok.get_geometry();
138 let locked: bool = block_scroll.get();
139 let stop_clk: bool = stop_bubble.get();
140 let on_outer_click = move |_: &UiEvent| {
141 let _: bool = parent_clicks.update(|v: &mut u32| *v += 1);
142 };
143 let on_inner_click = move |_: &UiEvent| {
144 let _: bool = child_clicks.update(|v: &mut u32| *v += 1);
145 };
146 let rows: Vec<NodeId> = (1..=8_usize)
147 .map(|row_i: usize| {
148 let row_txt: String = format!(
149 "Nested Scroll Row #{row_i} (scroll_lock={locked}, stop_bubble={stop_clk})"
150 );
151 view! {
152 text {
153 style: {
154 width: Length::Percent(100.0)
155 font_size: 12.0
156 color: live_p.get_foreground()
157 }
158 { row_txt }
159 }
160 }
161 })
162 .collect();
163 vec![view! {
164 column {
165 style: {
166 width: Length::Percent(100.0)
167 padding: Edges::all(SPACE_MD)
168 gap: SPACE_SM
169 background: live_p.get_muted()
170 border: (live_g.get_border_width(), live_p.get_border())
171 radius: live_g.get_radius_md()
172 }
173 on_click: on_outer_click
174 scroll {
175 style: {
176 width: Length::Percent(100.0)
177 height: Length::Px(104.0)
178 padding: Edges::all(SPACE_SM)
179 gap: SPACE_XS
180 background: live_p.get_card()
181 border: (live_g.get_border_width(), live_p.get_border())
182 radius: live_g.get_radius_sm()
183 stop_scroll_propagation: locked
184 stop_event_propagation: stop_clk
185 }
186 ..rows
187 }
188 EuvActionRow {
189 EuvButton {
190 label: LAB_BTN_INNER_TARGET.to_string()
191 tokens: live_tok
192 outline()
193 sm()
194 on_click: on_inner_click
195 }
196 }
197 }
198 }]
199 };
200 view! {
201 EuvCard {
202 title: LAB_SCROLL_TITLE.to_string()
203 tokens: tokens
204 subtitle: LAB_SCROLL_SUB
205 column {
206 style: {
207 width: Length::Percent(100.0)
208 gap: SPACE_SM
209 }
210 EuvSwitch {
211 checked: block_scroll
212 label: LAB_SWITCH_SCROLL_LOCK.to_string()
213 tokens: tokens
214 }
215 EuvSwitch {
216 checked: stop_bubble
217 label: LAB_SWITCH_STOP_BUBBLE.to_string()
218 tokens: tokens
219 }
220 text {
221 style: {
222 width: Length::Percent(100.0)
223 font_size: 12.0
224 color: p.get_muted_foreground()
225 }
226 { clicks_readout }
227 }
228 column {
229 style: {
230 width: Length::Percent(100.0)
231 }
232 bind_children: build_nested_box
233 }
234 }
235 }
236 }
237}
238
239pub(crate) fn mount_lab_rtl_recipe_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
250 let p: ThemePalette = tokens.get_palette();
251 let rtl_sig: Signal<bool> = state.get_lab_rtl_mode();
252 let preserve_cnt: Signal<u32> = state.get_lab_resize_preserve_count();
253 let on_increment = move |_: &UiEvent| {
254 let _: bool = preserve_cnt.update(|v: &mut u32| *v += 1);
255 };
256 let counter_readout = move || -> String {
257 format!(
258 "Resize-Preserved Counter: {} | Direction: {}",
259 preserve_cnt.get(),
260 if rtl_sig.get() { "RTL" } else { "LTR" }
261 )
262 };
263 let build_dir_preview = move || -> Vec<NodeId> {
264 let live_tok: ThemeTokens = live_tokens_untracked(tokens);
265 let live_p: ThemePalette = live_tok.get_palette();
266 let dir: EuvTextDirection = if rtl_sig.get() {
267 EuvTextDirection::Rtl
268 } else {
269 EuvTextDirection::Ltr
270 };
271 let dir_label: String =
272 format!("Direction preview ({dir:?}): Unified layout alignment across LTR & RTL");
273 let child_node: NodeId = view! {
274 text {
275 style: {
276 width: Length::Percent(100.0)
277 font_size: 13.0
278 color: live_p.get_foreground()
279 }
280 { dir_label }
281 }
282 };
283 vec![view! {
284 EuvDirection {
285 direction: dir
286 child: child_node
287 tokens: live_tok
288 }
289 }]
290 };
291 view! {
292 EuvCard {
293 title: LAB_RTL_TITLE.to_string()
294 tokens: tokens
295 subtitle: LAB_RTL_SUB
296 column {
297 style: {
298 width: Length::Percent(100.0)
299 gap: SPACE_MD
300 }
301 EuvSwitch {
302 checked: rtl_sig
303 label: LAB_SWITCH_RTL.to_string()
304 tokens: tokens
305 }
306 column {
307 style: {
308 width: Length::Percent(100.0)
309 }
310 bind_children: build_dir_preview
311 }
312 EuvActionRow {
313 EuvButton {
314 label: LAB_BTN_PRESERVE.to_string()
315 tokens: tokens
316 sm()
317 on_click: on_increment
318 }
319 }
320 text {
321 style: {
322 width: Length::Percent(100.0)
323 font_size: 12.0
324 color: p.get_muted_foreground()
325 }
326 { counter_readout }
327 }
328 }
329 }
330 }
331}
332
333pub(crate) fn mount_lab_settings_recipe_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
344 let p: ThemePalette = tokens.get_palette();
345 let autosave: Signal<bool> = Signal::new(true);
346 let record_traces: Signal<bool> = Signal::new(false);
347 let split_ratio: Signal<f32> = state.get_lab_split_ratio();
348 let settings_summary = move || -> String {
349 format!(
350 "Split: {:.0}% | Auto-save: {} | Traces: {}",
351 split_ratio.get() * 100.0,
352 autosave.get(),
353 record_traces.get()
354 )
355 };
356 let left_pane: NodeId = view! {
357 column {
358 style: {
359 width: Length::Percent(100.0)
360 gap: SPACE_SM
361 }
362 text {
363 style: {
364 width: Length::Percent(100.0)
365 font_size: 13.0
366 font_weight: FontWeight::SemiBold
367 color: p.get_foreground()
368 }
369 { LAB_SPLIT_LEFT_HEAD }
370 }
371 EuvSwitch {
372 checked: autosave
373 label: LAB_SWITCH_AUTOSAVE.to_string()
374 tokens: tokens
375 }
376 EuvSwitch {
377 checked: record_traces
378 label: LAB_SWITCH_TELEMETRY.to_string()
379 tokens: tokens
380 }
381 }
382 };
383 let right_pane: NodeId = view! {
384 column {
385 style: {
386 width: Length::Percent(100.0)
387 gap: SPACE_SM
388 }
389 text {
390 style: {
391 width: Length::Percent(100.0)
392 font_size: 13.0
393 font_weight: FontWeight::SemiBold
394 color: p.get_foreground()
395 }
396 { LAB_SPLIT_RIGHT_HEAD }
397 }
398 text {
399 style: {
400 width: Length::Percent(100.0)
401 font_size: 12.5
402 color: p.get_muted_foreground()
403 }
404 { LAB_SPLIT_RIGHT_DESC }
405 }
406 text {
407 style: {
408 width: Length::Percent(100.0)
409 font_size: 12.0
410 color: p.get_primary()
411 }
412 { settings_summary }
413 }
414 }
415 };
416 view! {
417 EuvCard {
418 title: LAB_SETTINGS_TITLE.to_string()
419 tokens: tokens
420 subtitle: LAB_SETTINGS_SUB
421 EuvResizable {
422 left: left_pane
423 right: right_pane
424 split_ratio: split_ratio
425 tokens: tokens
426 }
427 }
428 }
429}
430
431pub(crate) fn mount_lab_thread_recipe_card(tokens: ThemeTokens) -> NodeId {
441 let attach_vis: Signal<bool> = Signal::new(true);
442 let poll_sel: Signal<Option<usize>> = Signal::new(Some(0));
443 let poll_options: Vec<String> = vec![
444 LAB_POLL_OPT_1.to_string(),
445 LAB_POLL_OPT_2.to_string(),
446 LAB_POLL_OPT_3.to_string(),
447 ];
448 view! {
449 EuvCard {
450 title: LAB_THREAD_TITLE.to_string()
451 tokens: tokens
452 subtitle: LAB_THREAD_SUB
453 column {
454 style: {
455 width: Length::Percent(100.0)
456 gap: SPACE_MD
457 }
458 EuvBubble {
459 author: LAB_BUBBLE_BOT_AUTHOR.to_string()
460 content: LAB_BUBBLE_BOT_BODY.to_string()
461 tokens: tokens
462 timestamp: LAB_TIME_A
463 }
464 EuvBubble {
465 author: LAB_BUBBLE_DEV_AUTHOR.to_string()
466 content: LAB_BUBBLE_DEV_BODY.to_string()
467 tokens: tokens
468 timestamp: LAB_TIME_B
469 outgoing: true
470 }
471 EuvAttachment {
472 filename: LAB_ATTACH_FILE.to_string()
473 meta: LAB_ATTACH_META.to_string()
474 visible: attach_vis
475 tokens: tokens
476 }
477 EuvQuestionnaire {
478 prompt: LAB_POLL_PROMPT.to_string()
479 options: poll_options
480 selected: poll_sel
481 tokens: tokens
482 }
483 }
484 }
485 }
486}
487
488pub fn mount_lab_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
499 let arch_card: NodeId = mount_lab_architecture_card(state, tokens);
500 let recipe_cards: Vec<NodeId> = vec![
501 mount_lab_scroll_recipe_card(state, tokens),
502 mount_lab_rtl_recipe_card(state, tokens),
503 mount_lab_settings_recipe_card(state, tokens),
504 mount_lab_thread_recipe_card(tokens),
505 ];
506 let recipes_grid: NodeId = mount_responsive_grid(recipe_cards, 2);
507 view! {
508 EuvPage {
509 title: LAB_TITLE.to_string()
510 subtitle: LAB_SUBTITLE.to_string()
511 tokens: tokens
512 { arch_card }
513 { recipes_grid }
514 }
515 }
516}