euv-example 0.48.0

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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
use super::*;

/// Registers every `SHOWCASE_ROUTES` entry lazily onto `router` using typed `#[component(retention = Freeze)]` pages.
///
/// # Arguments
///
/// - `&ShowcaseState` - Shared reactive showcase state.
pub(crate) fn ensure_showcase_routes_registered(state: &ShowcaseState) {
    if state.get_router_ready().replace(true) {
        return;
    }
    let mut router: EuvRouter = state.get_router().clone();
    for spec in SHOWCASE_ROUTES.iter() {
        let path: &'static str = spec.get_path();
        let st: ShowcaseState = state.clone();
        router = router.route_component(path, spec.get_label(), move |_: &EuvRouteMatch| {
            let tok: ThemeTokens = untracked(|| st.get_theme().get_tokens().get());
            ShowcasePage::new(path, st.clone(), tok)
        });
    }
    let _: EuvRouter = router;
}

/// Lazily mounts the global Command Palette `EuvCommand` + `EuvModal` subtree on first open so Frame 1 mounts zero hidden portals.
///
/// # Arguments
///
/// - `&ShowcaseState` - Shared reactive showcase state.
/// - `ThemeTokens` - Active design tokens at first open.
///
/// # Returns
///
/// - `NodeId` - Mounted `EuvModal` handle with selection and in-place theme-remap scopes attached.
pub(crate) fn mount_lazy_cmd_palette_modal(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
    let cmd_open: Signal<bool> = state.get_cmd_palette_open();
    let cmd_query: Signal<String> = state.get_cmd_palette_query();
    let mut cmd_items: Vec<String> = SHOWCASE_ROUTES
        .iter()
        .map(|spec: &ShowcaseRouteSpec| {
            format!("Go to {} ({})", spec.get_label(), spec.get_section())
        })
        .collect();
    cmd_items.push(CMD_ITEM_TOGGLE_MODE.to_string());
    let cmd_sel: Signal<Option<usize>> = Signal::new(None);
    let cmd_route: Signal<String> = state.get_route();
    let cmd_state: ShowcaseState = state.clone();
    let cmd_list: NodeId = view! {
        EuvCommand {
            items: cmd_items
            selected: cmd_sel
            tokens: tokens
            query: cmd_query
            placeholder: CMD_PLACEHOLDER
        }
    };
    let (cmd_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
        Effect::new(move || {
            if let Some(idx) = cmd_sel.get() {
                match SHOWCASE_ROUTES.get(idx) {
                    Some(spec) => {
                        let _: bool = cmd_route.set_if_changed(spec.get_path().to_string());
                    }
                    None => {
                        cmd_state.toggle_theme_mode();
                    }
                }
                let _: bool = cmd_sel.set_if_changed(None);
                let _: bool = cmd_open.set_if_changed(false);
            }
        })
    });
    let cmd_modal: NodeId = view! {
        EuvModal {
            open: cmd_open
            title: CMD_MODAL_TITLE.to_string()
            body: cmd_list
            tokens: tokens
        }
    };
    let rctx: Context = current_context();
    let cmd_theme_sig: Memo<ThemeTokens> = state.get_theme().get_tokens();
    let prev_cmd_tok: Rc<Cell<ThemeTokens>> = Rc::new(Cell::new(tokens));
    let cmd_theme_ctx: Context = rctx.clone();
    let (cmd_theme_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
        Effect::new(move || {
            let next_tok: ThemeTokens = cmd_theme_sig.get();
            let old_tok: ThemeTokens = prev_cmd_tok.replace(next_tok);
            if old_tok == next_tok {
                return;
            }
            cmd_theme_ctx.get_scene().with_write(
                |tree: &mut SceneTree| {
                    remap_subtree_theme_in_place(tree, cmd_modal, old_tok, next_tok);
                },
                (),
            );
        })
    });
    rctx.get_scene().with_write(
        |tree: &mut SceneTree| {
            tree.attach_scope(cmd_modal, cmd_scope);
            tree.attach_scope(cmd_modal, cmd_theme_scope);
        },
        (),
    );
    cmd_modal
}

