use super::*;
pub(crate) fn mount_settings_appearance_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
let p: 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 all_schemes: [DesignScheme; 17] = DesignScheme::all();
let scheme_buttons: Vec<NodeId> = all_schemes
.into_iter()
.map(|scheme: DesignScheme| {
let on_pick = move |_: &UiEvent| {
let _: bool = scheme_sig.set_if_changed(scheme);
};
let btn_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 active: bool = scheme_sig.get() == scheme;
let bg: Color = if active {
live_p.get_primary()
} else {
live_p.get_card()
};
let border: Color = if active {
live_p.get_primary()
} else {
live_p.get_border()
};
Style::default()
.row()
.width(Length::Percent(100.0))
.height(Length::Px(live_g.get_control_sm()))
.padding(Edges::symmetric(0.0, SPACE_SM))
.align(AlignItems::Center)
.gap(SPACE_SM)
.overflow(Overflow::Hidden)
.background(bg)
.border(live_g.get_border_width(), border)
.radius(live_g.get_radius_md())
.cursor(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();
Style::default()
.width(Length::Px(10.0))
.height(Length::Px(10.0))
.flex_shrink(0.0)
.background(preview.get_primary())
.border(1.0, live_p.get_border())
.radius(PILL_RADIUS)
};
let lbl_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 fg: Color = if active {
live_p.get_primary_foreground()
} else {
live_p.get_foreground()
};
Style::default()
.flex_grow(1.0)
.flex_shrink(1.0)
.min_width(Length::Px(0.0))
.font_size(12.5)
.font_weight(FontWeight::Medium)
.color(fg)
.overflow(Overflow::Hidden)
.text_overflow(TextOverflow::Ellipsis)
};
view! {
row {
bind_style: btn_style
role: A11yRole::Button
on_click: on_pick
view {
bind_style: dot_style
}
text {
bind_style: lbl_style
{ scheme.as_str().to_string() }
}
}
}
})
.collect();
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::default()
.column()
.width(Length::Percent(100.0))
.padding(Edges::all(SPACE_MD))
.gap(SPACE_XS)
.background(live_p.get_background())
.border(live_g.get_border_width(), live_p.get_border())
.radius(live_g.get_radius_md())
.overflow(Overflow::Hidden)
};
let contrast_head_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
Style::default()
.width(Length::Percent(100.0))
.font_size(13.0)
.font_weight(FontWeight::SemiBold)
.color(live.get_palette().get_foreground())
};
let contrast_body_style = move || -> Style {
let live: ThemeTokens = use_live_tokens(tokens);
Style::default()
.width(Length::Percent(100.0))
.font_size(12.0)
.color(live.get_palette().get_muted_foreground())
};
let card_node: NodeId = view! {
EuvCard {
title: SETTINGS_APPEARANCE_TITLE.to_string()
tokens: tokens
subtitle: SETTINGS_APPEARANCE_SUB
column {
style: {
width: Length::Percent(100.0)
gap: SPACE_SM
}
text {
style: {
width: Length::Percent(100.0)
font_size: 13.5
font_weight: FontWeight::SemiBold
color: p.get_foreground()
}
{ SETTINGS_MODE_HEADING }
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
color: p.get_muted_foreground()
}
{ SETTINGS_MODE_SUB }
}
{ mode_segmented_node }
}
column {
style: {
width: Length::Percent(100.0)
gap: SPACE_SM
}
text {
style: {
width: Length::Percent(100.0)
font_size: 13.5
font_weight: FontWeight::SemiBold
color: p.get_foreground()
}
{ SETTINGS_SCHEME_HEADING }
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
color: p.get_muted_foreground()
}
{ SETTINGS_SCHEME_SUB }
}
grid {
style: {
width: Length::Percent(100.0)
columns: 2
gap: SPACE_SM
}
..scheme_buttons
}
}
column {
style: {
width: Length::Percent(100.0)
gap: SPACE_SM
}
text {
style: {
width: Length::Percent(100.0)
font_size: 13.5
font_weight: FontWeight::SemiBold
color: p.get_foreground()
}
{ SETTINGS_CONTRAST_TITLE }
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
color: p.get_muted_foreground()
}
{ 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: {
width: Length::Percent(100.0)
flex_wrap: FlexWrap::Wrap
gap: SPACE_SM
}
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
sm()
}
EuvButton {
label: SETTINGS_BTN_PREVIEW_SEC.to_string()
tokens: tokens
secondary()
sm()
}
EuvButton {
label: SETTINGS_BTN_PREVIEW_OUT.to_string()
tokens: tokens
outline()
sm()
}
}
}
}
};
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 p: 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();
view! {
EuvCard {
title: SETTINGS_NAV_TITLE.to_string()
tokens: tokens
subtitle: SETTINGS_NAV_SUB
column {
style: {
width: Length::Percent(100.0)
gap: SPACE_SM
}
EuvSwitch {
checked: auto_hide_sig
label: SETTINGS_AUTO_HIDE_LABEL.to_string()
tokens: tokens
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
color: p.get_muted_foreground()
}
{ SETTINGS_AUTO_HIDE_DESC }
}
}
column {
style: {
width: Length::Percent(100.0)
gap: SPACE_SM
}
EuvSwitch {
checked: show_fps_sig
label: SETTINGS_SHOW_FPS_LABEL.to_string()
tokens: tokens
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
color: p.get_muted_foreground()
}
{ SETTINGS_SHOW_FPS_DESC }
}
}
column {
style: {
width: Length::Percent(100.0)
gap: SPACE_SM
}
EuvSwitch {
checked: swipe_sig
label: SETTINGS_SWIPE_ROUTING_LABEL.to_string()
tokens: tokens
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
color: p.get_muted_foreground()
}
{ SETTINGS_SWIPE_ROUTING_DESC }
}
}
}
}
}
pub(crate) fn mount_settings_motion_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
let p: ThemePalette = tokens.get_palette();
let g: ThemeGeometry = tokens.get_geometry();
let reduced_motion_sig: Signal<bool> = state.get_reduced_motion();
view! {
EuvCard {
title: SETTINGS_MOTION_TITLE.to_string()
tokens: tokens
subtitle: SETTINGS_MOTION_SUB
column {
style: {
width: Length::Percent(100.0)
gap: SPACE_SM
}
EuvSwitch {
checked: reduced_motion_sig
label: SETTINGS_REDUCED_MOTION_LABEL.to_string()
tokens: tokens
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
color: p.get_muted_foreground()
}
{ SETTINGS_REDUCED_MOTION_DESC }
}
}
column {
style: {
width: Length::Percent(100.0)
gap: SPACE_SM
}
text {
style: {
width: Length::Percent(100.0)
font_size: 13.5
font_weight: FontWeight::SemiBold
color: p.get_foreground()
}
{ SETTINGS_MOTION_RHYTHM_TITLE }
}
column {
style: {
width: Length::Percent(100.0)
padding: Edges::all(SPACE_MD)
gap: SPACE_XS
background: p.get_background()
border: (g.get_border_width(), p.get_border())
radius: g.get_radius_md()
overflow: Overflow::Hidden
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.5
font_weight: FontWeight::SemiBold
color: p.get_primary()
}
{ SETTINGS_MOTION_MICRO_TITLE }
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
color: p.get_muted_foreground()
}
{ SETTINGS_MOTION_MICRO_DESC }
}
}
column {
style: {
width: Length::Percent(100.0)
padding: Edges::all(SPACE_MD)
gap: SPACE_XS
background: p.get_background()
border: (g.get_border_width(), p.get_border())
radius: g.get_radius_md()
overflow: Overflow::Hidden
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.5
font_weight: FontWeight::SemiBold
color: p.get_primary()
}
{ SETTINGS_MOTION_STD_TITLE }
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
color: p.get_muted_foreground()
}
{ SETTINGS_MOTION_STD_DESC }
}
}
column {
style: {
width: Length::Percent(100.0)
padding: Edges::all(SPACE_MD)
gap: SPACE_XS
background: p.get_background()
border: (g.get_border_width(), p.get_border())
radius: g.get_radius_md()
overflow: Overflow::Hidden
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.5
font_weight: FontWeight::SemiBold
color: p.get_primary()
}
{ SETTINGS_MOTION_EMPH_TITLE }
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
color: p.get_muted_foreground()
}
{ SETTINGS_MOTION_EMPH_DESC }
}
}
text {
style: {
width: Length::Percent(100.0)
font_size: 11.5
italic: true
color: p.get_muted_foreground()
}
{ SETTINGS_MOTION_EASING_NOTE }
}
}
}
}
}
pub(crate) fn mount_settings_runtime_card(
state: &ShowcaseState,
action_log: Signal<String>,
tokens: ThemeTokens,
) -> NodeId {
let p: ThemePalette = tokens.get_palette();
let g: 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 vp: Size = vp_sig.get();
format!("{:.0}x{:.0} px", vp.get_width(), vp.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());
};
view! {
EuvCard {
title: SETTINGS_RUNTIME_TITLE.to_string()
tokens: tokens
subtitle: SETTINGS_RUNTIME_SUB
grid {
style: {
width: Length::Percent(100.0)
columns: 2
gap: SPACE_SM
}
column {
style: {
width: Length::Percent(100.0)
padding: Edges::all(SPACE_SM)
gap: SPACE_XS
background: p.get_background()
border: (g.get_border_width(), p.get_border())
radius: g.get_radius_sm()
overflow: Overflow::Hidden
}
text {
style: {
width: Length::Percent(100.0)
font_size: 11.5
color: p.get_muted_foreground()
}
{ SETTINGS_KPI_PLATFORM }
}
text {
style: {
width: Length::Percent(100.0)
font_size: 13.0
font_weight: FontWeight::SemiBold
color: p.get_foreground()
}
{ platform_line }
}
}
column {
style: {
width: Length::Percent(100.0)
padding: Edges::all(SPACE_SM)
gap: SPACE_XS
background: p.get_background()
border: (g.get_border_width(), p.get_border())
radius: g.get_radius_sm()
overflow: Overflow::Hidden
}
text {
style: {
width: Length::Percent(100.0)
font_size: 11.5
color: p.get_muted_foreground()
}
{ SETTINGS_KPI_RENDERER }
}
text {
style: {
width: Length::Percent(100.0)
font_size: 13.0
font_weight: FontWeight::SemiBold
color: p.get_foreground()
}
{ SETTINGS_KPI_RENDERER_VAL }
}
}
column {
style: {
width: Length::Percent(100.0)
padding: Edges::all(SPACE_SM)
gap: SPACE_XS
background: p.get_background()
border: (g.get_border_width(), p.get_border())
radius: g.get_radius_sm()
overflow: Overflow::Hidden
}
text {
style: {
width: Length::Percent(100.0)
font_size: 11.5
color: p.get_muted_foreground()
}
{ SETTINGS_KPI_VIEWPORT }
}
text {
style: {
width: Length::Percent(100.0)
font_size: 13.0
font_weight: FontWeight::SemiBold
color: p.get_foreground()
}
{ vp_line }
}
}
column {
style: {
width: Length::Percent(100.0)
padding: Edges::all(SPACE_SM)
gap: SPACE_XS
background: p.get_background()
border: (g.get_border_width(), p.get_border())
radius: g.get_radius_sm()
overflow: Overflow::Hidden
}
text {
style: {
width: Length::Percent(100.0)
font_size: 11.5
color: p.get_muted_foreground()
}
{ SETTINGS_KPI_SAFE_AREA }
}
text {
style: {
width: Length::Percent(100.0)
font_size: 13.0
font_weight: FontWeight::SemiBold
color: p.get_foreground()
}
{ sa_line }
}
}
}
EuvActionRow {
EuvButton {
label: SETTINGS_BTN_GITHUB.to_string()
tokens: tokens
secondary()
sm()
on_click: on_open_github
}
EuvButton {
label: SETTINGS_BTN_RESET.to_string()
tokens: tokens
outline()
sm()
on_click: on_reset_defaults
}
}
text {
style: {
width: Length::Percent(100.0)
font_size: 12.0
font_family: FontFamily::Monospace
color: p.get_primary()
}
{ action_log_text }
}
}
}
}
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 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 }
{ runtime_card }
}
}
}