Skip to main content

euv_example/pages/shell/
fn.rs

1use super::*;
2
3/// Registers every `SHOWCASE_ROUTES` entry lazily onto `router` using typed `#[component(retention = Freeze)]` pages.
4///
5/// # Arguments
6///
7/// - `&ShowcaseState` - Shared reactive showcase state.
8pub(crate) fn ensure_showcase_routes_registered(state: &ShowcaseState) {
9    if state.get_router_ready().replace(true) {
10        return;
11    }
12    let mut router: EuvRouter = state.get_router().clone();
13    for spec in SHOWCASE_ROUTES.iter() {
14        let path: &'static str = spec.get_path();
15        let node_style: ShowcaseState = state.clone();
16        router = router.route_component(path, spec.get_label(), move |_: &EuvRouteMatch| {
17            let tok: ThemeTokens = untracked(|| node_style.get_theme().get_tokens().get());
18            ShowcasePage::new(path, node_style.clone(), tok)
19        });
20    }
21    let _: EuvRouter = router;
22}
23
24/// Lazily mounts the global Command Palette `EuvCommand` + `EuvModal` subtree on first open so Frame 1 mounts zero hidden portals.
25///
26/// # Arguments
27///
28/// - `&ShowcaseState` - Shared reactive showcase state.
29/// - `ThemeTokens` - Active design tokens at first open.
30///
31/// # Returns
32///
33/// - `NodeId` - Mounted `EuvModal` handle with selection and in-place theme-remap scopes attached.
34pub(crate) fn mount_lazy_cmd_palette_modal(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
35    let cmd_open: Signal<bool> = state.get_cmd_palette_open();
36    let cmd_query: Signal<String> = state.get_cmd_palette_query();
37    let mut cmd_items: Vec<String> = SHOWCASE_ROUTES
38        .iter()
39        .map(|spec: &ShowcaseRouteSpec| {
40            format!("Go to {} ({})", spec.get_label(), spec.get_section())
41        })
42        .collect();
43    cmd_items.push(CMD_ITEM_TOGGLE_MODE.to_string());
44    let cmd_sel: Signal<Option<usize>> = Signal::new(None);
45    let cmd_route: Signal<String> = state.get_route();
46    let cmd_state: ShowcaseState = state.clone();
47    let cmd_list: NodeId = view! {
48        EuvCommand {
49            items: cmd_items
50            selected: cmd_sel
51            tokens: tokens
52            query: cmd_query
53            placeholder: CMD_PLACEHOLDER
54            frameless: true
55        }
56    };
57    let (cmd_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
58        Effect::new(move || {
59            if let Some(idx) = cmd_sel.get() {
60                match SHOWCASE_ROUTES.get(idx) {
61                    Some(spec) => {
62                        let _: bool = cmd_route.set_if_changed(spec.get_path().to_string());
63                    }
64                    None => {
65                        cmd_state.toggle_theme_mode();
66                    }
67                }
68                let _: bool = cmd_sel.set_if_changed(None);
69                let _: bool = cmd_open.set_if_changed(false);
70            }
71        })
72    });
73    let cmd_modal: NodeId = view! {
74        EuvModal {
75            open: cmd_open
76            title: CMD_MODAL_TITLE.to_string()
77            body: cmd_list
78            tokens: tokens
79        }
80    };
81    let rctx: Context = current_context();
82    let cmd_theme_sig: Memo<ThemeTokens> = state.get_theme().get_tokens();
83    let prev_cmd_tok: Rc<Cell<ThemeTokens>> = Rc::new(Cell::new(tokens));
84    let cmd_theme_ctx: Context = rctx.clone();
85    let (cmd_theme_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
86        Effect::new(move || {
87            let next_tok: ThemeTokens = cmd_theme_sig.get();
88            let old_tok: ThemeTokens = prev_cmd_tok.replace(next_tok);
89            if old_tok == next_tok {
90                return;
91            }
92            cmd_theme_ctx.get_scene().with_write(
93                |tree: &mut SceneTree| {
94                    remap_subtree_theme_in_place(tree, cmd_modal, old_tok, next_tok);
95                },
96                (),
97            );
98        })
99    });
100    rctx.get_scene().with_write(
101        |tree: &mut SceneTree| {
102            tree.attach_scope(cmd_modal, cmd_scope);
103            tree.attach_scope(cmd_modal, cmd_theme_scope);
104        },
105        (),
106    );
107    cmd_modal
108}
109
110/// Mounts the fully reactive showcase application shell with lazy `PageRetention::Freeze` routing and cross-component events.
111///
112/// # Arguments
113///
114/// - `&ShowcaseState` - Reactive showcase state.
115///
116/// # Returns
117///
118/// - `NodeId` - Mounted reactive root container handle.
119pub fn mount_showcase_root(state: &ShowcaseState) -> NodeId {
120    provide_theme(state.get_theme().clone());
121    ensure_showcase_routes_registered(state);
122    let global_banner: Signal<ShowcaseGlobalBanner> =
123        state!(global ShowcaseGlobalBanner = ShowcaseGlobalBanner::default());
124    let state_c: ShowcaseState = state.clone();
125    let bg_state: ShowcaseState = state.clone();
126    let fg_state: ShowcaseState = state.clone();
127    let sys_state: ShowcaseState = state.clone();
128    let sys_log_sig: Signal<Vec<String>> = state.get_system_event_log();
129    let sys_count_sig: Signal<u32> = state.get_system_event_count();
130    let (ev_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
131        let _: SystemEventSubscription = on_background(move || {
132            bg_state.freeze_for_background();
133        });
134        let _: SystemEventSubscription = on_foreground(move || {
135            fg_state.restore_from_foreground();
136        });
137        let _: SystemEventSubscription = on_system_event(move |system_event: &SystemEvent| {
138            if matches!(system_event, SystemEvent::Terminate) {
139                sys_state.freeze_for_background();
140                let _: usize = EuvOverlayStack::dismiss_all();
141                reset_fullscreen_state();
142            } else if matches!(system_event, SystemEvent::Foreground) {
143                sys_state.restore_from_foreground();
144            } else if let SystemEvent::DeepLink(raw_uri) = system_event {
145                let stripped: &str = raw_uri
146                    .trim()
147                    .strip_prefix(DEEP_LINK_SCHEME_PREFIX)
148                    .unwrap_or(raw_uri.trim());
149                let (path_part, query_part): (&str, &str) = stripped
150                    .split('#')
151                    .next()
152                    .unwrap_or("")
153                    .split_once('?')
154                    .unwrap_or((stripped.split('#').next().unwrap_or(""), ""));
155                let trimmed: &str = path_part.trim_matches('/');
156                if trimmed.eq_ignore_ascii_case(DEEP_LINK_HOT_UPDATE_HOST) {
157                    if apply_hot_update_deep_link(sys_state.get_dynamic_hub(), query_part) {
158                        let _: bool = sys_state
159                            .get_route()
160                            .set_if_changed(ROUTE_DYNAMIC.to_string());
161                    }
162                } else {
163                    let candidate: String = if trimmed.is_empty() {
164                        ROUTE_OVERVIEW.to_string()
165                    } else {
166                        format!("/{trimmed}")
167                    };
168                    if SHOWCASE_ROUTES
169                        .iter()
170                        .any(|spec: &ShowcaseRouteSpec| spec.get_path() == candidate.as_str())
171                    {
172                        let _: bool = sys_state.get_route().set_if_changed(candidate);
173                    }
174                }
175            }
176            let next_seq: u32 = sys_count_sig.get_untracked().saturating_add(1);
177            let _: bool = sys_count_sig.set(next_seq);
178            let entry: String = format!("#{next_seq}: {system_event:?}");
179            let _: bool = {
180                if let Some(mut updated_value) = sys_log_sig.try_get_untracked() {
181                    {
182                        let items: &mut Vec<String> = &mut updated_value;
183                        items.insert(0, entry);
184                        if items.len() > SYS_EVENTS_LOG_LIMIT {
185                            items.truncate(SYS_EVENTS_LOG_LIMIT);
186                        }
187                    }
188                    sys_log_sig.set(updated_value)
189                } else {
190                    false
191                }
192            };
193        });
194        on!(ShowcasePulseEvent => move |ev: &ShowcasePulseEvent| {
195                            let src: String = ev.get_source().clone();
196                            let _: bool = {
197                    if let Some(mut updated_value) = global_banner.try_get_untracked() {
198                        {
199        let b: &mut ShowcaseGlobalBanner = &mut updated_value;
200        let next_pulses: u32 = b.get_pulses().saturating_add(1);
201                                b.set_pulses(next_pulses);
202                                b.set_last_source(src);
203        }
204                        global_banner.set(updated_value)
205                    } else {
206                        false
207                    }
208                };
209                        })
210    });
211    let build_root_children = move || -> Vec<NodeId> {
212        let tokens: ThemeTokens = untracked(|| state_c.get_theme().get_tokens().get());
213        let hub: DynamicUpdateHub = state_c.get_dynamic_hub().clone();
214        let cmd_open: Signal<bool> = state_c.get_cmd_palette_open();
215        let column_quaternary_style: Style = style! {
216            Position::Absolute
217            Width(Length::Px(0.0))
218            Height(Length::Px(0.0))
219        };
220        let cmd_slot: NodeId = view! {
221            column {
222                style: column_quaternary_style
223            }
224        };
225        let cmd_mounted: Rc<Cell<bool>> = Rc::new(Cell::new(false));
226        let cmd_state_lazy: ShowcaseState = state_c.clone();
227        let rctx: Context = current_context();
228        let cmd_ctx: Context = rctx.clone();
229        let (cmd_lazy_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
230            Effect::new(move || {
231                if !cmd_open.get() || cmd_mounted.get() {
232                    return;
233                }
234                cmd_mounted.set(true);
235                let live_tok: ThemeTokens =
236                    untracked(|| cmd_state_lazy.get_theme().get_tokens().get());
237                let modal_node: NodeId = with_context(cmd_ctx.clone(), || {
238                    mount_lazy_cmd_palette_modal(&cmd_state_lazy, live_tok)
239                });
240                cmd_ctx.get_scene().with_write(
241                    |tree: &mut SceneTree| {
242                        let dirty_mask: u16 = DIRTY_CHILDREN + DIRTY_LAYOUT + DIRTY_PAINT;
243                        tree.append_child(cmd_slot, modal_node);
244                        tree.mark_dirty(cmd_slot, dirty_mask);
245                    },
246                    (),
247                );
248            })
249        });
250        rctx.get_scene().with_write(
251            |tree: &mut SceneTree| {
252                tree.attach_scope(cmd_slot, cmd_lazy_scope);
253            },
254            (),
255        );
256        let state_shell: ShowcaseState = state_c.clone();
257        let hub_shell: DynamicUpdateHub = hub.clone();
258        let render_native_shell = move || -> NodeId {
259            let shell_node: NodeId = mount_native_app_shell(&state_shell, &hub_shell, tokens);
260            shell_node
261        };
262        let global_wasm_slot: NodeId = view! {
263            slot {
264                id: WASM_GLOBAL_ROOT_SLOT
265                hub: hub
266                style: c_full_col()
267                fallback: render_native_shell
268            }
269        };
270        vec![global_wasm_slot, cmd_slot]
271    };
272    let column_tertiary_style: Style = style! {
273        Width(Length::Percent(100.0))
274        Height(Length::Percent(100.0))
275    };
276    let root_node: NodeId = view! {
277        column {
278            style: column_tertiary_style
279            bind_children: build_root_children
280        }
281    };
282    let root_ctx: Context = current_context();
283    root_ctx.get_scene().with_write(
284        |tree: &mut SceneTree| {
285            tree.attach_scope(root_node, ev_scope);
286        },
287        (),
288    );
289    root_node
290}
291
292/// 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).
293///
294/// # Arguments
295///
296/// - `&ShowcaseState` - Reactive showcase state.
297/// - `&DynamicUpdateHub` - Active OTA dynamic route hub.
298/// - `ThemeTokens` - Active design tokens at mount time.
299///
300/// # Returns
301///
302/// - `NodeId` - Mounted `EuvAppShell` root handle.
303pub(crate) fn mount_native_app_shell(
304    state_shell: &ShowcaseState,
305    hub_shell: &DynamicUpdateHub,
306    tokens: ThemeTokens,
307) -> NodeId {
308    let hub_sidebar: DynamicUpdateHub = hub_shell.clone();
309    let route_sidebar: Signal<String> = state_shell.get_route();
310    let dynamic_route_list: Memo<Vec<(String, String)>> = Memo::new(move || {
311        let _: u64 = hub_sidebar.routes_signal().get();
312        hub_sidebar
313            .registered_routes()
314            .into_iter()
315            .filter(|route_path: &String| route_path != ROUTE_DYNAMIC_PANEL)
316            .map(|route_path: String| {
317                let label: String = hub_sidebar
318                    .page_title(&route_path)
319                    .filter(|title_str: &String| !title_str.is_empty())
320                    .unwrap_or_else(|| route_path.clone());
321                (route_path, label)
322            })
323            .collect()
324    });
325    let build_sidebar_children = move || -> Vec<NodeId> {
326        let mut nav_items: Vec<EuvNavItem> = ShowcaseState::nav_items();
327        for (dyn_route, label) in dynamic_route_list.get().into_iter() {
328            if !nav_items
329                .iter()
330                .any(|item: &EuvNavItem| item.get_path().as_str() == dyn_route.as_str())
331            {
332                nav_items.push(EuvNavItem::new(dyn_route, label).section(NAV_SEC_RUNTIME));
333            }
334        }
335        let sidebar_node: NodeId = view! {
336            EuvSidebarNav {
337                items: nav_items
338                active_route: route_sidebar
339                tokens: tokens
340            }
341        };
342        vec![sidebar_node]
343    };
344    let nav_col_style: Style = style! {
345        Width(Length::Percent(100.0))
346    };
347    let nav: NodeId = view! {
348        column {
349            style: nav_col_style
350            bind_children: build_sidebar_children
351        }
352    };
353    let bottom_items: Vec<EuvNavItem> = vec![
354        EuvNavItem::new(ROUTE_OVERVIEW.to_string(), BNAV_HOME_LABEL.to_string())
355            .section(BNAV_HOME_ICON),
356        EuvNavItem::new(ROUTE_MARKDOWN.to_string(), BNAV_DOCS_LABEL.to_string())
357            .section(BNAV_DOCS_ICON),
358        EuvNavItem::new(ROUTE_LAB.to_string(), BNAV_CASES_LABEL.to_string())
359            .section(BNAV_CASES_ICON),
360        EuvNavItem::new(ROUTE_STRESS.to_string(), BNAV_STRESS_LABEL.to_string())
361            .section(BNAV_STRESS_ICON),
362        EuvNavItem::new(ROUTE_GAME_3D.to_string(), BNAV_3D_LABEL.to_string()).section(BNAV_3D_ICON),
363    ];
364    let bottom_nav: NodeId = view! {
365        EuvBottomNav {
366            items: bottom_items
367            active_route: state_shell.get_route()
368            tokens: tokens
369        }
370    };
371    let swipe_order: Vec<String> = showcase_swipe_order();
372    let state_for_outlet: ShowcaseState = state_shell.clone();
373    let router: EuvRouter = state_shell
374        .get_router()
375        .clone()
376        .with_dynamic_hub(hub_shell.clone());
377    let route_sig: Signal<String> = state_shell.get_route();
378    let cur_target: String = route_sig.get_untracked();
379    if router.get_current_path().get_untracked() != cur_target {
380        router.replace(&cur_target);
381    }
382    let breadcrumb_sig: Signal<String> =
383        Signal::new(ShowcaseState::breadcrumb_for_route(&cur_target));
384    let page_pad_sig: Signal<Edges> = Signal::new(Edges::all(SPACE_LG));
385    let router_sync_in: EuvRouter = router.clone();
386    let router_path_sig: Signal<String> = router.get_current_path();
387    let reduced_motion_sig: Signal<bool> = state_shell.get_reduced_motion();
388    let ui_context: Context = current_context();
389    let (sync_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
390        let _: Effect = Effect::new(move || {
391            let target: String = route_sig.get();
392            if router_sync_in.get_current_path().get_untracked() != target {
393                router_sync_in.push(&target);
394            }
395            let _: bool =
396                breadcrumb_sig.set_if_changed(ShowcaseState::breadcrumb_for_route(&target));
397        });
398        let _: Effect = Effect::new(move || {
399            set_reduced_motion(reduced_motion_sig.get());
400        });
401        Effect::new(move || {
402            let rp: String = router_path_sig.get();
403            if route_sig.get_untracked() != rp {
404                let _: bool = route_sig.set_if_changed(rp);
405            }
406        })
407    });
408    let page_node: NodeId = router
409        .outlet(move |matched: &EuvRouteMatch| {
410            let tok: ThemeTokens = untracked(|| state_for_outlet.get_theme().get_tokens().get());
411            mount_route_by_name(matched.get_path(), &state_for_outlet, tok)
412        })
413        .with_theme(state_shell.get_theme().clone())
414        .with_page_padding(page_pad_sig)
415        .with_route_order(swipe_order.clone())
416        .with_double_back_exit(true)
417        .mount();
418    ui_context.get_scene().with_write(
419        |tree: &mut SceneTree| {
420            tree.attach_scope(page_node, sync_scope);
421        },
422        (),
423    );
424    let scheme_menu_open: Signal<bool> = Signal::new(false);
425    let (top_actions, palette_btn_desk): (NodeId, NodeId) =
426        mount_topbar_actions(state_shell, scheme_menu_open, tokens, true);
427    let (mobile_actions, palette_btn_mob): (NodeId, NodeId) =
428        mount_topbar_actions(state_shell, scheme_menu_open, tokens, false);
429    let shell_node: NodeId = view! {
430        EuvAppShell {
431            brand: SHOWCASE_BRAND.to_string()
432            sidebar: nav
433            main_content: page_node
434            tokens: tokens
435            theme: state_shell.get_theme().clone()
436            page_padding: page_pad_sig
437            route: state_shell.get_route()
438            breadcrumb: breadcrumb_sig
439            top_bar_actions: top_actions
440            mobile_header_actions: mobile_actions
441            bottom_nav: bottom_nav
442            swipe_routes: swipe_order
443            swipe_routes_enabled: state_shell.get_swipe_routing()
444            show_fps: true
445            show_fps_signal: state_shell.get_show_fps_hud()
446            auto_hide_chrome_on_scroll: true
447            auto_hide_chrome_signal: state_shell.get_auto_hide_chrome()
448        }
449    };
450    let scheme_portal: NodeId = mount_topbar_scheme_dropdown_portal(
451        state_shell,
452        scheme_menu_open,
453        tokens,
454        vec![palette_btn_desk, palette_btn_mob],
455    );
456    let column_secondary_style: Style = style! {
457        Width(Length::Percent(100.0))
458        Height(Length::Percent(100.0))
459    };
460    view! {
461        column {
462            style: column_secondary_style
463            { shell_node }
464            { scheme_portal }
465        }
466    }
467}
468
469/// Mounts the showcase page corresponding to the active route in `state`.
470///
471/// # Arguments
472///
473/// - `&ShowcaseState` - Reactive showcase state.
474/// - `ThemeTokens` - Active resolved design tokens.
475///
476/// # Returns
477///
478/// - `NodeId` - Mounted page container handle.
479pub fn mount_active_route(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
480    let route: String = state.get_route().get_untracked();
481    mount_route_by_name(&route, state, tokens)
482}
483
484/// Dispatches a route string to its corresponding declarative showcase page builder.
485///
486/// # Arguments
487///
488/// - `&str` - Active route path.
489/// - `&ShowcaseState` - Reactive showcase state.
490/// - `ThemeTokens` - Active resolved design tokens.
491///
492/// # Returns
493///
494/// - `NodeId` - Mounted page container handle.
495pub(crate) fn mount_route_by_name(
496    route: &str,
497    state: &ShowcaseState,
498    tokens: ThemeTokens,
499) -> NodeId {
500    let builder: fn(&ShowcaseState, ThemeTokens) -> NodeId = SHOWCASE_ROUTES
501        .iter()
502        .find(|spec: &&ShowcaseRouteSpec| spec.get_path() == route)
503        .map(|spec: &ShowcaseRouteSpec| spec.get_mount())
504        .unwrap_or(mount_overview_page);
505    builder(state, tokens)
506}
507
508/// Builds the horizontal swipe route order: the five bottom-nav destinations first, then every remaining registry route in sidebar order.
509///
510/// # Returns
511///
512/// - `Vec<String>` - Ordered swipe route paths.
513pub(crate) fn showcase_swipe_order() -> Vec<String> {
514    let mut order: Vec<String> = BOTTOM_NAV_ROUTES
515        .iter()
516        .map(|path: &&str| (*path).to_string())
517        .collect();
518    for spec in SHOWCASE_ROUTES.iter() {
519        if !BOTTOM_NAV_ROUTES.contains(&spec.get_path()) {
520            order.push(spec.get_path().to_string());
521        }
522    }
523    order
524}
525
526/// Computes normalized 24x24 viewbox origin, unit scale, and Lucide-grade stroke width centered inside `bounds`.
527///
528/// # Arguments
529///
530/// - `Rect` - Target logical bounding box.
531///
532/// # Returns
533///
534/// - `(f32, f32, f32, f32)` - Tuple `(ox, oy, u, stroke_width)`.
535pub(crate) fn topbar_icon_basis(bounds: Rect) -> (f32, f32, f32, f32) {
536    let width_val: f32 = bounds.get_width().max(8.0);
537    let height_val: f32 = bounds.get_height().max(8.0);
538    let side: f32 = width_val.min(height_val);
539    let ox: f32 = bounds.get_x() + (width_val - side) * 0.5;
540    let oy: f32 = bounds.get_y() + (height_val - side) * 0.5;
541    let tex_u: f32 = side / 24.0;
542    let stroke_width: f32 = (1.75 * tex_u).clamp(1.2, 2.0);
543    (ox, oy, tex_u, stroke_width)
544}
545
546/// Emits an anti-aliased line segment with precision rounded endcaps into `dl`.
547///
548/// # Arguments
549///
550/// - `&mut DisplayList` - Destination vector draw command list.
551/// - `Point` - Segment start point.
552/// - `Point` - Segment end point.
553/// - `Color` - Stroke color.
554/// - `f32` - Stroke width in logical pixels.
555pub(crate) fn push_rounded_stroke(
556    display_list: &mut DisplayList,
557    from: Point,
558    to: Point,
559    color: Color,
560    width: f32,
561) {
562    display_list.push(DrawCommand::Line {
563        from,
564        to,
565        color,
566        width,
567    });
568}
569
570/// Renders a Lucide-grade 24x24 search magnifying glass icon into `dl`.
571///
572/// # Arguments
573///
574/// - `Rect` - Target logical bounding box.
575/// - `&mut DisplayList` - Destination vector draw command list.
576/// - `Color` - Foreground stroke color.
577pub(crate) fn draw_topbar_search_icon(bounds: Rect, display_list: &mut DisplayList, color: Color) {
578    let (ox, oy, tex_u, stroke_width): (f32, f32, f32, f32) = topbar_icon_basis(bounds);
579    let lens_d: f32 = 13.6 * tex_u;
580    display_list.push(DrawCommand::FillRoundedRect {
581        rect: Rect::new(ox + 4.0 * tex_u, oy + 4.0 * tex_u, lens_d, lens_d),
582        color: COLOR_TRANSPARENT,
583        radius: CornerRadius::all(RADIUS_PILL),
584        border: Border::new(stroke_width, color),
585    });
586    push_rounded_stroke(
587        display_list,
588        Point::new(ox + 15.2 * tex_u, oy + 15.2 * tex_u),
589        Point::new(ox + 20.2 * tex_u, oy + 20.2 * tex_u),
590        color,
591        stroke_width,
592    );
593}
594
595/// Renders a Lucide / SF-Symbols grade 24x24 Sun icon (hollow center circle + 8 evenly-spaced rounded rays) into `dl`.
596///
597/// # Arguments
598///
599/// - `Rect` - Target logical bounding box.
600/// - `&mut DisplayList` - Destination vector draw command list.
601/// - `Color` - Foreground stroke color.
602pub(crate) fn draw_theme_sun_icon(bounds: Rect, display_list: &mut DisplayList, color: Color) {
603    let (ox, oy, tex_u, stroke_width): (f32, f32, f32, f32) = topbar_icon_basis(bounds);
604    let cx: f32 = ox + 12.0 * tex_u;
605    let cy: f32 = oy + 12.0 * tex_u;
606    let core_r: f32 = 4.2 * tex_u;
607    display_list.push(DrawCommand::FillRoundedRect {
608        rect: Rect::new(cx - core_r, cy - core_r, core_r * 2.0, core_r * 2.0),
609        color: COLOR_TRANSPARENT,
610        radius: CornerRadius::all(RADIUS_PILL),
611        border: Border::new(stroke_width, color),
612    });
613    let r_in: f32 = 7.0 * tex_u;
614    let r_out: f32 = 9.4 * tex_u;
615    for idx in 0..8_u8 {
616        let ang: f32 = (idx as f32) * (PI * 0.25);
617        let (cos_a, sin_a): (f32, f32) = (ang.cos(), ang.sin());
618        push_rounded_stroke(
619            display_list,
620            Point::new(cx + r_in * cos_a, cy + r_in * sin_a),
621            Point::new(cx + r_out * cos_a, cy + r_out * sin_a),
622            color,
623            stroke_width,
624        );
625    }
626}
627
628/// Renders a Lucide `MoonStar`-grade 24x24 crescent moon (exact circle-circle analytical arcs + 4-point star sparkle) into `dl`.
629///
630/// # Arguments
631///
632/// - `Rect` - Target logical bounding box.
633/// - `&mut DisplayList` - Destination vector draw command list.
634/// - `Color` - Foreground stroke color.
635pub(crate) fn draw_theme_moon_icon(bounds: Rect, display_list: &mut DisplayList, color: Color) {
636    let (ox, oy, tex_u, stroke_width): (f32, f32, f32, f32) = topbar_icon_basis(bounds);
637    let c1x: f32 = 11.8;
638    let c1y: f32 = 12.4;
639    let r1: f32 = 8.2;
640    let c2x: f32 = 16.4;
641    let c2y: f32 = 8.2;
642    let r2: f32 = 6.6;
643    let dx: f32 = c2x - c1x;
644    let dy: f32 = c2y - c1y;
645    let dist: f32 = (dx * dx + dy * dy).sqrt();
646    let base_ang: f32 = dy.atan2(dx);
647    let alpha_val: f32 = (r1 * r1 - r2 * r2 + dist * dist) / (2.0 * dist);
648    let alpha1: f32 = (alpha_val / r1).clamp(-1.0, 1.0).acos();
649    let theta1_top: f32 = base_ang - alpha1;
650    let theta1_bot: f32 = base_ang + alpha1;
651    let theta1_end: f32 = theta1_top + 2.0 * PI;
652    let p_top_x: f32 = c1x + r1 * theta1_top.cos();
653    let p_top_y: f32 = c1y + r1 * theta1_top.sin();
654    let p_bot_x: f32 = c1x + r1 * theta1_bot.cos();
655    let p_bot_y: f32 = c1y + r1 * theta1_bot.sin();
656    let p_top: Point = Point::new(ox + p_top_x * tex_u, oy + p_top_y * tex_u);
657    let p_bot: Point = Point::new(ox + p_bot_x * tex_u, oy + p_bot_y * tex_u);
658    let outer_steps: usize = 20;
659    let mut prev_outer: Point = p_bot;
660    for step in 1..=outer_steps {
661        let next_pt: Point = if step == outer_steps {
662            p_top
663        } else {
664            let blend_factor: f32 = (step as f32) / (outer_steps as f32);
665            let ang: f32 = theta1_bot + (theta1_end - theta1_bot) * blend_factor;
666            Point::new(
667                ox + (c1x + r1 * ang.cos()) * tex_u,
668                oy + (c1y + r1 * ang.sin()) * tex_u,
669            )
670        };
671        display_list.push(DrawCommand::Line {
672            from: prev_outer,
673            to: next_pt,
674            color,
675            width: stroke_width,
676        });
677        prev_outer = next_pt;
678    }
679    let mut theta2_top: f32 = (p_top_y - c2y).atan2(p_top_x - c2x);
680    let theta2_bot: f32 = (p_bot_y - c2y).atan2(p_bot_x - c2x);
681    if theta2_top < theta2_bot {
682        theta2_top += 2.0 * PI;
683    }
684    let inner_steps: usize = 14;
685    let mut prev_inner: Point = p_top;
686    for step in 1..=inner_steps {
687        let next_pt: Point = if step == inner_steps {
688            p_bot
689        } else {
690            let time_step: f32 = (step as f32) / (inner_steps as f32);
691            let ang: f32 = theta2_top + (theta2_bot - theta2_top) * time_step;
692            Point::new(
693                ox + (c2x + r2 * ang.cos()) * tex_u,
694                oy + (c2y + r2 * ang.sin()) * tex_u,
695            )
696        };
697        display_list.push(DrawCommand::Line {
698            from: prev_inner,
699            to: next_pt,
700            color,
701            width: stroke_width,
702        });
703        prev_inner = next_pt;
704    }
705    let star_x: f32 = ox + 17.8 * tex_u;
706    let star_y: f32 = oy + 6.4 * tex_u;
707    let star_arm: f32 = 2.1 * tex_u;
708    let star_sw: f32 = (1.45 * tex_u).clamp(1.05, 1.75);
709    push_rounded_stroke(
710        display_list,
711        Point::new(star_x, star_y - star_arm),
712        Point::new(star_x, star_y + star_arm),
713        color,
714        star_sw,
715    );
716    push_rounded_stroke(
717        display_list,
718        Point::new(star_x - star_arm, star_y),
719        Point::new(star_x + star_arm, star_y),
720        color,
721        star_sw,
722    );
723}
724
725/// Renders a Lucide / SF-Symbols grade 24x24 8-tooth precision cog gear icon with concentric hollow hub into `dl`.
726///
727/// # Arguments
728///
729/// - `Rect` - Target logical bounding box.
730/// - `&mut DisplayList` - Destination vector draw command list.
731/// - `Color` - Foreground stroke color.
732pub(crate) fn draw_gear_icon(bounds: Rect, display_list: &mut DisplayList, color: Color) {
733    let (ox, oy, tex_u, stroke_width): (f32, f32, f32, f32) = topbar_icon_basis(bounds);
734    let cx: f32 = ox + 12.0 * tex_u;
735    let cy: f32 = oy + 12.0 * tex_u;
736    let body_r: f32 = 6.3 * tex_u;
737    display_list.push(DrawCommand::FillRoundedRect {
738        rect: Rect::new(cx - body_r, cy - body_r, body_r * 2.0, body_r * 2.0),
739        color: COLOR_TRANSPARENT,
740        radius: CornerRadius::all(RADIUS_PILL),
741        border: Border::new(stroke_width, color),
742    });
743    let tooth_in: f32 = 6.0 * tex_u;
744    let tooth_out: f32 = 9.0 * tex_u;
745    let tooth_w: f32 = (stroke_width * 1.35).clamp(1.6, 2.7);
746    for idx in 0..8_u8 {
747        let ang: f32 = (idx as f32) * (PI * 0.25);
748        let (cos_a, sin_a): (f32, f32) = (ang.cos(), ang.sin());
749        display_list.push(DrawCommand::Line {
750            from: Point::new(cx + tooth_in * cos_a, cy + tooth_in * sin_a),
751            to: Point::new(cx + tooth_out * cos_a, cy + tooth_out * sin_a),
752            color,
753            width: tooth_w,
754        });
755    }
756    let hole_r: f32 = 2.8 * tex_u;
757    display_list.push(DrawCommand::FillRoundedRect {
758        rect: Rect::new(cx - hole_r, cy - hole_r, hole_r * 2.0, hole_r * 2.0),
759        color: COLOR_TRANSPARENT,
760        radius: CornerRadius::all(RADIUS_PILL),
761        border: Border::new(stroke_width, color),
762    });
763}
764
765/// Returns the clean human-readable display name for one of the 17 built-in `DesignScheme` presets.
766///
767/// # Arguments
768///
769/// - `DesignScheme` - Target design scheme variant.
770///
771/// # Returns
772///
773/// - `&'static str` - Human-readable scheme title.
774pub(crate) fn scheme_display_label(scheme: DesignScheme) -> &'static str {
775    match scheme {
776        DesignScheme::Shadcn => "Shadcn",
777        DesignScheme::Cupertino => "Cupertino",
778        DesignScheme::Material => "Material",
779        DesignScheme::Fluent => "Fluent",
780        DesignScheme::AntDesign => "Ant Design",
781        DesignScheme::Bootstrap => "Bootstrap",
782        DesignScheme::DaisyUi => "DaisyUI",
783        DesignScheme::Geist => "Geist",
784        DesignScheme::HeroUi => "HeroUI",
785        DesignScheme::Linear => "Linear",
786        DesignScheme::Mantine => "Mantine",
787        DesignScheme::Monochrome => "Monochrome",
788        DesignScheme::Notion => "Notion",
789        DesignScheme::Park => "Park UI",
790        DesignScheme::Radix => "Radix",
791        DesignScheme::Stripe => "Stripe",
792        DesignScheme::Supabase => "Supabase",
793    }
794}
795
796/// Renders a Lucide-grade 24×24 `Palette` vector icon with an active theme accent swatch dot into `dl`.
797///
798/// # Arguments
799///
800/// - `Rect` - Target logical bounding box.
801/// - `&mut DisplayList` - Destination vector draw command list.
802/// - `Color` - Foreground stroke color.
803/// - `Color` - Active theme primary accent color rendered inside the swatch dot.
804pub(crate) fn draw_topbar_palette_icon(
805    bounds: Rect,
806    display_list: &mut DisplayList,
807    color: Color,
808    accent: Color,
809) {
810    let (ox, oy, tex_u, stroke_width): (f32, f32, f32, f32) = topbar_icon_basis(bounds);
811    let cx: f32 = ox + 12.0 * tex_u;
812    let cy: f32 = oy + 12.0 * tex_u;
813    let red_val: f32 = 8.8 * tex_u;
814    let start_ang: f32 = 0.56;
815    let end_ang: f32 = 2.0 * PI - 0.12;
816    let p_start: Point = Point::new(
817        cx + red_val * start_ang.cos(),
818        cy + red_val * start_ang.sin(),
819    );
820    let arc_steps: usize = 22;
821    let mut prev: Point = p_start;
822    for source_val in 1..=arc_steps {
823        let blend_factor: f32 = (source_val as f32) / (arc_steps as f32);
824        let alpha_val: f32 = start_ang + (end_ang - start_ang) * blend_factor;
825        let cur: Point = Point::new(
826            cx + red_val * alpha_val.cos(),
827            cy + red_val * alpha_val.sin(),
828        );
829        display_list.push(DrawCommand::Line {
830            from: prev,
831            to: cur,
832            color,
833            width: stroke_width,
834        });
835        prev = cur;
836    }
837    let notch: [Point; 7] = [
838        prev,
839        Point::new(ox + 17.6 * tex_u, oy + 11.4 * tex_u),
840        Point::new(ox + 15.6 * tex_u, oy + 12.2 * tex_u),
841        Point::new(ox + 14.8 * tex_u, oy + 13.6 * tex_u),
842        Point::new(ox + 15.6 * tex_u, oy + 15.0 * tex_u),
843        Point::new(ox + 17.4 * tex_u, oy + 15.8 * tex_u),
844        p_start,
845    ];
846    for item_index in 0..6usize {
847        display_list.push(DrawCommand::Line {
848            from: notch[item_index],
849            to: notch[item_index + 1],
850            color,
851            width: stroke_width,
852        });
853    }
854    let dot_r: f32 = (1.35 * tex_u).max(1.0);
855    for &(dx, dy) in [(7.6_f32, 10.0_f32), (11.2, 6.8), (15.6, 8.6)].iter() {
856        display_list.push(DrawCommand::Circle {
857            center: Point::new(ox + dx * tex_u, oy + dy * tex_u),
858            radius: dot_r,
859            color,
860        });
861    }
862    let swatch_r: f32 = (2.15 * tex_u).max(1.5);
863    display_list.push(DrawCommand::Circle {
864        center: Point::new(ox + 9.2 * tex_u, oy + 15.2 * tex_u),
865        radius: swatch_r,
866        color: accent,
867    });
868}
869
870/// Mounts the viewport-clamped scrollable floating 17-Scheme Theme Color Dropdown portal anchored beneath the showcase topbar Palette icon button.
871///
872/// # Arguments
873///
874/// - `&ShowcaseState` - Shared reactive showcase state.
875/// - `Signal<bool>` - Controlled dropdown open state signal.
876/// - `ThemeTokens` - Base design tokens.
877/// - `Vec<NodeId>` - Desktop and Mobile Palette button node handles.
878///
879/// # Returns
880///
881/// - `NodeId` - Mounted floating scheme dropdown portal handle.
882pub(crate) fn mount_topbar_scheme_dropdown_portal(
883    state: &ShowcaseState,
884    open_sig: Signal<bool>,
885    tokens: ThemeTokens,
886    triggers: Vec<NodeId>,
887) -> NodeId {
888    let mut ctx: Context = current_context();
889    let scheme_sig: Signal<DesignScheme> = state.get_theme().get_scheme();
890    let mode_sig: Signal<ThemeMode> = state.get_theme().get_mode();
891    let vp_sig: Signal<Size> = ctx.get_viewport_size();
892    let safe_sig: Signal<SafeAreaInsets> = ctx.get_safe_area();
893    let init_tok: ThemeTokens = live_tokens_untracked(tokens);
894    let palette: ThemePalette = init_tok.get_palette();
895    let geometry: ThemeGeometry = init_tok.get_geometry();
896    let card_s: SurfaceColors = palette.surface(SurfaceRole::Card);
897    let menu_r: f32 = geometry.get_radius_lg();
898    let item_r: f32 = concentric_radius(menu_r, CONTROL_INSET);
899    let all_schemes: [DesignScheme; 17] = DesignScheme::all();
900    let init_scheme: DesignScheme = scheme_sig.get_untracked();
901    let init_mode: ThemeMode = mode_sig.get_untracked();
902    let hovered_idx: Signal<Option<usize>> = Signal::new(None);
903    let mut item_handles: Vec<(DesignScheme, NodeId, NodeId, NodeId, NodeId)> =
904        Vec::with_capacity(all_schemes.len());
905    let mut item_nodes: Vec<NodeId> = Vec::with_capacity(all_schemes.len());
906    for (idx, scheme) in all_schemes.into_iter().enumerate() {
907        let is_sel: bool = scheme == init_scheme;
908        let (init_bg, init_fg): (Color, Color) = if is_sel {
909            let ps: SurfaceColors = palette.surface(SurfaceRole::Primary);
910            (ps.get_bg(), ps.get_fg())
911        } else {
912            (COLOR_TRANSPARENT, card_s.get_fg())
913        };
914        let init_swatch: Color = ThemeTokens::resolve(scheme, init_mode)
915            .get_palette()
916            .get_primary();
917        let lbl_str: &'static str = scheme_display_label(scheme);
918        let on_pick = move |_: &UiEvent| {
919            let _: bool = scheme_sig.set_if_changed(scheme);
920            let _: bool = open_sig.set_if_changed(false);
921        };
922        let paint_check = move |bounds: Rect, display_list: &mut DisplayList| {
923            if scheme_sig.get_untracked() == scheme {
924                let lp: ThemePalette = live_tokens_untracked(tokens).get_palette();
925                let fg: Color = lp.surface(SurfaceRole::Primary).get_fg();
926                draw_euv_icon(EuvIconName::Check, bounds, display_list, fg);
927            }
928        };
929        let mut dot_id: NodeId = NodeId::default();
930        let mut txt_id: NodeId = NodeId::default();
931        let mut chk_id: NodeId = NodeId::default();
932        let row_secondary_style: Style = style! {
933            Width(Length::Percent(100.0))
934            Height(Length::Px(SCHEME_DROPDOWN_ITEM_HEIGHT))
935            Padding(Edges::symmetric(0.0, SPACE_SM))
936            AlignItems::Center
937            Gap(SPACE_SM)
938            Background(init_bg)
939            Radius(item_r)
940            Overflow::Hidden
941            CursorIcon::Pointer
942            StopEventPropagation(true)
943        };
944        let view_style: Style = style! {
945            Width(Length::Px(12.0))
946            Height(Length::Px(12.0))
947            FlexShrink(0.0)
948            Background(init_swatch)
949            Border::new(1.0, palette.get_border())
950            Radius(RADIUS_PILL)
951        };
952        let text_style: Style = style! {
953            FlexGrow(1.0)
954            FlexShrink(1.0)
955            MinWidth(Length::Px(0.0))
956            FontSize(13.0)
957            if is_sel { FontWeight::SemiBold } else { FontWeight::Normal }
958            TextColor(init_fg)
959            Overflow::Hidden
960            TextOverflow::Ellipsis
961        };
962        let canvas_secondary_style: Style = style! {
963            Width(Length::Px(13.0))
964            Height(Length::Px(13.0))
965            FlexShrink(0.0)
966        };
967        let row_id: NodeId = view! {
968            row {
969                style: row_secondary_style
970                role: A11yRole::MenuItem
971                a11y_label: lbl_str.to_string()
972                on_click: on_pick
973                view {
974                    node_ref: dot_id
975                    style: view_style
976                }
977                text {
978                    node_ref: txt_id
979                    style: text_style
980                    { lbl_str }
981                }
982                canvas {
983                    node_ref: chk_id
984                    style: canvas_secondary_style
985                    painter: paint_check
986                }
987            }
988        };
989        ctx.on_pointer_enter(row_id, move |_: &UiEvent| {
990            let _: bool = hovered_idx.set_if_changed(Some(idx));
991        });
992        ctx.on_pointer_leave(row_id, move |_: &UiEvent| {
993            if hovered_idx.get_untracked() == Some(idx) {
994                let _: bool = hovered_idx.set_if_changed(None);
995            }
996        });
997        item_handles.push((scheme, row_id, dot_id, txt_id, chk_id));
998        item_nodes.push(row_id);
999    }
1000    let mut card: NodeId = NodeId::default();
1001    let mut scroll_list: NodeId = NodeId::default();
1002    let portal_style: Style = style! {
1003        Display::None
1004        Position::Fixed
1005        Inset(Some(0.0), Some(0.0), Some(0.0), Some(0.0))
1006        Width(Length::Percent(100.0))
1007        Height(Length::Percent(100.0))
1008        Background(COLOR_TRANSPARENT)
1009        PointerEvents::None
1010        StopScrollPropagation(true)
1011        ZIndex(SCHEME_DROPDOWN_Z_INDEX)
1012    };
1013    let column_style: Style = style! {
1014        Position::Absolute
1015        Inset(Some(SHELL_DESKTOP_HEADER_HEIGHT + 6.0), None, None, Some(8.0))
1016        Width(Length::Px(SCHEME_DROPDOWN_WIDTH))
1017        Padding(Edges::all(CONTROL_INSET))
1018        Background(card_s.get_bg())
1019        Border::new(geometry.get_border_width(), card_s.get_border())
1020        Radius(menu_r)
1021        geometry.get_shadow_lg()
1022        Overflow::Hidden
1023        StopEventPropagation(true)
1024    };
1025    let scroll_style: Style = style! {
1026        FlexDirection::Column
1027        Width(Length::Percent(100.0))
1028        MaxHeight(Length::Px(SCHEME_DROPDOWN_MAX_HEIGHT))
1029        Gap(CONTROL_INSET)
1030    };
1031    let portal: NodeId = view! {
1032        portal {
1033            style: portal_style
1034            column {
1035                node_ref: card
1036                style: column_style
1037                role: A11yRole::Menu
1038                a11y_label: BTN_SCHEME_A11Y.to_string()
1039                scroll {
1040                    node_ref: scroll_list
1041                    style: scroll_style
1042                    ..item_nodes
1043                }
1044            }
1045        }
1046    };
1047    ctx.on_click(portal, move |ui_event: &UiEvent| {
1048        if ui_event.get_target() == portal {
1049            let _: bool = open_sig.set_if_changed(false);
1050        }
1051    });
1052    for key_target in [portal, card].into_iter() {
1053        ctx.on_key(key_target, move |interaction_event: &UiEvent| {
1054            let is_esc: bool = matches!(
1055                interaction_event.get_kind(),
1056                UiEventKind::KeyDown(KeyCode::Escape, _)
1057            ) || matches!(
1058                interaction_event.get_kind(),
1059                UiEventKind::KeyDown(KeyCode::Back, _)
1060            );
1061            if is_esc && open_sig.get_untracked() {
1062                let _: bool = open_sig.set_if_changed(false);
1063            }
1064        });
1065    }
1066    let sc_pos: SceneHandle = ctx.get_scene().clone();
1067    let sc_paint: SceneHandle = sc_pos.clone();
1068    let owned_nodes: Vec<NodeId> = {
1069        let mut node_id: Vec<NodeId> = Vec::with_capacity(item_handles.len() * 4 + 3);
1070        node_id.push(portal);
1071        node_id.push(card);
1072        node_id.push(scroll_list);
1073        for &(_, rid, did, tid, cid) in item_handles.iter() {
1074            node_id.push(rid);
1075            node_id.push(did);
1076            node_id.push(tid);
1077            node_id.push(cid);
1078        }
1079        node_id
1080    };
1081    let (scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1082        let _: Effect = EuvOverlayStack::bind_signal(
1083            open_sig,
1084            SCHEME_DROPDOWN_OVERLAY_NAME,
1085            SCHEME_DROPDOWN_Z_INDEX,
1086        );
1087        let _: Effect = Effect::new(move || {
1088            let is_open: bool = open_sig.get();
1089            let box_size: Size = vp_sig.get();
1090            let safe: SafeAreaInsets = safe_sig.get();
1091            let vp_w: f32 = box_size.get_width().max(320.0);
1092            let vp_h: f32 = box_size.get_height().max(320.0);
1093            let margin: f32 = SCHEME_DROPDOWN_EDGE_MARGIN;
1094            let safe_l: f32 = safe.get_left().max(0.0);
1095            let safe_r: f32 = safe.get_right().max(0.0);
1096            let safe_t: f32 = safe.get_top().max(0.0);
1097            let safe_b: f32 = safe.get_bottom().max(0.0);
1098            let menu_w: f32 =
1099                SCHEME_DROPDOWN_WIDTH.min((vp_w - safe_l - safe_r - margin * 2.0).max(160.0));
1100            let anchor_opt: Option<Rect> = sc_pos.with_read(
1101                |tree: &SceneTree| {
1102                    for &tid in triggers.iter() {
1103                        if tree.is_node_visible(tid)
1104                            && let Some(red_val) = tree.node_screen_bounds(tid)
1105                            && red_val.get_width() > 4.0
1106                            && red_val.get_height() > 4.0
1107                        {
1108                            return Some(red_val);
1109                        }
1110                    }
1111                    None
1112                },
1113                None,
1114            );
1115            let (raw_left, raw_top): (f32, f32) = match anchor_opt {
1116                Some(radius_val) => (
1117                    radius_val.get_x() + radius_val.get_width() - menu_w,
1118                    radius_val.get_y() + radius_val.get_height() + 6.0,
1119                ),
1120                None => (
1121                    vp_w - safe_r - menu_w - margin,
1122                    SHELL_DESKTOP_HEADER_HEIGHT + safe_t + 6.0,
1123                ),
1124            };
1125            let min_left: f32 = safe_l + margin;
1126            let max_left: f32 = (vp_w - safe_r - menu_w - margin).max(min_left);
1127            let left: f32 = raw_left.clamp(min_left, max_left);
1128            let min_top: f32 = safe_t + margin;
1129            let top_clamped: f32 = raw_top.max(min_top);
1130            let avail_h: f32 = (vp_h - safe_b - top_clamped - margin).max(120.0);
1131            let max_h: f32 = SCHEME_DROPDOWN_MAX_HEIGHT.min(avail_h).max(120.0);
1132            let max_top: f32 = (vp_h - safe_b - max_h - margin).max(min_top);
1133            let top: f32 = top_clamped.min(max_top);
1134            let inner_max_h: f32 = (max_h - CONTROL_INSET * 2.0).max(96.0);
1135            if !is_open {
1136                let _: bool = hovered_idx.set_if_changed(None);
1137            }
1138            sc_pos.with_write(
1139                |tree: &mut SceneTree| {
1140                    let dirty_l: u16 = DIRTY_LAYOUT | DIRTY_SUBTREE_LAYOUT;
1141                    let dirty_all: u16 = dirty_l | DIRTY_PAINT;
1142                    if let Some(item_count) = tree.get_node_mut(scroll_list) {
1143                        item_count
1144                            .get_mut_style()
1145                            .get_mut_layout()
1146                            .set_max_height(Length::Px(inner_max_h));
1147                        tree.mark_dirty(scroll_list, dirty_all);
1148                    }
1149                    if let Some(node_entry) = tree.get_node_mut(card) {
1150                        let lay: &mut LayoutStyle = node_entry.get_mut_style().get_mut_layout();
1151                        lay.set_left(Some(left))
1152                            .set_top(Some(top))
1153                            .set_width(Length::Px(menu_w));
1154                        tree.mark_dirty(card, dirty_all);
1155                    }
1156                    if let Some(normal_vec) = tree.get_node_mut(portal) {
1157                        let computed_style: &mut Style = normal_vec.get_mut_style();
1158                        computed_style.get_mut_layout().set_display(if is_open {
1159                            Display::Flex
1160                        } else {
1161                            Display::None
1162                        });
1163                        computed_style
1164                            .get_mut_paint()
1165                            .set_pointer_events(if is_open {
1166                                PointerEvents::Auto
1167                            } else {
1168                                PointerEvents::None
1169                            });
1170                        tree.mark_dirty(portal, dirty_all);
1171                    }
1172                },
1173                (),
1174            );
1175        });
1176        Effect::new(move || {
1177            let cur_scheme: DesignScheme = scheme_sig.get();
1178            let cur_mode: ThemeMode = mode_sig.get();
1179            let hov: Option<usize> = hovered_idx.get();
1180            let tok: ThemeTokens = use_live_tokens(tokens);
1181            let lp: ThemePalette = tok.get_palette();
1182            let lg: ThemeGeometry = tok.get_geometry();
1183            let cs: SurfaceColors = lp.surface(SurfaceRole::Card);
1184            let ps: SurfaceColors = lp.surface(SurfaceRole::Primary);
1185            let ac: SurfaceColors = lp.surface(SurfaceRole::Accent);
1186            sc_paint.with_write(
1187                |tree: &mut SceneTree| {
1188                    if let Some(total_len) = tree.get_node_mut(card) {
1189                        total_len
1190                            .get_mut_style()
1191                            .get_mut_paint()
1192                            .set_background(Some(cs.get_bg()))
1193                            .set_border(Border::new(lg.get_border_width(), cs.get_border()))
1194                            .set_shadow(Some(lg.get_shadow_lg()));
1195                        tree.mark_dirty(card, DIRTY_PAINT);
1196                    }
1197                    for (idx, &(sc_item, rid, did, tid, cid)) in item_handles.iter().enumerate() {
1198                        let is_sel: bool = sc_item == cur_scheme;
1199                        let is_hov: bool = hov == Some(idx);
1200                        let (bg, fg): (Color, Color) = if is_sel {
1201                            (ps.get_bg(), ps.get_fg())
1202                        } else if is_hov {
1203                            (ac.get_bg(), ac.get_fg())
1204                        } else {
1205                            (COLOR_TRANSPARENT, cs.get_fg())
1206                        };
1207                        let sw_col: Color = ThemeTokens::resolve(sc_item, cur_mode)
1208                            .get_palette()
1209                            .get_primary();
1210                        let sw_border: Color = if is_sel {
1211                            ps.get_fg().with_alpha(160)
1212                        } else {
1213                            lp.get_border()
1214                        };
1215                        if let Some(item_count_primary) = tree.get_node_mut(rid) {
1216                            item_count_primary
1217                                .get_mut_style()
1218                                .get_mut_paint()
1219                                .set_background(Some(bg));
1220                            tree.mark_dirty(rid, DIRTY_PAINT);
1221                        }
1222                        if let Some(item_count_secondary) = tree.get_node_mut(did) {
1223                            item_count_secondary
1224                                .get_mut_style()
1225                                .get_mut_paint()
1226                                .set_background(Some(sw_col))
1227                                .set_border(Border::new(1.0, sw_border));
1228                            tree.mark_dirty(did, DIRTY_PAINT);
1229                        }
1230                        if let Some(item_count_next) = tree.get_node_mut(tid) {
1231                            item_count_next
1232                                .get_mut_style()
1233                                .get_mut_text()
1234                                .set_color(fg)
1235                                .set_weight(if is_sel {
1236                                    FontWeight::SemiBold
1237                                } else {
1238                                    FontWeight::Normal
1239                                });
1240                            tree.mark_dirty(tid, DIRTY_PAINT);
1241                        }
1242                        tree.mark_dirty(cid, DIRTY_PAINT);
1243                    }
1244                },
1245                (),
1246            );
1247        })
1248    });
1249    ctx.get_scene().with_write(
1250        |tree: &mut SceneTree| {
1251            mark_theme_owned(tree, owned_nodes.as_slice());
1252            tree.attach_scope(portal, scope);
1253        },
1254        (),
1255    );
1256    portal
1257}
1258
1259/// Mounts one uniform topbar action cluster (command palette, 17-scheme Palette dropdown trigger, Light/Dark toggle, Settings gear) whose square icon buttons share the shell control-line height and `radius_md`.
1260///
1261/// # Arguments
1262///
1263/// - `&ShowcaseState` - Shared reactive showcase state.
1264/// - `Signal<bool>` - Controlled scheme dropdown visibility signal.
1265/// - `ThemeTokens` - Active design tokens at mount time.
1266///
1267/// # Returns
1268///
1269/// - `(NodeId, NodeId)` - Mounted action row handle and Palette trigger button handle.
1270pub(crate) fn mount_topbar_actions(
1271    state: &ShowcaseState,
1272    scheme_menu_open: Signal<bool>,
1273    tokens: ThemeTokens,
1274    include_settings: bool,
1275) -> (NodeId, NodeId) {
1276    let cmd_open: Signal<bool> = state.get_cmd_palette_open();
1277    let st_mode: ShowcaseState = state.clone();
1278    let route_sig: Signal<String> = state.get_route();
1279    let icon_btn_style = move || -> Style {
1280        let live_tok: ThemeTokens = use_live_tokens(tokens);
1281        let live_p: ThemePalette = live_tok.get_palette();
1282        let live_g: ThemeGeometry = live_tok.get_geometry();
1283        style! {
1284            FlexDirection::Row
1285            Width(Length::Px(TOPBAR_CONTROL_SIZE))
1286            Height(Length::Px(TOPBAR_CONTROL_SIZE))
1287            FlexShrink(0.0)
1288            JustifyContent::Center
1289            AlignItems::Center
1290            Background(live_p.get_background())
1291            Border::new(live_g.get_border_width(), live_p.get_border())
1292            Radius(live_g.get_radius_md())
1293            CursorIcon::Pointer
1294        }
1295    };
1296    let paint_search = move |bounds: Rect, display_list: &mut DisplayList| {
1297        let live_p: ThemePalette = live_tokens_untracked(tokens).get_palette();
1298        draw_topbar_search_icon(bounds, display_list, live_p.get_foreground());
1299    };
1300    let paint_palette = move |bounds: Rect, draw_commands: &mut DisplayList| {
1301        let live_p: ThemePalette = live_tokens_untracked(tokens).get_palette();
1302        draw_topbar_palette_icon(
1303            bounds,
1304            draw_commands,
1305            live_p.get_foreground(),
1306            live_p.get_primary(),
1307        );
1308    };
1309    let paint_mode = move |bounds: Rect, command_list: &mut DisplayList| {
1310        let live_tok: ThemeTokens = live_tokens_untracked(tokens);
1311        let fg: Color = live_tok.get_palette().get_foreground();
1312        match live_tok.get_mode() {
1313            ThemeMode::Dark => draw_theme_sun_icon(bounds, command_list, fg),
1314            ThemeMode::Light => draw_theme_moon_icon(bounds, command_list, fg),
1315        }
1316    };
1317    let paint_settings = move |bounds: Rect, display_list_primary: &mut DisplayList| {
1318        let live_p: ThemePalette = live_tokens_untracked(tokens).get_palette();
1319        draw_gear_icon(bounds, display_list_primary, live_p.get_foreground());
1320    };
1321    let on_open_cmd = move |_: &UiEvent| {
1322        let _: bool = scheme_menu_open.set_if_changed(false);
1323        let _: bool = cmd_open.set_if_changed(true);
1324    };
1325    let on_toggle_scheme = move |_: &UiEvent| {
1326        let _: bool = scheme_menu_open.set(!scheme_menu_open.get_untracked());
1327    };
1328    let on_toggle_mode = move |_: &UiEvent| {
1329        st_mode.toggle_theme_mode();
1330    };
1331    let on_open_settings = move |_: &UiEvent| {
1332        let _: bool = scheme_menu_open.set_if_changed(false);
1333        let _: bool = route_sig.set_if_changed(ROUTE_SETTINGS.to_string());
1334    };
1335    let mut palette_btn: NodeId = NodeId::default();
1336    let row_style: Style = style! {
1337        Gap(SPACE_XS)
1338        AlignItems::Center
1339    };
1340    let canvas_style: Style = style! {
1341        Width(Length::Px(TOPBAR_ICON_SIZE))
1342        Height(Length::Px(TOPBAR_ICON_SIZE))
1343    };
1344    let cluster: NodeId = view! {
1345        row {
1346            style: row_style
1347            row {
1348                bind_style: icon_btn_style
1349                role: A11yRole::Button
1350                a11y_label: BTN_SEARCH_A11Y.to_string()
1351                on_click: on_open_cmd
1352                canvas {
1353                    style: canvas_style
1354                    caching: CanvasCaching::RetainedStatic
1355                    painter: paint_search
1356                }
1357            }
1358            row {
1359                node_ref: palette_btn
1360                bind_style: icon_btn_style
1361                role: A11yRole::Button
1362                a11y_label: BTN_SCHEME_A11Y.to_string()
1363                on_click: on_toggle_scheme
1364                canvas {
1365                    style: canvas_style
1366                    caching: CanvasCaching::RetainedStatic
1367                    painter: paint_palette
1368                }
1369            }
1370            row {
1371                bind_style: icon_btn_style
1372                role: A11yRole::Button
1373                a11y_label: BTN_MODE_A11Y.to_string()
1374                on_click: on_toggle_mode
1375                canvas {
1376                    style: canvas_style
1377                    caching: CanvasCaching::RetainedStatic
1378                    painter: paint_mode
1379                }
1380            }
1381            if include_settings {
1382                row {
1383                    bind_style: icon_btn_style
1384                    role: A11yRole::Button
1385                    a11y_label: BTN_SETTINGS_A11Y.to_string()
1386                    on_click: on_open_settings
1387                    canvas {
1388                        style: canvas_style
1389                        caching: CanvasCaching::RetainedStatic
1390                        painter: paint_settings
1391                    }
1392                }
1393            }
1394        }
1395    };
1396    (cluster, palette_btn)
1397}