/// Mounts the fully reactive showcase application shell with lazy `PageRetention::Freeze` routing and cross-component events.
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
///
/// # Returns
///
/// - `NodeId` - Mounted reactive root container handle.
pub fn mount_showcase_root(state: &ShowcaseState) -> NodeId {
    provide_theme(state.get_theme().clone());
    ensure_showcase_routes_registered(state);
    let global_banner: Signal<ShowcaseGlobalBanner> =
        state!(global ShowcaseGlobalBanner = ShowcaseGlobalBanner::default());
    let state_c: ShowcaseState = state.clone();
    let bg_state: ShowcaseState = state.clone();
    let fg_state: ShowcaseState = state.clone();
    let sys_state: ShowcaseState = state.clone();
    let sys_log_sig: Signal<Vec<String>> = state.get_system_event_log();
    let sys_count_sig: Signal<u32> = state.get_system_event_count();
    let (ev_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
        let _: SystemEventSubscription = on_background(move || {
            bg_state.freeze_for_background();
        });
        let _: SystemEventSubscription = on_foreground(move || {
            fg_state.restore_from_foreground();
        });
        let _: SystemEventSubscription = on_system_event(move |ev: &SystemEvent| {
            if matches!(ev, SystemEvent::Terminate) {
                sys_state.freeze_for_background();
                let _: usize = EuvOverlayStack::dismiss_all();
                reset_fullscreen_state();
            } else if matches!(ev, SystemEvent::Foreground) {
                sys_state.restore_from_foreground();
            }
            let next_seq: u32 = sys_count_sig.get_untracked().saturating_add(1);
            let _: bool = sys_count_sig.set(next_seq);
            let entry: String = format!("#{next_seq}: {ev:?}");
            let _: bool = sys_log_sig.update(|items: &mut Vec<String>| {
                items.insert(0, entry);
                if items.len() > SYS_EVENTS_LOG_LIMIT {
                    items.truncate(SYS_EVENTS_LOG_LIMIT);
                }
            });
        });
        on!(ShowcasePulseEvent => move |ev: &ShowcasePulseEvent| {
            let src: String = ev.get_source().clone();
            let _: bool = global_banner.update(|b: &mut ShowcaseGlobalBanner| {
                let next_pulses: u32 = b.get_pulses().saturating_add(1);
                b.set_pulses(next_pulses);
                b.set_last_source(src);
            });
        })
    });
    let build_root_children = move || -> Vec<NodeId> {
        let tokens: ThemeTokens = untracked(|| state_c.get_theme().get_tokens().get());
        let hub: DynamicUpdateHub = state_c.get_dynamic_hub().clone();
        let _: u64 = hub.routes_signal().get();
        let cmd_open: Signal<bool> = state_c.get_cmd_palette_open();
        let cmd_slot: NodeId = view! {
            column {
                style: {
                    position: Position::Absolute
                    width: Length::Px(0.0)
                    height: Length::Px(0.0)
                }
            }
        };
        let cmd_mounted: Rc<Cell<bool>> = Rc::new(Cell::new(false));
        let cmd_state_lazy: ShowcaseState = state_c.clone();
        let rctx: Context = current_context();
        let cmd_ctx: Context = rctx.clone();
        let (cmd_lazy_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
            Effect::new(move || {
                if !cmd_open.get() || cmd_mounted.get() {
                    return;
                }
                cmd_mounted.set(true);
                let live_tok: ThemeTokens =
                    untracked(|| cmd_state_lazy.get_theme().get_tokens().get());
                let modal_node: NodeId = with_context(cmd_ctx.clone(), || {
                    mount_lazy_cmd_palette_modal(&cmd_state_lazy, live_tok)
                });
                cmd_ctx.get_scene().with_write(
                    |tree: &mut SceneTree| {
                        let dirty_mask: u16 = DIRTY_CHILDREN + DIRTY_LAYOUT + DIRTY_PAINT;
                        tree.append_child(cmd_slot, modal_node);
                        tree.mark_dirty(cmd_slot, dirty_mask);
                    },
                    (),
                );
            })
        });
        rctx.get_scene().with_write(
            |tree: &mut SceneTree| {
                tree.attach_scope(cmd_slot, cmd_lazy_scope);
            },
            (),
        );
        let state_shell: ShowcaseState = state_c.clone();
        let hub_shell: DynamicUpdateHub = hub.clone();
        let render_native_shell = move || -> NodeId {
            let shell_node: NodeId = mount_native_app_shell(&state_shell, &hub_shell, tokens);
            shell_node
        };
        let global_wasm_slot: NodeId = view! {
            slot {
                id: WASM_GLOBAL_ROOT_SLOT
                hub: hub
                style: c_full_col()
                fallback: render_native_shell
            }
        };
        vec![global_wasm_slot, cmd_slot]
    };
    let root_node: NodeId = view! {
        column {
            style: {
                width: Length::Percent(100.0)
                height: Length::Percent(100.0)
            }
            bind_children: build_root_children
        }
    };
    let root_ctx: Context = current_context();
    root_ctx.get_scene().with_write(
        |tree: &mut SceneTree| {
            tree.attach_scope(root_node, ev_scope);
        },
        (),
    );
    root_node
}

