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