Skip to main content

euv_example/pages/settings/
fn.rs

1use super::*;
2
3/// Mounts the Appearance & Theme customization card containing the 17 design schemes, mode selector, and semantic contrast preview.
4///
5/// # Arguments
6///
7/// - `&ShowcaseState` - Shared reactive showcase state.
8/// - `ThemeTokens` - Active design tokens.
9///
10/// # Returns
11///
12/// - `NodeId` - Mounted appearance card node.
13pub(crate) fn mount_settings_appearance_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
14    let p: ThemePalette = tokens.get_palette();
15    let scheme_sig: Signal<DesignScheme> = state.get_theme().get_scheme();
16    let mode_sig: Signal<ThemeMode> = state.get_theme().get_mode();
17    let initial_mode_idx: usize = match mode_sig.get_untracked() {
18        ThemeMode::Light => 0,
19        ThemeMode::Dark => 1,
20    };
21    let mode_sel_sig: Signal<usize> = Signal::new(initial_mode_idx);
22    let (mode_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
23        Effect::new(move || {
24            let sel: usize = mode_sel_sig.get();
25            if sel == 0 {
26                let _: bool = mode_sig.set_if_changed(ThemeMode::Light);
27            } else if sel == 1 {
28                let _: bool = mode_sig.set_if_changed(ThemeMode::Dark);
29            } else {
30                let sys: ThemeMode = use_system_theme().get();
31                let _: bool = mode_sig.set_if_changed(sys);
32            }
33        })
34    });
35    let mode_options: Vec<String> = vec![
36        MODE_LIGHT_STR.to_string(),
37        MODE_DARK_STR.to_string(),
38        MODE_SYSTEM_STR.to_string(),
39    ];
40    let mode_segmented_node: NodeId = view! {
41        EuvSegmented {
42            options: mode_options
43            selected: mode_sel_sig
44            tokens: tokens
45        }
46    };
47    let scheme_open_sig: Signal<bool> = Signal::new(false);
48    let scheme_hov_sig: Signal<Option<usize>> = Signal::new(None);
49    let all_schemes: [DesignScheme; 17] = DesignScheme::all();
50    let init_tok: ThemeTokens = live_tokens_untracked(tokens);
51    let init_g: ThemeGeometry = init_tok.get_geometry();
52    let menu_r: f32 = init_g.get_radius_lg();
53    let item_r: f32 = concentric_radius(menu_r, CONTROL_INSET);
54    let on_toggle_scheme_select = move |_: &UiEvent| {
55        let _: bool = scheme_open_sig.update(|v: &mut bool| *v = !*v);
56    };
57    let trigger_style = move || -> Style {
58        let live: ThemeTokens = use_live_tokens(tokens);
59        let live_p: ThemePalette = live.get_palette();
60        let live_g: ThemeGeometry = live.get_geometry();
61        let bg_s: SurfaceColors = live_p.surface(SurfaceRole::Background);
62        Style::default()
63            .row()
64            .width(Length::Percent(100.0))
65            .height(Length::Px(live_g.get_control_md()))
66            .padding(Edges::symmetric(0.0, SPACE_MD))
67            .justify(JustifyContent::SpaceBetween)
68            .align(AlignItems::Center)
69            .gap(SPACE_SM)
70            .background(bg_s.get_bg())
71            .border(live_g.get_border_width(), bg_s.get_border())
72            .radius(live_g.get_radius_md())
73            .overflow(Overflow::Hidden)
74            .cursor(CursorIcon::Pointer)
75    };
76    let trigger_dot_style = move || -> Style {
77        let cur: DesignScheme = scheme_sig.get();
78        let mode: ThemeMode = mode_sig.get();
79        let preview: ThemePalette = ThemeTokens::resolve(cur, mode).get_palette();
80        let live_p: ThemePalette = use_live_tokens(tokens).get_palette();
81        Style::default()
82            .width(Length::Px(12.0))
83            .height(Length::Px(12.0))
84            .flex_shrink(0.0)
85            .background(preview.get_primary())
86            .border(1.0, live_p.get_border())
87            .radius(PILL_RADIUS)
88    };
89    let trigger_label_style = move || -> Style {
90        let live_p: ThemePalette = use_live_tokens(tokens).get_palette();
91        Style::default()
92            .flex_grow(1.0)
93            .flex_shrink(1.0)
94            .min_width(Length::Px(0.0))
95            .font_size(13.5)
96            .font_weight(FontWeight::Medium)
97            .color(live_p.surface(SurfaceRole::Background).get_fg())
98            .overflow(Overflow::Hidden)
99            .text_overflow(TextOverflow::Ellipsis)
100    };
101    let trigger_label_text = move || -> String {
102        let cur: DesignScheme = scheme_sig.get();
103        scheme_display_label(cur).to_string()
104    };
105    let paint_select_chevron = move |bounds: Rect, dl: &mut DisplayList| {
106        let chevron_color: Color = live_tokens_untracked(tokens)
107            .get_palette()
108            .get_muted_foreground();
109        let cx: f32 = bounds.get_x() + bounds.get_width() * 0.5;
110        let cy: f32 = bounds.get_y() + bounds.get_height() * 0.5;
111        dl.push(DrawCommand::Line {
112            from: Point::new(cx - 4.0, cy - 2.0),
113            to: Point::new(cx, cy + 2.5),
114            color: chevron_color,
115            width: 1.6,
116        });
117        dl.push(DrawCommand::Line {
118            from: Point::new(cx, cy + 2.5),
119            to: Point::new(cx + 4.0, cy - 2.0),
120            color: chevron_color,
121            width: 1.6,
122        });
123    };
124    let mut scheme_check_canvases: Vec<NodeId> = Vec::with_capacity(all_schemes.len());
125    let scheme_option_nodes: Vec<NodeId> = all_schemes
126        .into_iter()
127        .enumerate()
128        .map(|(idx, scheme): (usize, DesignScheme)| {
129            let lbl_str: &'static str = scheme_display_label(scheme);
130            let on_pick = move |_: &UiEvent| {
131                let _: bool = scheme_sig.set_if_changed(scheme);
132                let _: bool = scheme_open_sig.set_if_changed(false);
133            };
134            let on_enter = move |_: &UiEvent| {
135                let _: bool = scheme_hov_sig.set_if_changed(Some(idx));
136            };
137            let on_leave = move |_: &UiEvent| {
138                if scheme_hov_sig.get_untracked() == Some(idx) {
139                    let _: bool = scheme_hov_sig.set_if_changed(None);
140                }
141            };
142            let opt_style = move || -> Style {
143                let live: ThemeTokens = use_live_tokens(tokens);
144                let live_p: ThemePalette = live.get_palette();
145                let active: bool = scheme_sig.get() == scheme;
146                let hovered: bool = scheme_hov_sig.get() == Some(idx);
147                let bg: Color = if active {
148                    live_p.surface(SurfaceRole::Primary).get_bg()
149                } else if hovered {
150                    live_p.surface(SurfaceRole::Accent).get_bg()
151                } else {
152                    COLOR_TRANSPARENT
153                };
154                Style::default()
155                    .row()
156                    .width(Length::Percent(100.0))
157                    .height(Length::Px(live.get_geometry().get_control_sm()))
158                    .padding(Edges::symmetric(0.0, SPACE_SM))
159                    .align(AlignItems::Center)
160                    .gap(SPACE_SM)
161                    .overflow(Overflow::Hidden)
162                    .background(bg)
163                    .radius(item_r)
164                    .cursor(CursorIcon::Pointer)
165            };
166            let dot_style = move || -> Style {
167                let mode: ThemeMode = mode_sig.get();
168                let preview: ThemePalette = ThemeTokens::resolve(scheme, mode).get_palette();
169                let live_p: ThemePalette = use_live_tokens(tokens).get_palette();
170                let active: bool = scheme_sig.get() == scheme;
171                let border_c: Color = if active {
172                    live_p
173                        .surface(SurfaceRole::Primary)
174                        .get_fg()
175                        .with_alpha(160)
176                } else {
177                    live_p.get_border()
178                };
179                Style::default()
180                    .width(Length::Px(12.0))
181                    .height(Length::Px(12.0))
182                    .flex_shrink(0.0)
183                    .background(preview.get_primary())
184                    .border(1.0, border_c)
185                    .radius(PILL_RADIUS)
186            };
187            let lbl_style = move || -> Style {
188                let live_p: ThemePalette = use_live_tokens(tokens).get_palette();
189                let active: bool = scheme_sig.get() == scheme;
190                let hovered: bool = scheme_hov_sig.get() == Some(idx);
191                let fg: Color = if active {
192                    live_p.surface(SurfaceRole::Primary).get_fg()
193                } else if hovered {
194                    live_p.surface(SurfaceRole::Accent).get_fg()
195                } else {
196                    live_p.surface(SurfaceRole::Card).get_fg()
197                };
198                Style::default()
199                    .flex_grow(1.0)
200                    .flex_shrink(1.0)
201                    .min_width(Length::Px(0.0))
202                    .font_size(13.0)
203                    .font_weight(if active {
204                        FontWeight::SemiBold
205                    } else {
206                        FontWeight::Normal
207                    })
208                    .color(fg)
209                    .overflow(Overflow::Hidden)
210                    .text_overflow(TextOverflow::Ellipsis)
211            };
212            let paint_chk = move |bounds: Rect, dl: &mut DisplayList| {
213                if scheme_sig.get_untracked() == scheme {
214                    let lp: ThemePalette = live_tokens_untracked(tokens).get_palette();
215                    let fg: Color = lp.surface(SurfaceRole::Primary).get_fg();
216                    draw_euv_icon(EuvIconName::Check, bounds, dl, fg);
217                }
218            };
219            let mut chk_id: NodeId = NodeId::default();
220            let row_node: NodeId = view! {
221                row {
222                    bind_style: opt_style
223                    role: A11yRole::MenuItem
224                    a11y_label: lbl_str.to_string()
225                    on_click: on_pick
226                    on_pointer_enter: on_enter
227                    on_pointer_leave: on_leave
228                    view {
229                        bind_style: dot_style
230                    }
231                    text {
232                        bind_style: lbl_style
233                        { lbl_str }
234                    }
235                    canvas {
236                        node_ref: chk_id
237                        style: {
238                            width: Length::Px(13.0)
239                            height: Length::Px(13.0)
240                            flex_shrink: 0.0
241                        }
242                        painter: paint_chk
243                    }
244                }
245            };
246            scheme_check_canvases.push(chk_id);
247            row_node
248        })
249        .collect();
250    let menu_wrap_style = move || -> Style {
251        let live: ThemeTokens = use_live_tokens(tokens);
252        let live_p: ThemePalette = live.get_palette();
253        let live_g: ThemeGeometry = live.get_geometry();
254        let card_s: SurfaceColors = live_p.surface(SurfaceRole::Card);
255        let is_open: bool = scheme_open_sig.get();
256        Style::default()
257            .column()
258            .display(if is_open {
259                Display::Flex
260            } else {
261                Display::None
262            })
263            .pointer_events(if is_open {
264                PointerEvents::Auto
265            } else {
266                PointerEvents::None
267            })
268            .width(Length::Percent(100.0))
269            .padding(Edges::all(CONTROL_INSET))
270            .background(card_s.get_bg())
271            .border(live_g.get_border_width(), card_s.get_border())
272            .radius(live_g.get_radius_lg())
273            .shadow(live_g.get_shadow_md())
274            .overflow(Overflow::Hidden)
275            .z_index(Z_INDEX_FLOATING)
276    };
277    let mut scheme_select_trigger: NodeId = NodeId::default();
278    let scheme_dropdown_node: NodeId = view! {
279        column {
280            style: {
281                width: Length::Percent(100.0)
282                gap: SPACE_XS
283            }
284            row {
285                node_ref: scheme_select_trigger
286                bind_style: trigger_style
287                role: A11yRole::Button
288                a11y_label: SETTINGS_SCHEME_SELECT_A11Y.to_string()
289                on_click: on_toggle_scheme_select
290                row {
291                    style: {
292                        flex_grow: 1.0
293                        flex_shrink: 1.0
294                        min_width: Length::Px(0.0)
295                        align: AlignItems::Center
296                        gap: SPACE_SM
297                        overflow: Overflow::Hidden
298                    }
299                    view {
300                        bind_style: trigger_dot_style
301                    }
302                    text {
303                        bind_style: trigger_label_style
304                        { trigger_label_text }
305                    }
306                }
307                canvas {
308                    style: {
309                        width: Length::Px(12.0)
310                        height: Length::Px(12.0)
311                        flex_shrink: 0.0
312                    }
313                    caching: CanvasCaching::RetainedStatic
314                    painter: paint_select_chevron
315                }
316            }
317            column {
318                bind_style: menu_wrap_style
319                role: A11yRole::Menu
320                a11y_label: SETTINGS_SCHEME_SELECT_A11Y.to_string()
321                scroll {
322                    style: {
323                        Style::default().column()
324                        width: Length::Percent(100.0)
325                        height: Length::Px(SETTINGS_SCHEME_MENU_MAX_H)
326                        max_height: Length::Px(SETTINGS_SCHEME_MENU_MAX_H)
327                        gap: CONTROL_INSET
328                    }
329                    ..scheme_option_nodes
330                }
331            }
332        }
333    };
334    let s_ctx: Context = current_context();
335    let sc_chk: SceneHandle = s_ctx.get_scene().clone();
336    let (scheme_dd_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
337        let _: Effect = EuvOverlayStack::bind_signal(
338            scheme_open_sig,
339            SETTINGS_SCHEME_OVERLAY_NAME,
340            Z_INDEX_DRAWER - 10,
341        );
342        Effect::new(move || {
343            let _: DesignScheme = scheme_sig.get();
344            let _: ThemeTokens = use_live_tokens(tokens);
345            sc_chk.with_write(
346                |tree: &mut SceneTree| {
347                    for &cid in scheme_check_canvases.iter() {
348                        tree.mark_dirty(cid, DIRTY_PAINT);
349                    }
350                },
351                (),
352            );
353        })
354    });
355    let mut s_ctx_key: Context = current_context();
356    s_ctx_key.on_key(scheme_select_trigger, move |ev: &UiEvent| {
357        let is_esc: bool = matches!(ev.get_kind(), UiEventKind::KeyDown(KeyCode::Escape, _))
358            || matches!(ev.get_kind(), UiEventKind::KeyDown(KeyCode::Back, _));
359        if is_esc && scheme_open_sig.get_untracked() {
360            let _: bool = scheme_open_sig.set_if_changed(false);
361        }
362    });
363    s_ctx.get_scene().with_write(
364        |tree: &mut SceneTree| {
365            tree.attach_scope(scheme_dropdown_node, scheme_dd_scope);
366        },
367        (),
368    );
369    let contrast_sample_style = move || -> Style {
370        let live: ThemeTokens = use_live_tokens(tokens);
371        let live_p: ThemePalette = live.get_palette();
372        let live_g: ThemeGeometry = live.get_geometry();
373        Style::default()
374            .column()
375            .width(Length::Percent(100.0))
376            .padding(Edges::all(SPACE_MD))
377            .gap(SPACE_XS)
378            .background(live_p.get_background())
379            .border(live_g.get_border_width(), live_p.get_border())
380            .radius(live_g.get_radius_md())
381            .overflow(Overflow::Hidden)
382    };
383    let contrast_head_style = move || -> Style {
384        let live: ThemeTokens = use_live_tokens(tokens);
385        Style::default()
386            .width(Length::Percent(100.0))
387            .font_size(13.0)
388            .font_weight(FontWeight::SemiBold)
389            .color(live.get_palette().get_foreground())
390    };
391    let contrast_body_style = move || -> Style {
392        let live: ThemeTokens = use_live_tokens(tokens);
393        Style::default()
394            .width(Length::Percent(100.0))
395            .font_size(12.0)
396            .color(live.get_palette().get_muted_foreground())
397    };
398    let card_node: NodeId = view! {
399        EuvCard {
400            title: SETTINGS_APPEARANCE_TITLE.to_string()
401            tokens: tokens
402            subtitle: SETTINGS_APPEARANCE_SUB
403            column {
404                style: {
405                    width: Length::Percent(100.0)
406                    gap: SPACE_SM
407                }
408                text {
409                    style: {
410                        width: Length::Percent(100.0)
411                        font_size: 13.5
412                        font_weight: FontWeight::SemiBold
413                        color: p.get_foreground()
414                    }
415                    { SETTINGS_MODE_HEADING }
416                }
417                text {
418                    style: {
419                        width: Length::Percent(100.0)
420                        font_size: 12.0
421                        color: p.get_muted_foreground()
422                    }
423                    { SETTINGS_MODE_SUB }
424                }
425                { mode_segmented_node }
426            }
427            column {
428                style: {
429                    width: Length::Percent(100.0)
430                    gap: SPACE_SM
431                }
432                text {
433                    style: {
434                        width: Length::Percent(100.0)
435                        font_size: 13.5
436                        font_weight: FontWeight::SemiBold
437                        color: p.get_foreground()
438                    }
439                    { SETTINGS_SCHEME_HEADING }
440                }
441                text {
442                    style: {
443                        width: Length::Percent(100.0)
444                        font_size: 12.0
445                        color: p.get_muted_foreground()
446                    }
447                    { SETTINGS_SCHEME_SUB }
448                }
449                { scheme_dropdown_node }
450            }
451            column {
452                style: {
453                    width: Length::Percent(100.0)
454                    gap: SPACE_SM
455                }
456                text {
457                    style: {
458                        width: Length::Percent(100.0)
459                        font_size: 13.5
460                        font_weight: FontWeight::SemiBold
461                        color: p.get_foreground()
462                    }
463                    { SETTINGS_CONTRAST_TITLE }
464                }
465                text {
466                    style: {
467                        width: Length::Percent(100.0)
468                        font_size: 12.0
469                        color: p.get_muted_foreground()
470                    }
471                    { SETTINGS_CONTRAST_SUB }
472                }
473                view {
474                    bind_style: contrast_sample_style
475                    text {
476                        bind_style: contrast_head_style
477                        { SETTINGS_CONTRAST_SAMPLE_HEAD }
478                    }
479                    text {
480                        bind_style: contrast_body_style
481                        { SETTINGS_CONTRAST_SAMPLE_BODY }
482                    }
483                }
484                row {
485                    style: {
486                        width: Length::Percent(100.0)
487                        flex_wrap: FlexWrap::Wrap
488                        gap: SPACE_SM
489                    }
490                    EuvBadge {
491                        label: SETTINGS_BADGE_PREVIEW_PRIMARY.to_string()
492                        tone: EuvTone::Primary
493                        tokens: tokens
494                    }
495                    EuvBadge {
496                        label: SETTINGS_BADGE_PREVIEW_SUCCESS.to_string()
497                        tone: EuvTone::Success
498                        tokens: tokens
499                    }
500                    EuvBadge {
501                        label: SETTINGS_BADGE_PREVIEW_WARNING.to_string()
502                        tone: EuvTone::Warning
503                        tokens: tokens
504                    }
505                    EuvBadge {
506                        label: SETTINGS_BADGE_PREVIEW_DANGER.to_string()
507                        tone: EuvTone::Destructive
508                        tokens: tokens
509                    }
510                }
511                EuvActionRow {
512                    EuvButton {
513                        label: SETTINGS_BTN_PREVIEW_PRI.to_string()
514                        tokens: tokens
515                        sm()
516                    }
517                    EuvButton {
518                        label: SETTINGS_BTN_PREVIEW_SEC.to_string()
519                        tokens: tokens
520                        secondary()
521                        sm()
522                    }
523                    EuvButton {
524                        label: SETTINGS_BTN_PREVIEW_OUT.to_string()
525                        tokens: tokens
526                        outline()
527                        sm()
528                    }
529                }
530            }
531        }
532    };
533    let ctx: Context = current_context();
534    ctx.get_scene().with_write(
535        |tree: &mut SceneTree| {
536            tree.attach_scope(card_node, mode_scope);
537        },
538        (),
539    );
540    card_node
541}
542
543/// Mounts the Navigation & Chrome toggles card for auto-hiding toolbars, live FPS pill, and horizontal swipe routing.
544///
545/// # Arguments
546///
547/// - `&ShowcaseState` - Shared reactive showcase state.
548/// - `ThemeTokens` - Active design tokens.
549///
550/// # Returns
551///
552/// - `NodeId` - Mounted chrome settings card node.
553pub(crate) fn mount_settings_chrome_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
554    let p: ThemePalette = tokens.get_palette();
555    let auto_hide_sig: Signal<bool> = state.get_auto_hide_chrome();
556    let show_fps_sig: Signal<bool> = state.get_show_fps_hud();
557    let swipe_sig: Signal<bool> = state.get_swipe_routing();
558    view! {
559        EuvCard {
560            title: SETTINGS_NAV_TITLE.to_string()
561            tokens: tokens
562            subtitle: SETTINGS_NAV_SUB
563            column {
564                style: {
565                    width: Length::Percent(100.0)
566                    gap: SPACE_SM
567                }
568                EuvSwitch {
569                    checked: auto_hide_sig
570                    label: SETTINGS_AUTO_HIDE_LABEL.to_string()
571                    tokens: tokens
572                }
573                text {
574                    style: {
575                        width: Length::Percent(100.0)
576                        font_size: 12.0
577                        color: p.get_muted_foreground()
578                    }
579                    { SETTINGS_AUTO_HIDE_DESC }
580                }
581            }
582            column {
583                style: {
584                    width: Length::Percent(100.0)
585                    gap: SPACE_SM
586                }
587                EuvSwitch {
588                    checked: show_fps_sig
589                    label: SETTINGS_SHOW_FPS_LABEL.to_string()
590                    tokens: tokens
591                }
592                text {
593                    style: {
594                        width: Length::Percent(100.0)
595                        font_size: 12.0
596                        color: p.get_muted_foreground()
597                    }
598                    { SETTINGS_SHOW_FPS_DESC }
599                }
600            }
601            column {
602                style: {
603                    width: Length::Percent(100.0)
604                    gap: SPACE_SM
605                }
606                EuvSwitch {
607                    checked: swipe_sig
608                    label: SETTINGS_SWIPE_ROUTING_LABEL.to_string()
609                    tokens: tokens
610                }
611                text {
612                    style: {
613                        width: Length::Percent(100.0)
614                        font_size: 12.0
615                        color: p.get_muted_foreground()
616                    }
617                    { SETTINGS_SWIPE_ROUTING_DESC }
618                }
619            }
620        }
621    }
622}
623
624/// Mounts the Motion & Accessibility card covering reduced motion preference and global animation timing standards.
625///
626/// # Arguments
627///
628/// - `&ShowcaseState` - Shared reactive showcase state.
629/// - `ThemeTokens` - Active design tokens.
630///
631/// # Returns
632///
633/// - `NodeId` - Mounted motion & accessibility card node.
634pub(crate) fn mount_settings_motion_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
635    let p: ThemePalette = tokens.get_palette();
636    let g: ThemeGeometry = tokens.get_geometry();
637    let reduced_motion_sig: Signal<bool> = state.get_reduced_motion();
638    view! {
639        EuvCard {
640            title: SETTINGS_MOTION_TITLE.to_string()
641            tokens: tokens
642            subtitle: SETTINGS_MOTION_SUB
643            column {
644                style: {
645                    width: Length::Percent(100.0)
646                    gap: SPACE_SM
647                }
648                EuvSwitch {
649                    checked: reduced_motion_sig
650                    label: SETTINGS_REDUCED_MOTION_LABEL.to_string()
651                    tokens: tokens
652                }
653                text {
654                    style: {
655                        width: Length::Percent(100.0)
656                        font_size: 12.0
657                        color: p.get_muted_foreground()
658                    }
659                    { SETTINGS_REDUCED_MOTION_DESC }
660                }
661            }
662            column {
663                style: {
664                    width: Length::Percent(100.0)
665                    gap: SPACE_SM
666                }
667                text {
668                    style: {
669                        width: Length::Percent(100.0)
670                        font_size: 13.5
671                        font_weight: FontWeight::SemiBold
672                        color: p.get_foreground()
673                    }
674                    { SETTINGS_MOTION_RHYTHM_TITLE }
675                }
676                column {
677                    style: {
678                        width: Length::Percent(100.0)
679                        padding: Edges::all(SPACE_MD)
680                        gap: SPACE_XS
681                        background: p.get_background()
682                        border: (g.get_border_width(), p.get_border())
683                        radius: g.get_radius_md()
684                        overflow: Overflow::Hidden
685                    }
686                    text {
687                        style: {
688                            width: Length::Percent(100.0)
689                            font_size: 12.5
690                            font_weight: FontWeight::SemiBold
691                            color: p.get_primary()
692                        }
693                        { SETTINGS_MOTION_MICRO_TITLE }
694                    }
695                    text {
696                        style: {
697                            width: Length::Percent(100.0)
698                            font_size: 12.0
699                            color: p.get_muted_foreground()
700                        }
701                        { SETTINGS_MOTION_MICRO_DESC }
702                    }
703                }
704                column {
705                    style: {
706                        width: Length::Percent(100.0)
707                        padding: Edges::all(SPACE_MD)
708                        gap: SPACE_XS
709                        background: p.get_background()
710                        border: (g.get_border_width(), p.get_border())
711                        radius: g.get_radius_md()
712                        overflow: Overflow::Hidden
713                    }
714                    text {
715                        style: {
716                            width: Length::Percent(100.0)
717                            font_size: 12.5
718                            font_weight: FontWeight::SemiBold
719                            color: p.get_primary()
720                        }
721                        { SETTINGS_MOTION_STD_TITLE }
722                    }
723                    text {
724                        style: {
725                            width: Length::Percent(100.0)
726                            font_size: 12.0
727                            color: p.get_muted_foreground()
728                        }
729                        { SETTINGS_MOTION_STD_DESC }
730                    }
731                }
732                column {
733                    style: {
734                        width: Length::Percent(100.0)
735                        padding: Edges::all(SPACE_MD)
736                        gap: SPACE_XS
737                        background: p.get_background()
738                        border: (g.get_border_width(), p.get_border())
739                        radius: g.get_radius_md()
740                        overflow: Overflow::Hidden
741                    }
742                    text {
743                        style: {
744                            width: Length::Percent(100.0)
745                            font_size: 12.5
746                            font_weight: FontWeight::SemiBold
747                            color: p.get_primary()
748                        }
749                        { SETTINGS_MOTION_EMPH_TITLE }
750                    }
751                    text {
752                        style: {
753                            width: Length::Percent(100.0)
754                            font_size: 12.0
755                            color: p.get_muted_foreground()
756                        }
757                        { SETTINGS_MOTION_EMPH_DESC }
758                    }
759                }
760                text {
761                    style: {
762                        width: Length::Percent(100.0)
763                        font_size: 11.5
764                        italic: true
765                        color: p.get_muted_foreground()
766                    }
767                    { SETTINGS_MOTION_EASING_NOTE }
768                }
769            }
770        }
771    }
772}
773
774/// Mounts the Runtime, Project & Defaults card displaying active platform capabilities, repository link, and reset action.
775///
776/// # Arguments
777///
778/// - `&ShowcaseState` - Shared reactive showcase state.
779/// - `Signal<String>` - Reactive action feedback readout.
780/// - `ThemeTokens` - Active design tokens.
781///
782/// # Returns
783///
784/// - `NodeId` - Mounted runtime diagnostics and actions card node.
785pub(crate) fn mount_settings_runtime_card(
786    state: &ShowcaseState,
787    action_log: Signal<String>,
788    tokens: ThemeTokens,
789) -> NodeId {
790    let p: ThemePalette = tokens.get_palette();
791    let g: ThemeGeometry = tokens.get_geometry();
792    let platform: PlatformKind = current_platform();
793    let vp_sig: Signal<Size> = use_viewport_size();
794    let safe_area_sig: Signal<SafeAreaInsets> = use_safe_area();
795    let state_reset: ShowcaseState = state.clone();
796    let platform_line: String = format!("{platform:?}");
797    let vp_line = move || -> String {
798        let vp: Size = vp_sig.get();
799        format!("{:.0}x{:.0} px", vp.get_width(), vp.get_height())
800    };
801    let sa_line = move || -> String {
802        let sa: SafeAreaInsets = safe_area_sig.get();
803        format!(
804            "T{:.0} R{:.0} B{:.0} L{:.0}",
805            sa.get_top(),
806            sa.get_right(),
807            sa.get_bottom(),
808            sa.get_left()
809        )
810    };
811    let action_log_text = move || -> String { action_log.get() };
812    let on_open_github = move |_: &UiEvent| {
813        let _: bool = open_external_url(PROJECT_GITHUB_URL);
814        let _: bool = action_log.set(SETTINGS_ACTION_LOG_GITHUB.to_string());
815    };
816    let on_reset_defaults = move |_: &UiEvent| {
817        state_reset.reset_preferences_to_defaults();
818        let _: bool = action_log.set(SETTINGS_ACTION_LOG_RESET.to_string());
819    };
820    view! {
821        EuvCard {
822            title: SETTINGS_RUNTIME_TITLE.to_string()
823            tokens: tokens
824            subtitle: SETTINGS_RUNTIME_SUB
825            grid {
826                style: {
827                    width: Length::Percent(100.0)
828                    columns: 2
829                    gap: SPACE_SM
830                }
831                column {
832                    style: {
833                        width: Length::Percent(100.0)
834                        padding: Edges::all(SPACE_SM)
835                        gap: SPACE_XS
836                        background: p.get_background()
837                        border: (g.get_border_width(), p.get_border())
838                        radius: g.get_radius_sm()
839                        overflow: Overflow::Hidden
840                    }
841                    text {
842                        style: {
843                            width: Length::Percent(100.0)
844                            font_size: 11.5
845                            color: p.get_muted_foreground()
846                        }
847                        { SETTINGS_KPI_PLATFORM }
848                    }
849                    text {
850                        style: {
851                            width: Length::Percent(100.0)
852                            font_size: 13.0
853                            font_weight: FontWeight::SemiBold
854                            color: p.get_foreground()
855                        }
856                        { platform_line }
857                    }
858                }
859                column {
860                    style: {
861                        width: Length::Percent(100.0)
862                        padding: Edges::all(SPACE_SM)
863                        gap: SPACE_XS
864                        background: p.get_background()
865                        border: (g.get_border_width(), p.get_border())
866                        radius: g.get_radius_sm()
867                        overflow: Overflow::Hidden
868                    }
869                    text {
870                        style: {
871                            width: Length::Percent(100.0)
872                            font_size: 11.5
873                            color: p.get_muted_foreground()
874                        }
875                        { SETTINGS_KPI_RENDERER }
876                    }
877                    text {
878                        style: {
879                            width: Length::Percent(100.0)
880                            font_size: 13.0
881                            font_weight: FontWeight::SemiBold
882                            color: p.get_foreground()
883                        }
884                        { SETTINGS_KPI_RENDERER_VAL }
885                    }
886                }
887                column {
888                    style: {
889                        width: Length::Percent(100.0)
890                        padding: Edges::all(SPACE_SM)
891                        gap: SPACE_XS
892                        background: p.get_background()
893                        border: (g.get_border_width(), p.get_border())
894                        radius: g.get_radius_sm()
895                        overflow: Overflow::Hidden
896                    }
897                    text {
898                        style: {
899                            width: Length::Percent(100.0)
900                            font_size: 11.5
901                            color: p.get_muted_foreground()
902                        }
903                        { SETTINGS_KPI_VIEWPORT }
904                    }
905                    text {
906                        style: {
907                            width: Length::Percent(100.0)
908                            font_size: 13.0
909                            font_weight: FontWeight::SemiBold
910                            color: p.get_foreground()
911                        }
912                        { vp_line }
913                    }
914                }
915                column {
916                    style: {
917                        width: Length::Percent(100.0)
918                        padding: Edges::all(SPACE_SM)
919                        gap: SPACE_XS
920                        background: p.get_background()
921                        border: (g.get_border_width(), p.get_border())
922                        radius: g.get_radius_sm()
923                        overflow: Overflow::Hidden
924                    }
925                    text {
926                        style: {
927                            width: Length::Percent(100.0)
928                            font_size: 11.5
929                            color: p.get_muted_foreground()
930                        }
931                        { SETTINGS_KPI_SAFE_AREA }
932                    }
933                    text {
934                        style: {
935                            width: Length::Percent(100.0)
936                            font_size: 13.0
937                            font_weight: FontWeight::SemiBold
938                            color: p.get_foreground()
939                        }
940                        { sa_line }
941                    }
942                }
943            }
944            EuvActionRow {
945                EuvButton {
946                    label: SETTINGS_BTN_GITHUB.to_string()
947                    tokens: tokens
948                    outline()
949                    sm()
950                    on_click: on_open_github
951                }
952                EuvButton {
953                    label: SETTINGS_BTN_RESET.to_string()
954                    tokens: tokens
955                    outline()
956                    sm()
957                    on_click: on_reset_defaults
958                }
959            }
960            text {
961                style: {
962                    width: Length::Percent(100.0)
963                    font_size: 12.0
964                    font_family: FontFamily::Monospace
965                    color: p.get_primary()
966                }
967                { action_log_text }
968            }
969        }
970    }
971}
972
973/// Mounts the Adaptive Rendering diagnostics and switch-mode control card on `/settings`.
974///
975/// # Arguments
976///
977/// - `&ShowcaseState` - Shared reactive showcase state.
978/// - `ThemeTokens` - Active design tokens.
979///
980/// # Returns
981///
982/// - `NodeId` - Mounted adaptive rendering card node.
983pub(crate) fn mount_settings_adaptive_render_card(
984    state: &ShowcaseState,
985    tokens: ThemeTokens,
986) -> NodeId {
987    let p: ThemePalette = tokens.get_palette();
988    let g: ThemeGeometry = tokens.get_geometry();
989    let auto_switch_sig: Signal<bool> = state.get_adaptive_auto_switch();
990    let active_backend_sig: Signal<String> = state.get_adaptive_active_backend();
991    let rec_backend_sig: Signal<String> = state.get_adaptive_recommended_backend();
992    let cpu_mirror_sig: Signal<bool> = state.get_adaptive_cpu_mirror_active();
993    let timing_src_sig: Signal<String> = state.get_adaptive_present_timing_source();
994    let upload_strat_sig: Signal<String> = state.get_adaptive_upload_strategy();
995    let attempts_sig: Signal<u64> = state.get_adaptive_handoff_attempts();
996    let successes_sig: Signal<u64> = state.get_adaptive_handoff_successes();
997    let aborts_sig: Signal<u64> = state.get_adaptive_handoff_aborts();
998    let init_idx: usize = if auto_switch_sig.get_untracked() {
999        1
1000    } else {
1001        0
1002    };
1003    let switch_sel_sig: Signal<usize> = Signal::new(init_idx);
1004    let (sync_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
1005        let _: Effect = Effect::new(move || {
1006            let expected: usize = if auto_switch_sig.get() { 1 } else { 0 };
1007            let _: bool = switch_sel_sig.set_if_changed(expected);
1008        });
1009        Effect::new(move || {
1010            let next_auto: bool = switch_sel_sig.get() == 1;
1011            let _: bool = auto_switch_sig.set_if_changed(next_auto);
1012        })
1013    });
1014    let switch_options: Vec<String> = vec![
1015        SETTINGS_ADAPTIVE_OPT_RECOMMEND.to_string(),
1016        SETTINGS_ADAPTIVE_OPT_AUTO.to_string(),
1017    ];
1018    let switch_segmented: NodeId = view! {
1019        EuvSegmented {
1020            options: switch_options
1021            selected: switch_sel_sig
1022            tokens: tokens
1023        }
1024    };
1025    let switch_mode_val = move || -> String {
1026        if auto_switch_sig.get() {
1027            SETTINGS_ADAPTIVE_OPT_AUTO.to_string()
1028        } else {
1029            SETTINGS_ADAPTIVE_OPT_RECOMMEND.to_string()
1030        }
1031    };
1032    let active_backend_val = move || -> String { active_backend_sig.get() };
1033    let rec_backend_val = move || -> String { rec_backend_sig.get() };
1034    let cpu_mirror_val = move || -> String {
1035        if cpu_mirror_sig.get() {
1036            SETTINGS_ADAPTIVE_MIRROR_YES.to_string()
1037        } else {
1038            SETTINGS_ADAPTIVE_MIRROR_NO.to_string()
1039        }
1040    };
1041    let timing_src_val = move || -> String { timing_src_sig.get() };
1042    let upload_strat_val = move || -> String { upload_strat_sig.get() };
1043    let handoffs_val = move || -> String {
1044        format!(
1045            "{} / {} / {}",
1046            attempts_sig.get(),
1047            successes_sig.get(),
1048            aborts_sig.get()
1049        )
1050    };
1051    let card_node: NodeId = view! {
1052        EuvCard {
1053            title: SETTINGS_ADAPTIVE_TITLE.to_string()
1054            tokens: tokens
1055            subtitle: SETTINGS_ADAPTIVE_SUB
1056            column {
1057                style: {
1058                    width: Length::Percent(100.0)
1059                    gap: SPACE_SM
1060                }
1061                text {
1062                    style: {
1063                        width: Length::Percent(100.0)
1064                        font_size: 13.5
1065                        font_weight: FontWeight::SemiBold
1066                        color: p.get_foreground()
1067                    }
1068                    { SETTINGS_ADAPTIVE_MODE_HEADING }
1069                }
1070                text {
1071                    style: {
1072                        width: Length::Percent(100.0)
1073                        font_size: 12.0
1074                        color: p.get_muted_foreground()
1075                    }
1076                    { SETTINGS_ADAPTIVE_MODE_SUB }
1077                }
1078                { switch_segmented }
1079            }
1080            grid {
1081                style: {
1082                    width: Length::Percent(100.0)
1083                    columns: 2
1084                    gap: SPACE_SM
1085                }
1086                column {
1087                    style: {
1088                        width: Length::Percent(100.0)
1089                        padding: Edges::all(SPACE_SM)
1090                        gap: SPACE_XS
1091                        background: p.get_background()
1092                        border: (g.get_border_width(), p.get_border())
1093                        radius: g.get_radius_sm()
1094                        overflow: Overflow::Hidden
1095                    }
1096                    text {
1097                        style: {
1098                            width: Length::Percent(100.0)
1099                            font_size: 11.5
1100                            color: p.get_muted_foreground()
1101                        }
1102                        { SETTINGS_ADAPTIVE_KPI_SWITCH_MODE }
1103                    }
1104                    text {
1105                        style: {
1106                            width: Length::Percent(100.0)
1107                            font_size: 13.0
1108                            font_weight: FontWeight::SemiBold
1109                            color: p.get_foreground()
1110                        }
1111                        { switch_mode_val }
1112                    }
1113                }
1114                column {
1115                    style: {
1116                        width: Length::Percent(100.0)
1117                        padding: Edges::all(SPACE_SM)
1118                        gap: SPACE_XS
1119                        background: p.get_background()
1120                        border: (g.get_border_width(), p.get_border())
1121                        radius: g.get_radius_sm()
1122                        overflow: Overflow::Hidden
1123                    }
1124                    text {
1125                        style: {
1126                            width: Length::Percent(100.0)
1127                            font_size: 11.5
1128                            color: p.get_muted_foreground()
1129                        }
1130                        { SETTINGS_ADAPTIVE_KPI_ACTIVE_BACKEND }
1131                    }
1132                    text {
1133                        style: {
1134                            width: Length::Percent(100.0)
1135                            font_size: 13.0
1136                            font_weight: FontWeight::SemiBold
1137                            color: p.get_foreground()
1138                        }
1139                        { active_backend_val }
1140                    }
1141                }
1142                column {
1143                    style: {
1144                        width: Length::Percent(100.0)
1145                        padding: Edges::all(SPACE_SM)
1146                        gap: SPACE_XS
1147                        background: p.get_background()
1148                        border: (g.get_border_width(), p.get_border())
1149                        radius: g.get_radius_sm()
1150                        overflow: Overflow::Hidden
1151                    }
1152                    text {
1153                        style: {
1154                            width: Length::Percent(100.0)
1155                            font_size: 11.5
1156                            color: p.get_muted_foreground()
1157                        }
1158                        { SETTINGS_ADAPTIVE_KPI_RECOMMENDED_BACKEND }
1159                    }
1160                    text {
1161                        style: {
1162                            width: Length::Percent(100.0)
1163                            font_size: 13.0
1164                            font_weight: FontWeight::SemiBold
1165                            color: p.get_foreground()
1166                        }
1167                        { rec_backend_val }
1168                    }
1169                }
1170                column {
1171                    style: {
1172                        width: Length::Percent(100.0)
1173                        padding: Edges::all(SPACE_SM)
1174                        gap: SPACE_XS
1175                        background: p.get_background()
1176                        border: (g.get_border_width(), p.get_border())
1177                        radius: g.get_radius_sm()
1178                        overflow: Overflow::Hidden
1179                    }
1180                    text {
1181                        style: {
1182                            width: Length::Percent(100.0)
1183                            font_size: 11.5
1184                            color: p.get_muted_foreground()
1185                        }
1186                        { SETTINGS_ADAPTIVE_KPI_CPU_MIRROR }
1187                    }
1188                    text {
1189                        style: {
1190                            width: Length::Percent(100.0)
1191                            font_size: 13.0
1192                            font_weight: FontWeight::SemiBold
1193                            color: p.get_foreground()
1194                        }
1195                        { cpu_mirror_val }
1196                    }
1197                }
1198                column {
1199                    style: {
1200                        width: Length::Percent(100.0)
1201                        padding: Edges::all(SPACE_SM)
1202                        gap: SPACE_XS
1203                        background: p.get_background()
1204                        border: (g.get_border_width(), p.get_border())
1205                        radius: g.get_radius_sm()
1206                        overflow: Overflow::Hidden
1207                    }
1208                    text {
1209                        style: {
1210                            width: Length::Percent(100.0)
1211                            font_size: 11.5
1212                            color: p.get_muted_foreground()
1213                        }
1214                        { SETTINGS_ADAPTIVE_KPI_TIMING_SOURCE }
1215                    }
1216                    text {
1217                        style: {
1218                            width: Length::Percent(100.0)
1219                            font_size: 13.0
1220                            font_weight: FontWeight::SemiBold
1221                            color: p.get_foreground()
1222                        }
1223                        { timing_src_val }
1224                    }
1225                }
1226                column {
1227                    style: {
1228                        width: Length::Percent(100.0)
1229                        padding: Edges::all(SPACE_SM)
1230                        gap: SPACE_XS
1231                        background: p.get_background()
1232                        border: (g.get_border_width(), p.get_border())
1233                        radius: g.get_radius_sm()
1234                        overflow: Overflow::Hidden
1235                    }
1236                    text {
1237                        style: {
1238                            width: Length::Percent(100.0)
1239                            font_size: 11.5
1240                            color: p.get_muted_foreground()
1241                        }
1242                        { SETTINGS_ADAPTIVE_KPI_UPLOAD_STRATEGY }
1243                    }
1244                    text {
1245                        style: {
1246                            width: Length::Percent(100.0)
1247                            font_size: 13.0
1248                            font_weight: FontWeight::SemiBold
1249                            color: p.get_foreground()
1250                        }
1251                        { upload_strat_val }
1252                    }
1253                }
1254                column {
1255                    style: {
1256                        width: Length::Percent(100.0)
1257                        padding: Edges::all(SPACE_SM)
1258                        gap: SPACE_XS
1259                        background: p.get_background()
1260                        border: (g.get_border_width(), p.get_border())
1261                        radius: g.get_radius_sm()
1262                        overflow: Overflow::Hidden
1263                    }
1264                    text {
1265                        style: {
1266                            width: Length::Percent(100.0)
1267                            font_size: 11.5
1268                            color: p.get_muted_foreground()
1269                        }
1270                        { SETTINGS_ADAPTIVE_KPI_HANDOFFS }
1271                    }
1272                    text {
1273                        style: {
1274                            width: Length::Percent(100.0)
1275                            font_size: 13.0
1276                            font_weight: FontWeight::SemiBold
1277                            color: p.get_foreground()
1278                        }
1279                        { handoffs_val }
1280                    }
1281                }
1282                column {
1283                    style: {
1284                        width: Length::Percent(100.0)
1285                        padding: Edges::all(SPACE_SM)
1286                        gap: SPACE_XS
1287                        background: p.get_background()
1288                        border: (g.get_border_width(), p.get_border())
1289                        radius: g.get_radius_sm()
1290                        overflow: Overflow::Hidden
1291                    }
1292                    text {
1293                        style: {
1294                            width: Length::Percent(100.0)
1295                            font_size: 11.5
1296                            color: p.get_muted_foreground()
1297                        }
1298                        { SETTINGS_ADAPTIVE_KPI_EQUIVALENCE }
1299                    }
1300                    text {
1301                        style: {
1302                            width: Length::Percent(100.0)
1303                            font_size: 13.0
1304                            font_weight: FontWeight::SemiBold
1305                            color: p.get_foreground()
1306                        }
1307                        { SETTINGS_ADAPTIVE_EQUIVALENCE_VAL }
1308                    }
1309                }
1310            }
1311        }
1312    };
1313    let ctx: Context = current_context();
1314    ctx.get_scene().with_write(
1315        |tree: &mut SceneTree| {
1316            tree.attach_scope(card_node, sync_scope);
1317        },
1318        (),
1319    );
1320    card_node
1321}
1322
1323/// Mounts the unified showcase `/settings` preferences page.
1324///
1325/// # Arguments
1326///
1327/// - `&ShowcaseState` - Reactive showcase state.
1328/// - `ThemeTokens` - Active resolved design tokens.
1329///
1330/// # Returns
1331///
1332/// - `NodeId` - Mounted settings page container handle.
1333pub fn mount_settings_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
1334    let action_log: Signal<String> = Signal::new(SETTINGS_ACTION_LOG_READY.to_string());
1335    let appearance_card: NodeId = mount_settings_appearance_card(state, tokens);
1336    let chrome_card: NodeId = mount_settings_chrome_card(state, tokens);
1337    let motion_card: NodeId = mount_settings_motion_card(state, tokens);
1338    let adaptive_card: NodeId = mount_settings_adaptive_render_card(state, tokens);
1339    let runtime_card: NodeId = mount_settings_runtime_card(state, action_log, tokens);
1340    let top_grid: NodeId = mount_responsive_grid(vec![chrome_card, motion_card], 2);
1341    view! {
1342        EuvPage {
1343            title: SETTINGS_TITLE.to_string()
1344            subtitle: SETTINGS_SUBTITLE.to_string()
1345            tokens: tokens
1346            { appearance_card }
1347            { top_grid }
1348            { adaptive_card }
1349            { runtime_card }
1350        }
1351    }
1352}