/// Mounts the native dual-mode `EuvAppShell` (Desktop `>= 960px`: full-width topbar + permanent left sidebar + zero bottom nav; Mobile `< 960px`: compact topbar + overlay drawer + floating bottom navigation bar).
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
/// - `&DynamicUpdateHub` - Active OTA dynamic route hub.
/// - `ThemeTokens` - Active design tokens at mount time.
///
/// # Returns
///
/// - `NodeId` - Mounted `EuvAppShell` root handle.
pub(crate) fn mount_native_app_shell(
    state_shell: &ShowcaseState,
    hub_shell: &DynamicUpdateHub,
    tokens: ThemeTokens,
) -> NodeId {
    let mut nav_items: Vec<EuvNavItem> = ShowcaseState::nav_items();
    for dyn_route in hub_shell.registered_routes().into_iter() {
        if dyn_route == ROUTE_DYNAMIC_PANEL {
            continue;
        }
        if !nav_items
            .iter()
            .any(|item: &EuvNavItem| item.get_path().as_str() == dyn_route.as_str())
        {
            let label: String = hub_shell
                .page_title(&dyn_route)
                .filter(|t: &String| !t.is_empty())
                .unwrap_or_else(|| dyn_route.clone());
            nav_items.push(EuvNavItem::new(dyn_route, label).section(NAV_SEC_RUNTIME));
        }
    }
    let nav: NodeId = view! {
        EuvSidebarNav {
            items: nav_items
            active_route: state_shell.get_route()
            tokens: tokens
        }
    };
    let bottom_items: Vec<EuvNavItem> = vec![
        EuvNavItem::new(ROUTE_OVERVIEW.to_string(), BNAV_HOME_LABEL.to_string())
            .section(BNAV_HOME_ICON),
        EuvNavItem::new(ROUTE_MARKDOWN.to_string(), BNAV_DOCS_LABEL.to_string())
            .section(BNAV_DOCS_ICON),
        EuvNavItem::new(ROUTE_LAB.to_string(), BNAV_CASES_LABEL.to_string())
            .section(BNAV_CASES_ICON),
        EuvNavItem::new(ROUTE_STRESS.to_string(), BNAV_STRESS_LABEL.to_string())
            .section(BNAV_STRESS_ICON),
        EuvNavItem::new(ROUTE_GAME_3D.to_string(), BNAV_3D_LABEL.to_string()).section(BNAV_3D_ICON),
    ];
    let bottom_nav: NodeId = view! {
        EuvBottomNav {
            items: bottom_items
            active_route: state_shell.get_route()
            tokens: tokens
        }
    };
    let swipe_order: Vec<String> = showcase_swipe_order();
    let state_for_outlet: ShowcaseState = state_shell.clone();
    let router: EuvRouter = state_shell
        .get_router()
        .clone()
        .with_dynamic_hub(hub_shell.clone());
    let route_sig: Signal<String> = state_shell.get_route();
    let cur_target: String = route_sig.get_untracked();
    if router.get_current_path().get_untracked() != cur_target {
        router.replace(&cur_target);
    }
    let breadcrumb_sig: Signal<String> =
        Signal::new(ShowcaseState::breadcrumb_for_route(&cur_target));
    let page_pad_sig: Signal<Edges> = Signal::new(Edges::all(SPACE_LG));
    let router_sync_in: EuvRouter = router.clone();
    let router_path_sig: Signal<String> = router.get_current_path();
    let reduced_motion_sig: Signal<bool> = state_shell.get_reduced_motion();
    let sctx: Context = current_context();
    let (sync_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
        let _: Effect = Effect::new(move || {
            let target: String = route_sig.get();
            if router_sync_in.get_current_path().get_untracked() != target {
                router_sync_in.push(&target);
            }
            let _: bool =
                breadcrumb_sig.set_if_changed(ShowcaseState::breadcrumb_for_route(&target));
        });
        let _: Effect = Effect::new(move || {
            set_reduced_motion(reduced_motion_sig.get());
        });
        Effect::new(move || {
            let rp: String = router_path_sig.get();
            if route_sig.get_untracked() != rp {
                let _: bool = route_sig.set_if_changed(rp);
            }
        })
    });
    let page_node: NodeId = router
        .outlet(move |matched: &EuvRouteMatch| {
            let tok: ThemeTokens = untracked(|| state_for_outlet.get_theme().get_tokens().get());
            mount_route_by_name(matched.get_path(), &state_for_outlet, tok)
        })
        .with_theme(state_shell.get_theme().clone())
        .with_page_padding(page_pad_sig)
        .with_route_order(swipe_order.clone())
        .with_double_back_exit(true)
        .mount();
    sctx.get_scene().with_write(
        |tree: &mut SceneTree| {
            tree.attach_scope(page_node, sync_scope);
        },
        (),
    );
    let top_actions: NodeId = mount_topbar_actions(state_shell, tokens);
    let mobile_actions: NodeId = mount_topbar_actions(state_shell, tokens);
    view! {
        EuvAppShell {
            brand: SHOWCASE_BRAND.to_string()
            sidebar: nav
            main_content: page_node
            tokens: tokens
            theme: state_shell.get_theme().clone()
            page_padding: page_pad_sig
            route: state_shell.get_route()
            breadcrumb: breadcrumb_sig
            top_bar_actions: top_actions
            mobile_header_actions: mobile_actions
            bottom_nav: bottom_nav
            swipe_routes: swipe_order
            swipe_routes_enabled: state_shell.get_swipe_routing()
            show_fps: true
            show_fps_signal: state_shell.get_show_fps_hud()
            auto_hide_chrome_on_scroll: true
            auto_hide_chrome_signal: state_shell.get_auto_hide_chrome()
        }
    }
}

