euv-example 0.48.2

Cross-platform native showcase application demonstrating euv fine-grained reactivity, multi-mode rendering, window controls, and euv-ui components.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
use super::*;

/// Mounts the Architecture Case Study card with persistent `EuvNavigationMenu` tabs, uniform `SPACE_MD` spacing to the sibling telemetry chart, and a compact frame trace.
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
/// - `ThemeTokens` - Active design tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted architecture case study card node.
pub(crate) fn mount_lab_architecture_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
    let nav_items: Vec<(String, String)> = vec![
        (
            LAB_NAV_ARCH_LABEL.to_string(),
            LAB_NAV_ARCH_DESC.to_string(),
        ),
        (LAB_NAV_3D_LABEL.to_string(), LAB_NAV_3D_DESC.to_string()),
        (
            LAB_NAV_MEDIA_LABEL.to_string(),
            LAB_NAV_MEDIA_DESC.to_string(),
        ),
    ];
    let chart_data: Vec<EuvChartPoint> = vec![
        EuvChartPoint::new("Mon".to_string(), 60.0),
        EuvChartPoint::new("Tue".to_string(), 88.0),
        EuvChartPoint::new("Wed".to_string(), 118.0),
        EuvChartPoint::new("Thu".to_string(), 104.0),
        EuvChartPoint::new("Fri".to_string(), 120.0),
        EuvChartPoint::new("Sat".to_string(), 116.0),
    ];
    let trace_spans: Vec<EuvTraceSpan> = vec![
        EuvTraceSpan::new(
            LAB_TRACE_LAYOUT.to_string(),
            0.14,
            0.0,
            0.12,
            EuvTone::Primary,
        ),
        EuvTraceSpan::new(
            LAB_TRACE_BVH.to_string(),
            0.88,
            0.12,
            0.60,
            EuvTone::Success,
        ),
        EuvTraceSpan::new(
            LAB_TRACE_TONEMAP.to_string(),
            0.24,
            0.72,
            0.16,
            EuvTone::Warning,
        ),
        EuvTraceSpan::new(
            LAB_TRACE_BLIT.to_string(),
            0.16,
            0.88,
            0.12,
            EuvTone::Neutral,
        ),
    ];
    view! {
        EuvCard {
            title: LAB_ARCH_TITLE.to_string()
            tokens: tokens
            subtitle: LAB_ARCH_SUB
            row {
                style: c_action_row()
                EuvMarker {
                    code: "01".to_string()
                    label: LAB_MARKER_ZERO.to_string()
                    tone: EuvTone::Primary
                    tokens: tokens
                }
                EuvMarker {
                    code: "02".to_string()
                    label: LAB_MARKER_FPS.to_string()
                    tone: EuvTone::Success
                    tokens: tokens
                }
                EuvMarker {
                    code: "03".to_string()
                    label: LAB_MARKER_FREEZE.to_string()
                    tone: EuvTone::Warning
                    tokens: tokens
                }
            }
            EuvNavigationMenu {
                items: nav_items
                active: state.get_lab_nav_menu_active()
                tokens: tokens
            }
            EuvChart {
                title: LAB_CHART_TITLE.to_string()
                kind: EuvChartKind::Bar
                data: chart_data
                tokens: tokens
            }
            EuvTrace {
                title: LAB_TRACE_TITLE.to_string()
                spans: trace_spans
                tokens: tokens
            }
        }
    }
}

