Skip to main content

euv_example/pages/lab/
fn.rs

1use super::*;
2
3/// Mounts the Architecture Case Study card with persistent `EuvNavigationMenu` tabs, uniform `SPACE_MD` spacing to the sibling telemetry chart, and a compact frame trace.
4///
5/// # Arguments
6///
7/// - `&ShowcaseState` - Reactive showcase state.
8/// - `ThemeTokens` - Active design tokens.
9///
10/// # Returns
11///
12/// - `NodeId` - Mounted architecture case study card node.
13pub(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
109/// Mounts the Scroll Chaining & Click Bubbling interactive recipe card.
110///
111/// # Arguments
112///
113/// - `&ShowcaseState` - Reactive showcase state.
114/// - `ThemeTokens` - Active design tokens.
115///
116/// # Returns
117///
118/// - `NodeId` - Mounted scroll and bubbling recipe card node.
119pub(crate) fn mount_lab_scroll_recipe_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
120    let palette: 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.set(parent_clicks.get_untracked() + 1);
142        };
143        let on_inner_click = move |_: &UiEvent| {
144            let _: bool = child_clicks.set(child_clicks.get_untracked() + 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                let text_eighth_style: Style = style! {
152                    Width(Length::Percent(100.0))
153                    FontSize(12.0)
154                    TextColor(live_p.get_foreground())
155                };
156                view! {
157                    text {
158                        style: text_eighth_style
159                        { row_txt }
160                    }
161                }
162            })
163            .collect();
164        vec![{
165            let column_eighth_style: Style = 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::new(live_g.get_border_width(), live_p.get_border())
171                Radius(live_g.get_radius_md())
172            };
173            let scroll_style: Style = style! {
174                Width(Length::Percent(100.0))
175                Height(Length::Px(104.0))
176                Padding(Edges::all(SPACE_SM))
177                Gap(SPACE_XS)
178                Background(live_p.get_card())
179                Border::new(live_g.get_border_width(), live_p.get_border())
180                Radius(live_g.get_radius_sm())
181                StopScrollPropagation(locked)
182                StopEventPropagation(stop_clk)
183            };
184            view! {
185                column {
186                    style: column_eighth_style
187                    on_click: on_outer_click
188                    scroll {
189                        style: scroll_style
190                        ..rows
191                    }
192                    EuvActionRow {
193                        EuvButton {
194                            label: LAB_BTN_INNER_TARGET.to_string()
195                            tokens: live_tok
196                            outline()
197                            small()
198                            on_click: on_inner_click
199                        }
200                    }
201                }
202            }
203        }]
204    };
205    let column_sixth_style: Style = style! {
206        Width(Length::Percent(100.0))
207        Gap(SPACE_SM)
208    };
209    let text_seventh_style: Style = style! {
210        Width(Length::Percent(100.0))
211        FontSize(12.0)
212        TextColor(palette.get_muted_foreground())
213    };
214    let column_seventh_style: Style = style! {
215        Width(Length::Percent(100.0))
216    };
217    view! {
218        EuvCard {
219            title: LAB_SCROLL_TITLE.to_string()
220            tokens: tokens
221            subtitle: LAB_SCROLL_SUB
222            column {
223                style: column_sixth_style
224                EuvSwitch {
225                    checked: block_scroll
226                    label: LAB_SWITCH_SCROLL_LOCK.to_string()
227                    tokens: tokens
228                }
229                EuvSwitch {
230                    checked: stop_bubble
231                    label: LAB_SWITCH_STOP_BUBBLE.to_string()
232                    tokens: tokens
233                }
234                text {
235                    style: text_seventh_style
236                    { clicks_readout }
237                }
238                column {
239                    style: column_seventh_style
240                    bind_children: build_nested_box
241                }
242            }
243        }
244    }
245}
246
247/// Mounts the RTL Direction & Resize-Safe State recipe card preserving `Increment Preserved Counter`.
248///
249/// # Arguments
250///
251/// - `&ShowcaseState` - Reactive showcase state.
252/// - `ThemeTokens` - Active design tokens.
253///
254/// # Returns
255///
256/// - `NodeId` - Mounted RTL and state-preservation recipe card node.
257pub(crate) fn mount_lab_rtl_recipe_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
258    let palette: ThemePalette = tokens.get_palette();
259    let rtl_sig: Signal<bool> = state.get_lab_rtl_mode();
260    let preserve_cnt: Signal<u32> = state.get_lab_resize_preserve_count();
261    let on_increment = move |_: &UiEvent| {
262        let _: bool = preserve_cnt.set(preserve_cnt.get_untracked() + 1);
263    };
264    let counter_readout = move || -> String {
265        format!(
266            "Resize-Preserved Counter: {} | Direction: {}",
267            preserve_cnt.get(),
268            if rtl_sig.get() { "RTL" } else { "LTR" }
269        )
270    };
271    let build_dir_preview = move || -> Vec<NodeId> {
272        let live_tok: ThemeTokens = live_tokens_untracked(tokens);
273        let live_p: ThemePalette = live_tok.get_palette();
274        let dir: EuvTextDirection = if rtl_sig.get() {
275            EuvTextDirection::Rtl
276        } else {
277            EuvTextDirection::Ltr
278        };
279        let dir_label: String =
280            format!("Direction preview ({dir:?}): Unified layout alignment across LTR & RTL");
281        let text_sixth_style: Style = style! {
282            Width(Length::Percent(100.0))
283            FontSize(13.0)
284            TextColor(live_p.get_foreground())
285        };
286        let child_node: NodeId = view! {
287            text {
288                style: text_sixth_style
289                { dir_label }
290            }
291        };
292        vec![view! {
293            EuvDirection {
294                direction: dir
295                child: child_node
296                tokens: live_tok
297            }
298        }]
299    };
300    let column_quaternary_style: Style = style! {
301        Width(Length::Percent(100.0))
302        Gap(SPACE_MD)
303    };
304    let column_fifth_style: Style = style! {
305        Width(Length::Percent(100.0))
306    };
307    let text_fifth_style: Style = style! {
308        Width(Length::Percent(100.0))
309        FontSize(12.0)
310        TextColor(palette.get_muted_foreground())
311    };
312    view! {
313        EuvCard {
314            title: LAB_RTL_TITLE.to_string()
315            tokens: tokens
316            subtitle: LAB_RTL_SUB
317            column {
318                style: column_quaternary_style
319                EuvSwitch {
320                    checked: rtl_sig
321                    label: LAB_SWITCH_RTL.to_string()
322                    tokens: tokens
323                }
324                column {
325                    style: column_fifth_style
326                    bind_children: build_dir_preview
327                }
328                EuvActionRow {
329                    EuvButton {
330                        label: LAB_BTN_PRESERVE.to_string()
331                        tokens: tokens
332                        small()
333                        on_click: on_increment
334                    }
335                }
336                text {
337                    style: text_fifth_style
338                    { counter_readout }
339                }
340            }
341        }
342    }
343}
344
345/// Mounts the Resizable Settings Panel composition recipe card.
346///
347/// # Arguments
348///
349/// - `&ShowcaseState` - Reactive showcase state.
350/// - `ThemeTokens` - Active design tokens.
351///
352/// # Returns
353///
354/// - `NodeId` - Mounted settings split panel recipe card node.
355pub(crate) fn mount_lab_settings_recipe_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
356    let palette: ThemePalette = tokens.get_palette();
357    let autosave: Signal<bool> = Signal::new(true);
358    let record_traces: Signal<bool> = Signal::new(false);
359    let split_ratio: Signal<f32> = state.get_lab_split_ratio();
360    let settings_summary = move || -> String {
361        format!(
362            "Split: {:.0}% | Auto-save: {} | Traces: {}",
363            split_ratio.get() * 100.0,
364            autosave.get(),
365            record_traces.get()
366        )
367    };
368    let column_tertiary_style: Style = style! {
369        Width(Length::Percent(100.0))
370        Gap(SPACE_SM)
371    };
372    let text_quaternary_style: Style = style! {
373        Width(Length::Percent(100.0))
374        FontSize(13.0)
375        FontWeight::SemiBold
376        TextColor(palette.get_foreground())
377    };
378    let left_pane: NodeId = view! {
379        column {
380            style: column_tertiary_style
381            text {
382                style: text_quaternary_style
383                { LAB_SPLIT_LEFT_HEAD }
384            }
385            EuvSwitch {
386                checked: autosave
387                label: LAB_SWITCH_AUTOSAVE.to_string()
388                tokens: tokens
389            }
390            EuvSwitch {
391                checked: record_traces
392                label: LAB_SWITCH_TELEMETRY.to_string()
393                tokens: tokens
394            }
395        }
396    };
397    let column_secondary_style: Style = style! {
398        Width(Length::Percent(100.0))
399        Gap(SPACE_SM)
400    };
401    let text_style: Style = style! {
402        Width(Length::Percent(100.0))
403        FontSize(13.0)
404        FontWeight::SemiBold
405        TextColor(palette.get_foreground())
406    };
407    let text_secondary_style: Style = style! {
408        Width(Length::Percent(100.0))
409        FontSize(12.5)
410        TextColor(palette.get_muted_foreground())
411    };
412    let text_tertiary_style: Style = style! {
413        Width(Length::Percent(100.0))
414        FontSize(12.0)
415        TextColor(palette.get_primary())
416    };
417    let right_pane: NodeId = view! {
418        column {
419            style: column_secondary_style
420            text {
421                style: text_style
422                { LAB_SPLIT_RIGHT_HEAD }
423            }
424            text {
425                style: text_secondary_style
426                { LAB_SPLIT_RIGHT_DESC }
427            }
428            text {
429                style: text_tertiary_style
430                { settings_summary }
431            }
432        }
433    };
434    view! {
435        EuvCard {
436            title: LAB_SETTINGS_TITLE.to_string()
437            tokens: tokens
438            subtitle: LAB_SETTINGS_SUB
439            EuvResizable {
440                left: left_pane
441                right: right_pane
442                split_ratio: split_ratio
443                tokens: tokens
444            }
445        }
446    }
447}
448
449/// Mounts the Assistant Thread & Quick Poll real-world composition recipe card.
450///
451/// # Arguments
452///
453/// - `ThemeTokens` - Active design tokens.
454///
455/// # Returns
456///
457/// - `NodeId` - Mounted thread and poll recipe card node.
458pub(crate) fn mount_lab_thread_recipe_card(tokens: ThemeTokens) -> NodeId {
459    let attach_vis: Signal<bool> = Signal::new(true);
460    let poll_sel: Signal<Option<usize>> = Signal::new(Some(0));
461    let poll_options: Vec<String> = vec![
462        LAB_POLL_OPT_1.to_string(),
463        LAB_POLL_OPT_2.to_string(),
464        LAB_POLL_OPT_3.to_string(),
465    ];
466    let column_style: Style = style! {
467        Width(Length::Percent(100.0))
468        Gap(SPACE_MD)
469    };
470    view! {
471        EuvCard {
472            title: LAB_THREAD_TITLE.to_string()
473            tokens: tokens
474            subtitle: LAB_THREAD_SUB
475            column {
476                style: column_style
477                EuvBubble {
478                    author: LAB_BUBBLE_BOT_AUTHOR.to_string()
479                    content: LAB_BUBBLE_BOT_BODY.to_string()
480                    tokens: tokens
481                    timestamp: LAB_TIME_A
482                }
483                EuvBubble {
484                    author: LAB_BUBBLE_DEV_AUTHOR.to_string()
485                    content: LAB_BUBBLE_DEV_BODY.to_string()
486                    tokens: tokens
487                    timestamp: LAB_TIME_B
488                    outgoing: true
489                }
490                EuvAttachment {
491                    filename: LAB_ATTACH_FILE.to_string()
492                    meta: LAB_ATTACH_META.to_string()
493                    visible: attach_vis
494                    tokens: tokens
495                }
496                EuvQuestionnaire {
497                    prompt: LAB_POLL_PROMPT.to_string()
498                    options: poll_options
499                    selected: poll_sel
500                    tokens: tokens
501                }
502            }
503        }
504    }
505}
506
507/// Mounts the clean Architecture & Cases page featuring the persistent Architecture navigation case study plus compact real-world composition recipes.
508///
509/// # Arguments
510///
511/// - `&ShowcaseState` - Reactive showcase state.
512/// - `ThemeTokens` - Active design tokens.
513///
514/// # Returns
515///
516/// - `NodeId` - Mounted architecture and cases page node.
517pub fn mount_lab_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
518    let arch_card: NodeId = mount_lab_architecture_card(state, tokens);
519    let recipe_cards: Vec<NodeId> = vec![
520        mount_lab_scroll_recipe_card(state, tokens),
521        mount_lab_rtl_recipe_card(state, tokens),
522        mount_lab_settings_recipe_card(state, tokens),
523        mount_lab_thread_recipe_card(tokens),
524    ];
525    let recipes_grid: NodeId = mount_responsive_grid(recipe_cards, 2);
526    view! {
527        EuvPage {
528            title: LAB_TITLE.to_string()
529            subtitle: LAB_SUBTITLE.to_string()
530            tokens: tokens
531            { arch_card }
532            { recipes_grid }
533        }
534    }
535}