/// Mounts the showcase page corresponding to the active route in `state`.
///
/// # Arguments
///
/// - `&ShowcaseState` - Reactive showcase state.
/// - `ThemeTokens` - Active resolved design tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted page container handle.
pub fn mount_active_route(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
    let route: String = state.get_route().get_untracked();
    mount_route_by_name(&route, state, tokens)
}

/// Dispatches a route string to its corresponding declarative showcase page builder.
///
/// # Arguments
///
/// - `&str` - Active route path.
/// - `&ShowcaseState` - Reactive showcase state.
/// - `ThemeTokens` - Active resolved design tokens.
///
/// # Returns
///
/// - `NodeId` - Mounted page container handle.
pub(crate) fn mount_route_by_name(
    route: &str,
    state: &ShowcaseState,
    tokens: ThemeTokens,
) -> NodeId {
    let builder: fn(&ShowcaseState, ThemeTokens) -> NodeId = SHOWCASE_ROUTES
        .iter()
        .find(|spec: &&ShowcaseRouteSpec| spec.get_path() == route)
        .map(|spec: &ShowcaseRouteSpec| spec.get_mount())
        .unwrap_or(mount_overview_page);
    builder(state, tokens)
}

/// Builds the horizontal swipe route order: the five bottom-nav destinations first, then every remaining registry route in sidebar order.
///
/// # Returns
///
/// - `Vec<String>` - Ordered swipe route paths.
pub(crate) fn showcase_swipe_order() -> Vec<String> {
    let mut order: Vec<String> = BOTTOM_NAV_ROUTES
        .iter()
        .map(|path: &&str| (*path).to_string())
        .collect();
    for spec in SHOWCASE_ROUTES.iter() {
        if !BOTTOM_NAV_ROUTES.contains(&spec.get_path()) {
            order.push(spec.get_path().to_string());
        }
    }
    order
}

