use super::*;
pub(crate) fn mount_settings_appearance_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
let palette: ThemePalette = tokens.get_palette();
let scheme_sig: Signal<DesignScheme> = state.get_theme().get_scheme();
let mode_sig: Signal<ThemeMode> = state.get_theme().get_mode();
let initial_mode_idx: usize = match mode_sig.get_untracked() {
ThemeMode::Light => 0,
ThemeMode::Dark => 1,
};
let mode_sel_sig: Signal<usize> = Signal::new(initial_mode_idx);
let (mode_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
Effect::new(move || {
let sel: usize = mode_sel_sig.get();
if sel == 0 {
let _: bool = mode_sig.set_if_changed(ThemeMode::Light);
} else if sel == 1 {
let _: bool = mode_sig.set_if_changed(ThemeMode::Dark);
} else {
let sys: ThemeMode = use_system_theme().get();
let _: bool = mode_sig.set_if_changed(sys);
}
})
});
let mode_options: Vec<String> = vec![
MODE_LIGHT_STR.to_string(),
MODE_DARK_STR.to_string(),
MODE_SYSTEM_STR.to_string(),
];
let mode_segmented_node: NodeId = view! {
EuvSegmented {
options: mode_options
selected: mode_sel_sig
tokens: tokens
}
};
let scheme_open_sig: Signal<bool> = Signal::new(false);
let scheme_hov_sig: Signal<Option<usize>> = Signal::new(None);
let all_schemes: [DesignScheme; 17] = DesignScheme::all();
let init_tok: ThemeTokens = live_tokens_untracked(tokens);
let init_g: ThemeGeometry = init_tok.get_geometry();
let menu_r: f32 = init_g.get_radius_lg();
let item_r: f32 = concentric_radius(menu_r, CONTROL_INSET);
let on_toggle_scheme_select = move |_: &UiEvent| {
let _: bool = scheme_open_sig.set(!scheme_open_sig.get_untracked());
};
let trigger_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
let live_p: ThemePalette = live.get_palette();
let live_g: ThemeGeometry = live.get_geometry();
let bg_s: SurfaceColors = live_p.surface(SurfaceRole::Background);
style! {
FlexDirection::Row
Width(Length::Percent(100.0))
Height(Length::Px(live_g.get_control_md()))
Padding(Edges::symmetric(0.0, SPACE_MD))
JustifyContent::SpaceBetween
AlignItems::Center
Gap(SPACE_SM)
Background(bg_s.get_bg())
Border::new(live_g.get_border_width(), bg_s.get_border())
Radius(live_g.get_radius_md())
Overflow::Hidden
CursorIcon::Pointer
}
};
let trigger_dot_style = move || -> Style {
let cur: DesignScheme = scheme_sig.get();
let mode: ThemeMode = mode_sig.get();
let preview: ThemePalette = ThemeTokens::resolve(cur, mode).get_palette();
let live_p: ThemePalette = use_live_tokens(tokens).get_palette();
style! {
Width(Length::Px(12.0))
Height(Length::Px(12.0))
FlexShrink(0.0)
Background(preview.get_primary())
Border::new(1.0, live_p.get_border())
Radius(PILL_RADIUS)
}
};
let trigger_label_style = move || -> Style {
let live_p: ThemePalette = use_live_tokens(tokens).get_palette();
style! {
FlexGrow(1.0)
FlexShrink(1.0)
MinWidth(Length::Px(0.0))
FontSize(13.5)
FontWeight::Medium
TextColor(live_p.surface(SurfaceRole::Background).get_fg())
Overflow::Hidden
TextOverflow::Ellipsis
}
};
let trigger_label_text = move || -> String {
let cur: DesignScheme = scheme_sig.get();
scheme_display_label(cur).to_string()
};
let paint_select_chevron = move |bounds: Rect, display_list: &mut DisplayList| {
let chevron_color: Color = live_tokens_untracked(tokens)
.get_palette()
.get_muted_foreground();
let cx: f32 = bounds.get_x() + bounds.get_width() * 0.5;
let cy: f32 = bounds.get_y() + bounds.get_height() * 0.5;
display_list.push(DrawCommand::Line {
from: Point::new(cx - 4.0, cy - 2.0),
to: Point::new(cx, cy + 2.5),
color: chevron_color,
width: 1.6,
});
display_list.push(DrawCommand::Line {
from: Point::new(cx, cy + 2.5),
to: Point::new(cx + 4.0, cy - 2.0),
color: chevron_color,
width: 1.6,
});
};
let mut scheme_check_canvases: Vec<NodeId> = Vec::with_capacity(all_schemes.len());
let scheme_option_nodes: Vec<NodeId> = all_schemes
.into_iter()
.enumerate()
.map(|(idx, scheme): (usize, DesignScheme)| {
let lbl_str: &'static str = scheme_display_label(scheme);
let on_pick = move |_: &UiEvent| {
let _: bool = scheme_sig.set_if_changed(scheme);
let _: bool = scheme_open_sig.set_if_changed(false);
};
let on_enter = move |_: &UiEvent| {
let _: bool = scheme_hov_sig.set_if_changed(Some(idx));
};
let on_leave = move |_: &UiEvent| {
if scheme_hov_sig.get_untracked() == Some(idx) {
let _: bool = scheme_hov_sig.set_if_changed(None);
}
};
let opt_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
let live_p: ThemePalette = live.get_palette();
let active: bool = scheme_sig.get() == scheme;
let hovered: bool = scheme_hov_sig.get() == Some(idx);
let bg: Color = if active {
live_p.surface(SurfaceRole::Primary).get_bg()
} else if hovered {
live_p.surface(SurfaceRole::Accent).get_bg()
} else {
COLOR_TRANSPARENT
};
style! {
FlexDirection::Row
Width(Length::Percent(100.0))
Height(Length::Px(live.get_geometry().get_control_sm()))
Padding(Edges::symmetric(0.0, SPACE_SM))
AlignItems::Center
Gap(SPACE_SM)
Overflow::Hidden
Background(bg)
Radius(item_r)
CursorIcon::Pointer
}
};
let dot_style = move || -> Style {
let mode: ThemeMode = mode_sig.get();
let preview: ThemePalette = ThemeTokens::resolve(scheme, mode).get_palette();
let live_p: ThemePalette = use_live_tokens(tokens).get_palette();
let active: bool = scheme_sig.get() == scheme;
let border_c: Color = if active {
live_p
.surface(SurfaceRole::Primary)
.get_fg()
.with_alpha(160)
} else {
live_p.get_border()
};
style! {
Width(Length::Px(12.0))
Height(Length::Px(12.0))
FlexShrink(0.0)
Background(preview.get_primary())
Border::new(1.0, border_c)
Radius(PILL_RADIUS)
}
};
let lbl_style = move || -> Style {
let live_p: ThemePalette = use_live_tokens(tokens).get_palette();
let active: bool = scheme_sig.get() == scheme;
let hovered: bool = scheme_hov_sig.get() == Some(idx);
let fg: Color = if active {
live_p.surface(SurfaceRole::Primary).get_fg()
} else if hovered {
live_p.surface(SurfaceRole::Accent).get_fg()
} else {
live_p.surface(SurfaceRole::Card).get_fg()
};
style! {
FlexGrow(1.0)
FlexShrink(1.0)
MinWidth(Length::Px(0.0))
FontSize(13.0)
if active {
FontWeight::SemiBold
} else {
FontWeight::Normal
}
TextColor(fg)
Overflow::Hidden
TextOverflow::Ellipsis
}
};
let paint_chk = move |bounds: Rect, draw_commands: &mut DisplayList| {
if scheme_sig.get_untracked() == scheme {
let lp: ThemePalette = live_tokens_untracked(tokens).get_palette();
let fg: Color = lp.surface(SurfaceRole::Primary).get_fg();
draw_euv_icon(EuvIconName::Check, bounds, draw_commands, fg);
}
};
let mut chk_id: NodeId = NodeId::default();
let canvas_secondary_style: Style = style! {
Width(Length::Px(13.0))
Height(Length::Px(13.0))
FlexShrink(0.0)
};
let row_node: NodeId = view! {
row {
bind_style: opt_style
role: A11yRole::MenuItem
a11y_label: lbl_str.to_string()
on_click: on_pick
on_pointer_enter: on_enter
on_pointer_leave: on_leave
view {
bind_style: dot_style
}
text {
bind_style: lbl_style
{ lbl_str }
}
canvas {
node_ref: chk_id
style: canvas_secondary_style
painter: paint_chk
}
}
};
scheme_check_canvases.push(chk_id);
row_node
})
.collect();
let menu_wrap_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
let live_p: ThemePalette = live.get_palette();
let live_g: ThemeGeometry = live.get_geometry();
let card_s: SurfaceColors = live_p.surface(SurfaceRole::Card);
let is_open: bool = scheme_open_sig.get();
style! {
FlexDirection::Column
if is_open {
Display::Flex
} else {
Display::None
}
if is_open {
PointerEvents::Auto
} else {
PointerEvents::None
}
Width(Length::Percent(100.0))
Padding(Edges::all(CONTROL_INSET))
Background(card_s.get_bg())
Border::new(live_g.get_border_width(), card_s.get_border())
Radius(live_g.get_radius_lg())
live_g.get_shadow_md()
Overflow::Hidden
ZIndex(Z_INDEX_FLOATING)
}
};
let mut scheme_select_trigger: NodeId = NodeId::default();
let column_ninth_style: Style = style! {
Width(Length::Percent(100.0))
Gap(SPACE_XS)
};
let row_secondary_style: Style = style! {
FlexGrow(1.0)
FlexShrink(1.0)
MinWidth(Length::Px(0.0))
AlignItems::Center
Gap(SPACE_SM)
Overflow::Hidden
};
let canvas_style: Style = style! {
Width(Length::Px(12.0))
Height(Length::Px(12.0))
FlexShrink(0.0)
};
let scroll_style: Style = style! {
FlexDirection::Column
Width(Length::Percent(100.0))
Height(Length::Px(SETTINGS_SCHEME_MENU_MAX_H))
MaxHeight(Length::Px(SETTINGS_SCHEME_MENU_MAX_H))
Gap(CONTROL_INSET)
};
let scheme_dropdown_node: NodeId = view! {
column {
style: column_ninth_style
row {
node_ref: scheme_select_trigger
bind_style: trigger_style
role: A11yRole::Button
a11y_label: SETTINGS_SCHEME_SELECT_A11Y.to_string()
on_click: on_toggle_scheme_select
row {
style: row_secondary_style
view {
bind_style: trigger_dot_style
}
text {
bind_style: trigger_label_style
{ trigger_label_text }
}
}
canvas {
style: canvas_style
caching: CanvasCaching::RetainedStatic
painter: paint_select_chevron
}
}
column {
bind_style: menu_wrap_style
role: A11yRole::Menu
a11y_label: SETTINGS_SCHEME_SELECT_A11Y.to_string()
scroll {
style: scroll_style
..scheme_option_nodes
}
}
}
};
let s_ctx: Context = current_context();
let sc_chk: SceneHandle = s_ctx.get_scene().clone();
let (scheme_dd_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
let _: Effect = EuvOverlayStack::bind_signal(
scheme_open_sig,
SETTINGS_SCHEME_OVERLAY_NAME,
Z_INDEX_DRAWER - 10,
);
Effect::new(move || {
let _: DesignScheme = scheme_sig.get();
let _: ThemeTokens = use_live_tokens(tokens);
sc_chk.with_write(
|tree: &mut SceneTree| {
for &cid in scheme_check_canvases.iter() {
tree.mark_dirty(cid, DIRTY_PAINT);
}
},
(),
);
})
});
let mut s_ctx_key: Context = current_context();
s_ctx_key.on_key(scheme_select_trigger, move |ui_event: &UiEvent| {
let is_esc: bool =
matches!(
ui_event.get_kind(),
UiEventKind::KeyDown(KeyCode::Escape, _)
) || matches!(ui_event.get_kind(), UiEventKind::KeyDown(KeyCode::Back, _));
if is_esc && scheme_open_sig.get_untracked() {
let _: bool = scheme_open_sig.set_if_changed(false);
}
});
s_ctx.get_scene().with_write(
|tree: &mut SceneTree| {
tree.attach_scope(scheme_dropdown_node, scheme_dd_scope);
},
(),
);
let contrast_sample_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
let live_p: ThemePalette = live.get_palette();
let live_g: ThemeGeometry = live.get_geometry();
style! {
FlexDirection::Column
Width(Length::Percent(100.0))
Padding(Edges::all(SPACE_MD))
Gap(SPACE_XS)
Background(live_p.get_background())
Border::new(live_g.get_border_width(), live_p.get_border())
Radius(live_g.get_radius_md())
Overflow::Hidden
}
};
let contrast_head_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
style! {
Width(Length::Percent(100.0))
FontSize(13.0)
FontWeight::SemiBold
TextColor(live.get_palette().get_foreground())
}
};
let contrast_body_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
style! {
Width(Length::Percent(100.0))
FontSize(12.0)
TextColor(live.get_palette().get_muted_foreground())
}
};
let column_eighth_style: Style = style! {
Width(Length::Percent(100.0))
Gap(SPACE_SM)
};
let text_fourteenth_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(13.5)
FontWeight::SemiBold
TextColor(palette.get_foreground())
};
let text_fifteenth_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(12.0)
TextColor(palette.get_muted_foreground())
};
let row_style: Style = style! {
Width(Length::Percent(100.0))
FlexWrap::Wrap
Gap(SPACE_SM)
};
let card_node: NodeId = view! {
EuvCard {
title: SETTINGS_APPEARANCE_TITLE.to_string()
tokens: tokens
subtitle: SETTINGS_APPEARANCE_SUB
column {
style: column_eighth_style
text {
style: text_fourteenth_style
{ SETTINGS_MODE_HEADING }
}
text {
style: text_fifteenth_style
{ SETTINGS_MODE_SUB }
}
{ mode_segmented_node }
}
column {
style: column_eighth_style
text {
style: text_fourteenth_style
{ SETTINGS_SCHEME_HEADING }
}
text {
style: text_fifteenth_style
{ SETTINGS_SCHEME_SUB }
}
{ scheme_dropdown_node }
}
column {
style: column_eighth_style
text {
style: text_fourteenth_style
{ SETTINGS_CONTRAST_TITLE }
}
text {
style: text_fifteenth_style
{ SETTINGS_CONTRAST_SUB }
}
view {
bind_style: contrast_sample_style
text {
bind_style: contrast_head_style
{ SETTINGS_CONTRAST_SAMPLE_HEAD }
}
text {
bind_style: contrast_body_style
{ SETTINGS_CONTRAST_SAMPLE_BODY }
}
}
row {
style: row_style
EuvBadge {
label: SETTINGS_BADGE_PREVIEW_PRIMARY.to_string()
tone: EuvTone::Primary
tokens: tokens
}
EuvBadge {
label: SETTINGS_BADGE_PREVIEW_SUCCESS.to_string()
tone: EuvTone::Success
tokens: tokens
}
EuvBadge {
label: SETTINGS_BADGE_PREVIEW_WARNING.to_string()
tone: EuvTone::Warning
tokens: tokens
}
EuvBadge {
label: SETTINGS_BADGE_PREVIEW_DANGER.to_string()
tone: EuvTone::Destructive
tokens: tokens
}
}
EuvActionRow {
EuvButton {
label: SETTINGS_BTN_PREVIEW_PRI.to_string()
tokens: tokens
small()
}
EuvButton {
label: SETTINGS_BTN_PREVIEW_SEC.to_string()
tokens: tokens
secondary()
small()
}
EuvButton {
label: SETTINGS_BTN_PREVIEW_OUT.to_string()
tokens: tokens
outline()
small()
}
}
}
}
};
let ctx: Context = current_context();
ctx.get_scene().with_write(
|tree: &mut SceneTree| {
tree.attach_scope(card_node, mode_scope);
},
(),
);
card_node
}
pub(crate) fn mount_settings_chrome_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
let palette: ThemePalette = tokens.get_palette();
let auto_hide_sig: Signal<bool> = state.get_auto_hide_chrome();
let show_fps_sig: Signal<bool> = state.get_show_fps_hud();
let swipe_sig: Signal<bool> = state.get_swipe_routing();
let column_seventh_style: Style = style! {
Width(Length::Percent(100.0))
Gap(SPACE_SM)
};
let text_thirteenth_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(12.0)
TextColor(palette.get_muted_foreground())
};
view! {
EuvCard {
title: SETTINGS_NAV_TITLE.to_string()
tokens: tokens
subtitle: SETTINGS_NAV_SUB
column {
style: column_seventh_style
EuvSwitch {
checked: auto_hide_sig
label: SETTINGS_AUTO_HIDE_LABEL.to_string()
tokens: tokens
}
text {
style: text_thirteenth_style
{ SETTINGS_AUTO_HIDE_DESC }
}
}
column {
style: column_seventh_style
EuvSwitch {
checked: show_fps_sig
label: SETTINGS_SHOW_FPS_LABEL.to_string()
tokens: tokens
}
text {
style: text_thirteenth_style
{ SETTINGS_SHOW_FPS_DESC }
}
}
column {
style: column_seventh_style
EuvSwitch {
checked: swipe_sig
label: SETTINGS_SWIPE_ROUTING_LABEL.to_string()
tokens: tokens
}
text {
style: text_thirteenth_style
{ SETTINGS_SWIPE_ROUTING_DESC }
}
}
}
}
}
pub(crate) fn mount_settings_motion_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
let palette: ThemePalette = tokens.get_palette();
let geometry: ThemeGeometry = tokens.get_geometry();
let reduced_motion_sig: Signal<bool> = state.get_reduced_motion();
let column_fifth_style: Style = style! {
Width(Length::Percent(100.0))
Gap(SPACE_SM)
};
let text_ninth_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(12.0)
TextColor(palette.get_muted_foreground())
};
let text_tenth_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(13.5)
FontWeight::SemiBold
TextColor(palette.get_foreground())
};
let column_sixth_style: Style = style! {
Width(Length::Percent(100.0))
Padding(Edges::all(SPACE_MD))
Gap(SPACE_XS)
Background(palette.get_background())
Border::new(geometry.get_border_width(), palette.get_border())
Radius(geometry.get_radius_md())
Overflow::Hidden
};
let text_eleventh_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(12.5)
FontWeight::SemiBold
TextColor(palette.get_primary())
};
let text_twelfth_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(11.5)
Italic(true)
TextColor(palette.get_muted_foreground())
};
view! {
EuvCard {
title: SETTINGS_MOTION_TITLE.to_string()
tokens: tokens
subtitle: SETTINGS_MOTION_SUB
column {
style: column_fifth_style
EuvSwitch {
checked: reduced_motion_sig
label: SETTINGS_REDUCED_MOTION_LABEL.to_string()
tokens: tokens
}
text {
style: text_ninth_style
{ SETTINGS_REDUCED_MOTION_DESC }
}
}
column {
style: column_fifth_style
text {
style: text_tenth_style
{ SETTINGS_MOTION_RHYTHM_TITLE }
}
column {
style: column_sixth_style
text {
style: text_eleventh_style
{ SETTINGS_MOTION_MICRO_TITLE }
}
text {
style: text_ninth_style
{ SETTINGS_MOTION_MICRO_DESC }
}
}
column {
style: column_sixth_style
text {
style: text_eleventh_style
{ SETTINGS_MOTION_STD_TITLE }
}
text {
style: text_ninth_style
{ SETTINGS_MOTION_STD_DESC }
}
}
column {
style: column_sixth_style
text {
style: text_eleventh_style
{ SETTINGS_MOTION_EMPH_TITLE }
}
text {
style: text_ninth_style
{ SETTINGS_MOTION_EMPH_DESC }
}
}
text {
style: text_twelfth_style
{ SETTINGS_MOTION_EASING_NOTE }
}
}
}
}
}
pub(crate) fn mount_settings_runtime_card(
state: &ShowcaseState,
action_log: Signal<String>,
tokens: ThemeTokens,
) -> NodeId {
let palette: ThemePalette = tokens.get_palette();
let geometry: ThemeGeometry = tokens.get_geometry();
let platform: PlatformKind = current_platform();
let vp_sig: Signal<Size> = use_viewport_size();
let safe_area_sig: Signal<SafeAreaInsets> = use_safe_area();
let state_reset: ShowcaseState = state.clone();
let platform_line: String = format!("{platform:?}");
let vp_line = move || -> String {
let box_size: Size = vp_sig.get();
format!(
"{:.0}x{:.0} px",
box_size.get_width(),
box_size.get_height()
)
};
let sa_line = move || -> String {
let sa: SafeAreaInsets = safe_area_sig.get();
format!(
"T{:.0} R{:.0} B{:.0} L{:.0}",
sa.get_top(),
sa.get_right(),
sa.get_bottom(),
sa.get_left()
)
};
let action_log_text = move || -> String { action_log.get() };
let on_open_github = move |_: &UiEvent| {
let _: bool = open_external_url(PROJECT_GITHUB_URL);
let _: bool = action_log.set(SETTINGS_ACTION_LOG_GITHUB.to_string());
};
let on_reset_defaults = move |_: &UiEvent| {
state_reset.reset_preferences_to_defaults();
let _: bool = action_log.set(SETTINGS_ACTION_LOG_RESET.to_string());
};
let grid_secondary_style: Style = style! {
Width(Length::Percent(100.0))
GridColumns(2)
Gap(SPACE_SM)
};
let column_quaternary_style: Style = style! {
Width(Length::Percent(100.0))
Padding(Edges::all(SPACE_SM))
Gap(SPACE_XS)
Background(palette.get_background())
Border::new(geometry.get_border_width(), palette.get_border())
Radius(geometry.get_radius_sm())
Overflow::Hidden
};
let text_sixth_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(11.5)
TextColor(palette.get_muted_foreground())
};
let text_seventh_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(13.0)
FontWeight::SemiBold
TextColor(palette.get_foreground())
};
let text_eighth_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(12.0)
FontFamily::Monospace
TextColor(palette.get_primary())
};
view! {
EuvCard {
title: SETTINGS_RUNTIME_TITLE.to_string()
tokens: tokens
subtitle: SETTINGS_RUNTIME_SUB
grid {
style: grid_secondary_style
column {
style: column_quaternary_style
text {
style: text_sixth_style
{ SETTINGS_KPI_PLATFORM }
}
text {
style: text_seventh_style
{ platform_line }
}
}
column {
style: column_quaternary_style
text {
style: text_sixth_style
{ SETTINGS_KPI_RENDERER }
}
text {
style: text_seventh_style
{ SETTINGS_KPI_RENDERER_VAL }
}
}
column {
style: column_quaternary_style
text {
style: text_sixth_style
{ SETTINGS_KPI_VIEWPORT }
}
text {
style: text_seventh_style
{ vp_line }
}
}
column {
style: column_quaternary_style
text {
style: text_sixth_style
{ SETTINGS_KPI_SAFE_AREA }
}
text {
style: text_seventh_style
{ sa_line }
}
}
}
EuvActionRow {
EuvButton {
label: SETTINGS_BTN_GITHUB.to_string()
tokens: tokens
outline()
small()
on_click: on_open_github
}
EuvButton {
label: SETTINGS_BTN_RESET.to_string()
tokens: tokens
outline()
small()
on_click: on_reset_defaults
}
}
text {
style: text_eighth_style
{ action_log_text }
}
}
}
}
pub(crate) fn mount_settings_adaptive_render_card(
state: &ShowcaseState,
tokens: ThemeTokens,
) -> NodeId {
let palette: ThemePalette = tokens.get_palette();
let geometry: ThemeGeometry = tokens.get_geometry();
let auto_switch_sig: Signal<bool> = state.get_adaptive_auto_switch();
let active_backend_sig: Signal<String> = state.get_adaptive_active_backend();
let rec_backend_sig: Signal<String> = state.get_adaptive_recommended_backend();
let cpu_mirror_sig: Signal<bool> = state.get_adaptive_cpu_mirror_active();
let timing_src_sig: Signal<String> = state.get_adaptive_present_timing_source();
let upload_strat_sig: Signal<String> = state.get_adaptive_upload_strategy();
let attempts_sig: Signal<u64> = state.get_adaptive_handoff_attempts();
let successes_sig: Signal<u64> = state.get_adaptive_handoff_successes();
let aborts_sig: Signal<u64> = state.get_adaptive_handoff_aborts();
let init_idx: usize = if auto_switch_sig.get_untracked() {
1
} else {
0
};
let switch_sel_sig: Signal<usize> = Signal::new(init_idx);
let (sync_scope, _): (Scope, Effect) = Scope::run(|_: Scope| {
let _: Effect = Effect::new(move || {
let expected: usize = if auto_switch_sig.get() { 1 } else { 0 };
let _: bool = switch_sel_sig.set_if_changed(expected);
});
Effect::new(move || {
let next_auto: bool = switch_sel_sig.get() == 1;
let _: bool = auto_switch_sig.set_if_changed(next_auto);
})
});
let switch_options: Vec<String> = vec![
SETTINGS_ADAPTIVE_OPT_RECOMMEND.to_string(),
SETTINGS_ADAPTIVE_OPT_AUTO.to_string(),
];
let switch_segmented: NodeId = view! {
EuvSegmented {
options: switch_options
selected: switch_sel_sig
tokens: tokens
}
};
let switch_mode_val = move || -> String {
if auto_switch_sig.get() {
SETTINGS_ADAPTIVE_OPT_AUTO.to_string()
} else {
SETTINGS_ADAPTIVE_OPT_RECOMMEND.to_string()
}
};
let active_backend_val = move || -> String { active_backend_sig.get() };
let rec_backend_val = move || -> String { rec_backend_sig.get() };
let cpu_mirror_val = move || -> String {
if cpu_mirror_sig.get() {
SETTINGS_ADAPTIVE_MIRROR_YES.to_string()
} else {
SETTINGS_ADAPTIVE_MIRROR_NO.to_string()
}
};
let timing_src_val = move || -> String { timing_src_sig.get() };
let upload_strat_val = move || -> String { upload_strat_sig.get() };
let handoffs_val = move || -> String {
format!(
"{} / {} / {}",
attempts_sig.get(),
successes_sig.get(),
aborts_sig.get()
)
};
let column_secondary_style: Style = style! {
Width(Length::Percent(100.0))
Gap(SPACE_SM)
};
let text_secondary_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(13.5)
FontWeight::SemiBold
TextColor(palette.get_foreground())
};
let text_tertiary_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(12.0)
TextColor(palette.get_muted_foreground())
};
let grid_style: Style = style! {
Width(Length::Percent(100.0))
GridColumns(2)
Gap(SPACE_SM)
};
let column_tertiary_style: Style = style! {
Width(Length::Percent(100.0))
Padding(Edges::all(SPACE_SM))
Gap(SPACE_XS)
Background(palette.get_background())
Border::new(geometry.get_border_width(), palette.get_border())
Radius(geometry.get_radius_sm())
Overflow::Hidden
};
let text_quaternary_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(11.5)
TextColor(palette.get_muted_foreground())
};
let text_fifth_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(13.0)
FontWeight::SemiBold
TextColor(palette.get_foreground())
};
let card_node: NodeId = view! {
EuvCard {
title: SETTINGS_ADAPTIVE_TITLE.to_string()
tokens: tokens
subtitle: SETTINGS_ADAPTIVE_SUB
column {
style: column_secondary_style
text {
style: text_secondary_style
{ SETTINGS_ADAPTIVE_MODE_HEADING }
}
text {
style: text_tertiary_style
{ SETTINGS_ADAPTIVE_MODE_SUB }
}
{ switch_segmented }
}
grid {
style: grid_style
column {
style: column_tertiary_style
text {
style: text_quaternary_style
{ SETTINGS_ADAPTIVE_KPI_SWITCH_MODE }
}
text {
style: text_fifth_style
{ switch_mode_val }
}
}
column {
style: column_tertiary_style
text {
style: text_quaternary_style
{ SETTINGS_ADAPTIVE_KPI_ACTIVE_BACKEND }
}
text {
style: text_fifth_style
{ active_backend_val }
}
}
column {
style: column_tertiary_style
text {
style: text_quaternary_style
{ SETTINGS_ADAPTIVE_KPI_RECOMMENDED_BACKEND }
}
text {
style: text_fifth_style
{ rec_backend_val }
}
}
column {
style: column_tertiary_style
text {
style: text_quaternary_style
{ SETTINGS_ADAPTIVE_KPI_CPU_MIRROR }
}
text {
style: text_fifth_style
{ cpu_mirror_val }
}
}
column {
style: column_tertiary_style
text {
style: text_quaternary_style
{ SETTINGS_ADAPTIVE_KPI_TIMING_SOURCE }
}
text {
style: text_fifth_style
{ timing_src_val }
}
}
column {
style: column_tertiary_style
text {
style: text_quaternary_style
{ SETTINGS_ADAPTIVE_KPI_UPLOAD_STRATEGY }
}
text {
style: text_fifth_style
{ upload_strat_val }
}
}
column {
style: column_tertiary_style
text {
style: text_quaternary_style
{ SETTINGS_ADAPTIVE_KPI_HANDOFFS }
}
text {
style: text_fifth_style
{ handoffs_val }
}
}
column {
style: column_tertiary_style
text {
style: text_quaternary_style
{ SETTINGS_ADAPTIVE_KPI_EQUIVALENCE }
}
text {
style: text_fifth_style
{ SETTINGS_ADAPTIVE_EQUIVALENCE_VAL }
}
}
}
}
};
let ctx: Context = current_context();
ctx.get_scene().with_write(
|tree: &mut SceneTree| {
tree.attach_scope(card_node, sync_scope);
},
(),
);
card_node
}
pub(crate) fn mount_settings_hot_update_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
let palette: ThemePalette = tokens.get_palette();
let config_spec: HotUpdateProxyConfig = resolve_proxy_env();
let proxy_label: &str = config_spec.proxy_url_str().unwrap_or("Direct (no proxy)");
let summary: String = format!(
"Server: {} | Proxy: {proxy_label} | Channel: {}",
config_spec.get_server_url(),
config_spec.get_channel()
);
let route_sig: Signal<String> = state.get_route();
let on_open_dynamic = move |_: &UiEvent| {
let _: bool = route_sig.set_if_changed(ROUTE_DYNAMIC.to_string());
};
let column_style: Style = style! {
Width(Length::Percent(100.0))
Gap(SPACE_SM)
Overflow::Hidden
};
let text_style: Style = style! {
Width(Length::Percent(100.0))
FontSize(12.0)
FontFamily::Monospace
TextColor(palette.get_muted_foreground())
};
view! {
EuvCard {
title: SETTINGS_HOT_UPDATE_TITLE.to_string()
tokens: tokens
subtitle: SETTINGS_HOT_UPDATE_SUB
column {
style: column_style
text {
style: text_style
{ summary }
}
EuvActionRow {
EuvButton {
label: SETTINGS_BTN_OPEN_HOT_UPDATE.to_string()
tokens: tokens
outline()
on_click: on_open_dynamic
}
}
}
}
}
}
pub fn mount_settings_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
let action_log: Signal<String> = Signal::new(SETTINGS_ACTION_LOG_READY.to_string());
let appearance_card: NodeId = mount_settings_appearance_card(state, tokens);
let chrome_card: NodeId = mount_settings_chrome_card(state, tokens);
let motion_card: NodeId = mount_settings_motion_card(state, tokens);
let adaptive_card: NodeId = mount_settings_adaptive_render_card(state, tokens);
let hot_update_card: NodeId = mount_settings_hot_update_card(state, tokens);
let runtime_card: NodeId = mount_settings_runtime_card(state, action_log, tokens);
let top_grid: NodeId = mount_responsive_grid(vec![chrome_card, motion_card], 2);
view! {
EuvPage {
title: SETTINGS_TITLE.to_string()
subtitle: SETTINGS_SUBTITLE.to_string()
tokens: tokens
{ appearance_card }
{ top_grid }
{ adaptive_card }
{ hot_update_card }
{ runtime_card }
}
}
}