/// Mounts the Scroll Chaining & Click Bubbling interactive recipe card.
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
/// - `ThemeTokens` - Active design tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted scroll and bubbling recipe card node.
pub(crate) fn mount_lab_scroll_recipe_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
    let p: ThemePalette = tokens.get_palette();
    let touches_sig: Signal<Vec<(u64, Point)>> = current_context().get_active_touches();
    let block_scroll: Signal<bool> = state.get_lab_block_scroll_chain();
    let stop_bubble: Signal<bool> = state.get_lab_stop_click_bubble();
    let parent_clicks: Signal<u32> = state.get_lab_parent_clicks();
    let child_clicks: Signal<u32> = state.get_lab_child_clicks();
    let clicks_readout = move || -> String {
        format!(
            "Inner Clicks: {} | Outer Parent Clicks: {} | Active Touches: {}",
            child_clicks.get(),
            parent_clicks.get(),
            touches_sig.get().len()
        )
    };
    let build_nested_box = move || -> Vec<NodeId> {
        let live_tok: ThemeTokens = live_tokens_untracked(tokens);
        let live_p: ThemePalette = live_tok.get_palette();
        let live_g: ThemeGeometry = live_tok.get_geometry();
        let locked: bool = block_scroll.get();
        let stop_clk: bool = stop_bubble.get();
        let on_outer_click = move |_: &UiEvent| {
            let _: bool = parent_clicks.update(|v: &mut u32| *v += 1);
        };
        let on_inner_click = move |_: &UiEvent| {
            let _: bool = child_clicks.update(|v: &mut u32| *v += 1);
        };
        let rows: Vec<NodeId> = (1..=8_usize)
            .map(|row_i: usize| {
                let row_txt: String = format!(
                    "Nested Scroll Row #{row_i} (scroll_lock={locked}, stop_bubble={stop_clk})"
                );
                view! {
                    text {
                        style: {
                            width: Length::Percent(100.0)
                            font_size: 12.0
                            color: live_p.get_foreground()
                        }
                        { row_txt }
                    }
                }
            })
            .collect();
        vec![view! {
            column {
                style: {
                    width: Length::Percent(100.0)
                    padding: Edges::all(SPACE_MD)
                    gap: SPACE_SM
                    background: live_p.get_muted()
                    border: (live_g.get_border_width(), live_p.get_border())
                    radius: live_g.get_radius_md()
                }
                on_click: on_outer_click
                scroll {
                    style: {
                        width: Length::Percent(100.0)
                        height: Length::Px(104.0)
                        padding: Edges::all(SPACE_SM)
                        gap: SPACE_XS
                        background: live_p.get_card()
                        border: (live_g.get_border_width(), live_p.get_border())
                        radius: live_g.get_radius_sm()
                        stop_scroll_propagation: locked
                        stop_event_propagation: stop_clk
                    }
                    ..rows
                }
                EuvActionRow {
                    EuvButton {
                        label: LAB_BTN_INNER_TARGET.to_string()
                        tokens: live_tok
                        outline()
                        sm()
                        on_click: on_inner_click
                    }
                }
            }
        }]
    };
    view! {
        EuvCard {
            title: LAB_SCROLL_TITLE.to_string()
            tokens: tokens
            subtitle: LAB_SCROLL_SUB
            column {
                style: {
                    width: Length::Percent(100.0)
                    gap: SPACE_SM
                }
                EuvSwitch {
                    checked: block_scroll
                    label: LAB_SWITCH_SCROLL_LOCK.to_string()
                    tokens: tokens
                }
                EuvSwitch {
                    checked: stop_bubble
                    label: LAB_SWITCH_STOP_BUBBLE.to_string()
                    tokens: tokens
                }
                text {
                    style: {
                        width: Length::Percent(100.0)
                        font_size: 12.0
                        color: p.get_muted_foreground()
                    }
                    { clicks_readout }
                }
                column {
                    style: {
                        width: Length::Percent(100.0)
                    }
                    bind_children: build_nested_box
                }
            }
        }
    }
}

/// Mounts the RTL Direction & Resize-Safe State recipe card preserving `Increment Preserved Counter`.
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
/// - `ThemeTokens` - Active design tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted RTL and state-preservation recipe card node.
pub(crate) fn mount_lab_rtl_recipe_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
    let p: ThemePalette = tokens.get_palette();
    let rtl_sig: Signal<bool> = state.get_lab_rtl_mode();
    let preserve_cnt: Signal<u32> = state.get_lab_resize_preserve_count();
    let on_increment = move |_: &UiEvent| {
        let _: bool = preserve_cnt.update(|v: &mut u32| *v += 1);
    };
    let counter_readout = move || -> String {
        format!(
            "Resize-Preserved Counter: {} | Direction: {}",
            preserve_cnt.get(),
            if rtl_sig.get() { "RTL" } else { "LTR" }
        )
    };
    let build_dir_preview = move || -> Vec<NodeId> {
        let live_tok: ThemeTokens = live_tokens_untracked(tokens);
        let live_p: ThemePalette = live_tok.get_palette();
        let dir: EuvTextDirection = if rtl_sig.get() {
            EuvTextDirection::Rtl
        } else {
            EuvTextDirection::Ltr
        };
        let dir_label: String =
            format!("Direction preview ({dir:?}): Unified layout alignment across LTR & RTL");
        let child_node: NodeId = view! {
            text {
                style: {
                    width: Length::Percent(100.0)
                    font_size: 13.0
                    color: live_p.get_foreground()
                }
                { dir_label }
            }
        };
        vec![view! {
            EuvDirection {
                direction: dir
                child: child_node
                tokens: live_tok
            }
        }]
    };
    view! {
        EuvCard {
            title: LAB_RTL_TITLE.to_string()
            tokens: tokens
            subtitle: LAB_RTL_SUB
            column {
                style: {
                    width: Length::Percent(100.0)
                    gap: SPACE_MD
                }
                EuvSwitch {
                    checked: rtl_sig
                    label: LAB_SWITCH_RTL.to_string()
                    tokens: tokens
                }
                column {
                    style: {
                        width: Length::Percent(100.0)
                    }
                    bind_children: build_dir_preview
                }
                EuvActionRow {
                    EuvButton {
                        label: LAB_BTN_PRESERVE.to_string()
                        tokens: tokens
                        sm()
                        on_click: on_increment
                    }
                }
                text {
                    style: {
                        width: Length::Percent(100.0)
                        font_size: 12.0
                        color: p.get_muted_foreground()
                    }
                    { counter_readout }
                }
            }
        }
    }
}