/// Computes normalized 24x24 viewbox origin, unit scale, and Lucide-grade stroke width centered inside `bounds`.
///
/// # Arguments
///
/// - `Rect` - Target logical bounding box.
///
/// # Returns
///
/// - `(f32, f32, f32, f32)` - Tuple `(ox, oy, u, stroke_width)`.
pub(crate) fn topbar_icon_basis(bounds: Rect) -> (f32, f32, f32, f32) {
    let w: f32 = bounds.get_width().max(8.0);
    let h: f32 = bounds.get_height().max(8.0);
    let side: f32 = w.min(h);
    let ox: f32 = bounds.get_x() + (w - side) * 0.5;
    let oy: f32 = bounds.get_y() + (h - side) * 0.5;
    let u: f32 = side / 24.0;
    let sw: f32 = (1.75 * u).clamp(1.2, 2.0);
    (ox, oy, u, sw)
}

/// Emits an anti-aliased line segment with precision rounded endcaps into `dl`.
///
/// # Arguments
///
/// - `&mut DisplayList` - Destination vector draw command list.
/// - `Point` - Segment start point.
/// - `Point` - Segment end point.
/// - `Color` - Stroke color.
/// - `f32` - Stroke width in logical pixels.
pub(crate) fn push_rounded_stroke(
    dl: &mut DisplayList,
    from: Point,
    to: Point,
    color: Color,
    width: f32,
) {
    let cap_r: f32 = (width * 0.48).max(0.45);
    dl.push(DrawCommand::Line {
        from,
        to,
        color,
        width,
    });
    dl.push(DrawCommand::Circle {
        center: from,
        radius: cap_r,
        color,
    });
    dl.push(DrawCommand::Circle {
        center: to,
        radius: cap_r,
        color,
    });
}

/// Renders a Lucide-grade 24x24 search magnifying glass icon into `dl`.
///
/// # Arguments
///
/// - `Rect` - Target logical bounding box.
/// - `&mut DisplayList` - Destination vector draw command list.
/// - `Color` - Foreground stroke color.
pub(crate) fn draw_topbar_search_icon(bounds: Rect, dl: &mut DisplayList, color: Color) {
    let (ox, oy, u, sw): (f32, f32, f32, f32) = topbar_icon_basis(bounds);
    let lens_d: f32 = 13.6 * u;
    dl.push(DrawCommand::FillRoundedRect {
        rect: Rect::new(ox + 4.2 * u, oy + 4.2 * u, lens_d, lens_d),
        color: COLOR_TRANSPARENT,
        radius: CornerRadius::all(RADIUS_PILL),
        border: Border::new(sw, color),
    });
    push_rounded_stroke(
        dl,
        Point::new(ox + 16.0 * u, oy + 16.0 * u),
        Point::new(ox + 20.2 * u, oy + 20.2 * u),
        color,
        sw,
    );
}

/// Renders a Lucide / SF-Symbols grade 24x24 Sun icon (hollow center circle + 8 evenly-spaced rounded rays) into `dl`.
///
/// # Arguments
///
/// - `Rect` - Target logical bounding box.
/// - `&mut DisplayList` - Destination vector draw command list.
/// - `Color` - Foreground stroke color.
pub(crate) fn draw_theme_sun_icon(bounds: Rect, dl: &mut DisplayList, color: Color) {
    let (ox, oy, u, sw): (f32, f32, f32, f32) = topbar_icon_basis(bounds);
    let cx: f32 = ox + 12.0 * u;
    let cy: f32 = oy + 12.0 * u;
    let core_r: f32 = 4.2 * u;
    dl.push(DrawCommand::FillRoundedRect {
        rect: Rect::new(cx - core_r, cy - core_r, core_r * 2.0, core_r * 2.0),
        color: COLOR_TRANSPARENT,
        radius: CornerRadius::all(RADIUS_PILL),
        border: Border::new(sw, color),
    });
    let r_in: f32 = 7.0 * u;
    let r_out: f32 = 9.4 * u;
    for idx in 0..8_u8 {
        let ang: f32 = (idx as f32) * (PI * 0.25);
        let (cos_a, sin_a): (f32, f32) = (ang.cos(), ang.sin());
        push_rounded_stroke(
            dl,
            Point::new(cx + r_in * cos_a, cy + r_in * sin_a),
            Point::new(cx + r_out * cos_a, cy + r_out * sin_a),
            color,
            sw,
        );
    }
}

/// Renders a Lucide `MoonStar`-grade 24x24 crescent moon (exact circle-circle analytical arcs + 4-point star sparkle) into `dl`.
///
/// # Arguments
///
/// - `Rect` - Target logical bounding box.
/// - `&mut DisplayList` - Destination vector draw command list.
/// - `Color` - Foreground stroke color.
pub(crate) fn draw_theme_moon_icon(bounds: Rect, dl: &mut DisplayList, color: Color) {
    let (ox, oy, u, sw): (f32, f32, f32, f32) = topbar_icon_basis(bounds);
    let c1x: f32 = 11.8;
    let c1y: f32 = 12.4;
    let r1: f32 = 8.2;
    let c2x: f32 = 16.4;
    let c2y: f32 = 8.2;
    let r2: f32 = 6.6;
    let dx: f32 = c2x - c1x;
    let dy: f32 = c2y - c1y;
    let dist: f32 = (dx * dx + dy * dy).sqrt();
    let base_ang: f32 = dy.atan2(dx);
    let a: f32 = (r1 * r1 - r2 * r2 + dist * dist) / (2.0 * dist);
    let alpha1: f32 = (a / r1).clamp(-1.0, 1.0).acos();
    let theta1_top: f32 = base_ang - alpha1;
    let theta1_bot: f32 = base_ang + alpha1;
    let theta1_end: f32 = theta1_top + 2.0 * PI;
    let outer_steps: usize = 28;
    let mut prev_outer: Point = Point::new(
        ox + (c1x + r1 * theta1_bot.cos()) * u,
        oy + (c1y + r1 * theta1_bot.sin()) * u,
    );
    for step in 1..=outer_steps {
        let t: f32 = (step as f32) / (outer_steps as f32);
        let ang: f32 = theta1_bot + (theta1_end - theta1_bot) * t;
        let next_pt: Point = Point::new(
            ox + (c1x + r1 * ang.cos()) * u,
            oy + (c1y + r1 * ang.sin()) * u,
        );
        dl.push(DrawCommand::Line {
            from: prev_outer,
            to: next_pt,
            color,
            width: sw,
        });
        prev_outer = next_pt;
    }
    let p_top_x: f32 = c1x + r1 * theta1_top.cos();
    let p_top_y: f32 = c1y + r1 * theta1_top.sin();
    let p_bot_x: f32 = c1x + r1 * theta1_bot.cos();
    let p_bot_y: f32 = c1y + r1 * theta1_bot.sin();
    let mut theta2_top: f32 = (p_top_y - c2y).atan2(p_top_x - c2x);
    let theta2_bot: f32 = (p_bot_y - c2y).atan2(p_bot_x - c2x);
    if theta2_top < theta2_bot {
        theta2_top += 2.0 * PI;
    }
    let inner_steps: usize = 18;
    let mut prev_inner: Point = Point::new(ox + p_top_x * u, oy + p_top_y * u);
    for step in 1..=inner_steps {
        let t: f32 = (step as f32) / (inner_steps as f32);
        let ang: f32 = theta2_top + (theta2_bot - theta2_top) * t;
        let next_pt: Point = Point::new(
            ox + (c2x + r2 * ang.cos()) * u,
            oy + (c2y + r2 * ang.sin()) * u,
        );
        dl.push(DrawCommand::Line {
            from: prev_inner,
            to: next_pt,
            color,
            width: sw,
        });
        prev_inner = next_pt;
    }
    let tip_r: f32 = (sw * 0.48).max(0.45);
    dl.push(DrawCommand::Circle {
        center: Point::new(ox + p_top_x * u, oy + p_top_y * u),
        radius: tip_r,
        color,
    });
    dl.push(DrawCommand::Circle {
        center: Point::new(ox + p_bot_x * u, oy + p_bot_y * u),
        radius: tip_r,
        color,
    });
    let star_x: f32 = ox + 17.8 * u;
    let star_y: f32 = oy + 6.4 * u;
    let star_arm: f32 = 2.1 * u;
    let star_sw: f32 = (1.45 * u).clamp(1.05, 1.75);
    push_rounded_stroke(
        dl,
        Point::new(star_x, star_y - star_arm),
        Point::new(star_x, star_y + star_arm),
        color,
        star_sw,
    );
    push_rounded_stroke(
        dl,
        Point::new(star_x - star_arm, star_y),
        Point::new(star_x + star_arm, star_y),
        color,
        star_sw,
    );
}