/// Mounts the Resizable Settings Panel composition recipe card.
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
/// - `ThemeTokens` - Active design tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted settings split panel recipe card node.
pub(crate) fn mount_lab_settings_recipe_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
    let p: ThemePalette = tokens.get_palette();
    let autosave: Signal<bool> = Signal::new(true);
    let record_traces: Signal<bool> = Signal::new(false);
    let split_ratio: Signal<f32> = state.get_lab_split_ratio();
    let settings_summary = move || -> String {
        format!(
            "Split: {:.0}% | Auto-save: {} | Traces: {}",
            split_ratio.get() * 100.0,
            autosave.get(),
            record_traces.get()
        )
    };
    let left_pane: NodeId = view! {
        column {
            style: {
                width: Length::Percent(100.0)
                gap: SPACE_SM
            }
            text {
                style: {
                    width: Length::Percent(100.0)
                    font_size: 13.0
                    font_weight: FontWeight::SemiBold
                    color: p.get_foreground()
                }
                { LAB_SPLIT_LEFT_HEAD }
            }
            EuvSwitch {
                checked: autosave
                label: LAB_SWITCH_AUTOSAVE.to_string()
                tokens: tokens
            }
            EuvSwitch {
                checked: record_traces
                label: LAB_SWITCH_TELEMETRY.to_string()
                tokens: tokens
            }
        }
    };
    let right_pane: NodeId = view! {
        column {
            style: {
                width: Length::Percent(100.0)
                gap: SPACE_SM
            }
            text {
                style: {
                    width: Length::Percent(100.0)
                    font_size: 13.0
                    font_weight: FontWeight::SemiBold
                    color: p.get_foreground()
                }
                { LAB_SPLIT_RIGHT_HEAD }
            }
            text {
                style: {
                    width: Length::Percent(100.0)
                    font_size: 12.5
                    color: p.get_muted_foreground()
                }
                { LAB_SPLIT_RIGHT_DESC }
            }
            text {
                style: {
                    width: Length::Percent(100.0)
                    font_size: 12.0
                    color: p.get_primary()
                }
                { settings_summary }
            }
        }
    };
    view! {
        EuvCard {
            title: LAB_SETTINGS_TITLE.to_string()
            tokens: tokens
            subtitle: LAB_SETTINGS_SUB
            EuvResizable {
                left: left_pane
                right: right_pane
                split_ratio: split_ratio
                tokens: tokens
            }
        }
    }
}

/// Mounts the Assistant Thread & Quick Poll real-world composition recipe card.
///
/// # Arguments
///
/// - `ThemeTokens` - Active design tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted thread and poll recipe card node.
pub(crate) fn mount_lab_thread_recipe_card(tokens: ThemeTokens) -> NodeId {
    let attach_vis: Signal<bool> = Signal::new(true);
    let poll_sel: Signal<Option<usize>> = Signal::new(Some(0));
    let poll_options: Vec<String> = vec![
        LAB_POLL_OPT_1.to_string(),
        LAB_POLL_OPT_2.to_string(),
        LAB_POLL_OPT_3.to_string(),
    ];
    view! {
        EuvCard {
            title: LAB_THREAD_TITLE.to_string()
            tokens: tokens
            subtitle: LAB_THREAD_SUB
            column {
                style: {
                    width: Length::Percent(100.0)
                    gap: SPACE_MD
                }
                EuvBubble {
                    author: LAB_BUBBLE_BOT_AUTHOR.to_string()
                    content: LAB_BUBBLE_BOT_BODY.to_string()
                    tokens: tokens
                    timestamp: LAB_TIME_A
                }
                EuvBubble {
                    author: LAB_BUBBLE_DEV_AUTHOR.to_string()
                    content: LAB_BUBBLE_DEV_BODY.to_string()
                    tokens: tokens
                    timestamp: LAB_TIME_B
                    outgoing: true
                }
                EuvAttachment {
                    filename: LAB_ATTACH_FILE.to_string()
                    meta: LAB_ATTACH_META.to_string()
                    visible: attach_vis
                    tokens: tokens
                }
                EuvQuestionnaire {
                    prompt: LAB_POLL_PROMPT.to_string()
                    options: poll_options
                    selected: poll_sel
                    tokens: tokens
                }
            }
        }
    }
}

/// Mounts the clean Architecture & Cases page featuring the persistent Architecture navigation case study plus compact real-world composition recipes.
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
/// - `ThemeTokens` - Active design tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted architecture and cases page node.
pub fn mount_lab_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
    let arch_card: NodeId = mount_lab_architecture_card(state, tokens);
    let recipe_cards: Vec<NodeId> = vec![
        mount_lab_scroll_recipe_card(state, tokens),
        mount_lab_rtl_recipe_card(state, tokens),
        mount_lab_settings_recipe_card(state, tokens),
        mount_lab_thread_recipe_card(tokens),
    ];
    let recipes_grid: NodeId = mount_responsive_grid(recipe_cards, 2);
    view! {
        EuvPage {
            title: LAB_TITLE.to_string()
            subtitle: LAB_SUBTITLE.to_string()
            tokens: tokens
            { arch_card }
            { recipes_grid }
        }
    }
}