/// Renders a Lucide / SF-Symbols grade 24x24 6-tooth smooth scalloped gear icon with concentric hollow hub into `dl`.
///
/// # Arguments
///
/// - `Rect` - Target logical bounding box.
/// - `&mut DisplayList` - Destination vector draw command list.
/// - `Color` - Foreground stroke color.
pub(crate) fn draw_gear_icon(bounds: Rect, dl: &mut DisplayList, color: Color) {
    let (ox, oy, u, sw): (f32, f32, f32, f32) = topbar_icon_basis(bounds);
    let cx: f32 = ox + 12.0 * u;
    let cy: f32 = oy + 12.0 * u;
    let teeth: f32 = 6.0;
    let r_valley: f32 = 6.7 * u;
    let r_crown: f32 = 9.4 * u;
    let steepness: f32 = 2.6;
    let norm: f32 = steepness.tanh();
    let steps: usize = 72;
    let start_ang: f32 = -PI * 0.5;
    let step_ang: f32 = 2.0 * PI / (steps as f32);
    let mut prev_pt: Point = Point::new(cx, cy - r_crown);
    for idx in 1..=steps {
        let ang: f32 = start_ang + ((idx % steps) as f32) * step_ang;
        let wave: f32 = (teeth * (ang - start_ang)).cos();
        let blend: f32 = 0.5 + 0.5 * ((steepness * wave).tanh() / norm);
        let r: f32 = r_valley + (r_crown - r_valley) * blend;
        let next_pt: Point = Point::new(cx + r * ang.cos(), cy + r * ang.sin());
        dl.push(DrawCommand::Line {
            from: prev_pt,
            to: next_pt,
            color,
            width: sw,
        });
        prev_pt = next_pt;
    }
    let hole_r: f32 = 3.1 * u;
    dl.push(DrawCommand::FillRoundedRect {
        rect: Rect::new(cx - hole_r, cy - hole_r, hole_r * 2.0, hole_r * 2.0),
        color: COLOR_TRANSPARENT,
        radius: CornerRadius::all(RADIUS_PILL),
        border: Border::new(sw, color),
    });
}

/// Mounts one uniform topbar action cluster (command palette, Light/Dark toggle, Settings gear) whose square icon buttons share the shell control-line height and `radius_md`.
///
/// # Arguments
///
/// - `&ShowcaseState` - Shared reactive showcase state.
/// - `ThemeTokens` - Active design tokens at mount time.
///
/// # Returns
///
/// - `NodeId` - Mounted action row handle.
pub(crate) fn mount_topbar_actions(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
    let cmd_open: Signal<bool> = state.get_cmd_palette_open();
    let st_mode: ShowcaseState = state.clone();
    let route_sig: Signal<String> = state.get_route();
    let icon_btn_style = move || -> Style {
        let live_tok: ThemeTokens = use_live_tokens(tokens);
        let live_p: ThemePalette = live_tok.get_palette();
        let live_g: ThemeGeometry = live_tok.get_geometry();
        Style::default()
            .row()
            .width(Length::Px(TOPBAR_CONTROL_SIZE))
            .height(Length::Px(TOPBAR_CONTROL_SIZE))
            .flex_shrink(0.0)
            .justify(JustifyContent::Center)
            .align(AlignItems::Center)
            .background(live_p.get_background())
            .border(live_g.get_border_width(), live_p.get_border())
            .radius(live_g.get_radius_md())
            .cursor(CursorIcon::Pointer)
    };
    let paint_search = move |bounds: Rect, dl: &mut DisplayList| {
        let live_p: ThemePalette = live_tokens_untracked(tokens).get_palette();
        draw_topbar_search_icon(bounds, dl, live_p.get_foreground());
    };
    let paint_mode = move |bounds: Rect, dl: &mut DisplayList| {
        let live_tok: ThemeTokens = live_tokens_untracked(tokens);
        let fg: Color = live_tok.get_palette().get_foreground();
        match live_tok.get_mode() {
            ThemeMode::Dark => draw_theme_sun_icon(bounds, dl, fg),
            ThemeMode::Light => draw_theme_moon_icon(bounds, dl, fg),
        }
    };
    let paint_settings = move |bounds: Rect, dl: &mut DisplayList| {
        let live_p: ThemePalette = live_tokens_untracked(tokens).get_palette();
        draw_gear_icon(bounds, dl, live_p.get_foreground());
    };
    let on_open_cmd = move |_: &UiEvent| {
        let _: bool = cmd_open.set_if_changed(true);
    };
    let on_toggle_mode = move |_: &UiEvent| {
        st_mode.toggle_theme_mode();
    };
    let on_open_settings = move |_: &UiEvent| {
        let _: bool = route_sig.set_if_changed(ROUTE_SETTINGS.to_string());
    };
    view! {
        row {
            style: {
                gap: SPACE_XS
                align: AlignItems::Center
            }
            row {
                bind_style: icon_btn_style
                role: A11yRole::Button
                a11y_label: BTN_SEARCH_A11Y.to_string()
                on_click: on_open_cmd
                canvas {
                    style: {
                        width: Length::Px(TOPBAR_ICON_SIZE)
                        height: Length::Px(TOPBAR_ICON_SIZE)
                    }
                    caching: CanvasCaching::RetainedStatic
                    painter: paint_search
                }
            }
            row {
                bind_style: icon_btn_style
                role: A11yRole::Button
                a11y_label: BTN_MODE_A11Y.to_string()
                on_click: on_toggle_mode
                canvas {
                    style: {
                        width: Length::Px(TOPBAR_ICON_SIZE)
                        height: Length::Px(TOPBAR_ICON_SIZE)
                    }
                    caching: CanvasCaching::RetainedStatic
                    painter: paint_mode
                }
            }
            row {
                bind_style: icon_btn_style
                role: A11yRole::Button
                a11y_label: BTN_SETTINGS_A11Y.to_string()
                on_click: on_open_settings
                canvas {
                    style: {
                        width: Length::Px(TOPBAR_ICON_SIZE)
                        height: Length::Px(TOPBAR_ICON_SIZE)
                    }
                    caching: CanvasCaching::RetainedStatic
                    painter: paint_settings
                }
            }
        }
    }
}