euv_example/pages/settings/
fn.rs1use super::*;
2
3pub(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 all_schemes: [DesignScheme; 17] = DesignScheme::all();
48 let scheme_buttons: Vec<NodeId> = all_schemes
49 .into_iter()
50 .map(|scheme: DesignScheme| {
51 let on_pick = move |_: &UiEvent| {
52 let _: bool = scheme_sig.set_if_changed(scheme);
53 };
54 let btn_style = move || -> Style {
55 let live: ThemeTokens = use_live_tokens(tokens);
56 let live_p: ThemePalette = live.get_palette();
57 let live_g: ThemeGeometry = live.get_geometry();
58 let active: bool = scheme_sig.get() == scheme;
59 let bg: Color = if active {
60 live_p.get_primary()
61 } else {
62 live_p.get_card()
63 };
64 let border: Color = if active {
65 live_p.get_primary()
66 } else {
67 live_p.get_border()
68 };
69 Style::default()
70 .row()
71 .width(Length::Percent(100.0))
72 .height(Length::Px(live_g.get_control_sm()))
73 .padding(Edges::symmetric(0.0, SPACE_SM))
74 .align(AlignItems::Center)
75 .gap(SPACE_SM)
76 .overflow(Overflow::Hidden)
77 .background(bg)
78 .border(live_g.get_border_width(), border)
79 .radius(live_g.get_radius_md())
80 .cursor(CursorIcon::Pointer)
81 };
82 let dot_style = move || -> Style {
83 let mode: ThemeMode = mode_sig.get();
84 let preview: ThemePalette = ThemeTokens::resolve(scheme, mode).get_palette();
85 let live_p: ThemePalette = use_live_tokens(tokens).get_palette();
86 Style::default()
87 .width(Length::Px(10.0))
88 .height(Length::Px(10.0))
89 .flex_shrink(0.0)
90 .background(preview.get_primary())
91 .border(1.0, live_p.get_border())
92 .radius(PILL_RADIUS)
93 };
94 let lbl_style = move || -> Style {
95 let live: ThemeTokens = use_live_tokens(tokens);
96 let live_p: ThemePalette = live.get_palette();
97 let active: bool = scheme_sig.get() == scheme;
98 let fg: Color = if active {
99 live_p.get_primary_foreground()
100 } else {
101 live_p.get_foreground()
102 };
103 Style::default()
104 .flex_grow(1.0)
105 .flex_shrink(1.0)
106 .min_width(Length::Px(0.0))
107 .font_size(12.5)
108 .font_weight(FontWeight::Medium)
109 .color(fg)
110 .overflow(Overflow::Hidden)
111 .text_overflow(TextOverflow::Ellipsis)
112 };
113 view! {
114 row {
115 bind_style: btn_style
116 role: A11yRole::Button
117 on_click: on_pick
118 view {
119 bind_style: dot_style
120 }
121 text {
122 bind_style: lbl_style
123 { scheme.as_str().to_string() }
124 }
125 }
126 }
127 })
128 .collect();
129 let contrast_sample_style = move || -> Style {
130 let live: ThemeTokens = use_live_tokens(tokens);
131 let live_p: ThemePalette = live.get_palette();
132 let live_g: ThemeGeometry = live.get_geometry();
133 Style::default()
134 .column()
135 .width(Length::Percent(100.0))
136 .padding(Edges::all(SPACE_MD))
137 .gap(SPACE_XS)
138 .background(live_p.get_background())
139 .border(live_g.get_border_width(), live_p.get_border())
140 .radius(live_g.get_radius_md())
141 .overflow(Overflow::Hidden)
142 };
143 let contrast_head_style = move || -> Style {
144 let live: ThemeTokens = use_live_tokens(tokens);
145 Style::default()
146 .width(Length::Percent(100.0))
147 .font_size(13.0)
148 .font_weight(FontWeight::SemiBold)
149 .color(live.get_palette().get_foreground())
150 };
151 let contrast_body_style = move || -> Style {
152 let live: ThemeTokens = use_live_tokens(tokens);
153 Style::default()
154 .width(Length::Percent(100.0))
155 .font_size(12.0)
156 .color(live.get_palette().get_muted_foreground())
157 };
158 let card_node: NodeId = view! {
159 EuvCard {
160 title: SETTINGS_APPEARANCE_TITLE.to_string()
161 tokens: tokens
162 subtitle: SETTINGS_APPEARANCE_SUB
163 column {
164 style: {
165 width: Length::Percent(100.0)
166 gap: SPACE_SM
167 }
168 text {
169 style: {
170 width: Length::Percent(100.0)
171 font_size: 13.5
172 font_weight: FontWeight::SemiBold
173 color: p.get_foreground()
174 }
175 { SETTINGS_MODE_HEADING }
176 }
177 text {
178 style: {
179 width: Length::Percent(100.0)
180 font_size: 12.0
181 color: p.get_muted_foreground()
182 }
183 { SETTINGS_MODE_SUB }
184 }
185 { mode_segmented_node }
186 }
187 column {
188 style: {
189 width: Length::Percent(100.0)
190 gap: SPACE_SM
191 }
192 text {
193 style: {
194 width: Length::Percent(100.0)
195 font_size: 13.5
196 font_weight: FontWeight::SemiBold
197 color: p.get_foreground()
198 }
199 { SETTINGS_SCHEME_HEADING }
200 }
201 text {
202 style: {
203 width: Length::Percent(100.0)
204 font_size: 12.0
205 color: p.get_muted_foreground()
206 }
207 { SETTINGS_SCHEME_SUB }
208 }
209 grid {
210 style: {
211 width: Length::Percent(100.0)
212 columns: 2
213 gap: SPACE_SM
214 }
215 ..scheme_buttons
216 }
217 }
218 column {
219 style: {
220 width: Length::Percent(100.0)
221 gap: SPACE_SM
222 }
223 text {
224 style: {
225 width: Length::Percent(100.0)
226 font_size: 13.5
227 font_weight: FontWeight::SemiBold
228 color: p.get_foreground()
229 }
230 { SETTINGS_CONTRAST_TITLE }
231 }
232 text {
233 style: {
234 width: Length::Percent(100.0)
235 font_size: 12.0
236 color: p.get_muted_foreground()
237 }
238 { SETTINGS_CONTRAST_SUB }
239 }
240 view {
241 bind_style: contrast_sample_style
242 text {
243 bind_style: contrast_head_style
244 { SETTINGS_CONTRAST_SAMPLE_HEAD }
245 }
246 text {
247 bind_style: contrast_body_style
248 { SETTINGS_CONTRAST_SAMPLE_BODY }
249 }
250 }
251 row {
252 style: {
253 width: Length::Percent(100.0)
254 flex_wrap: FlexWrap::Wrap
255 gap: SPACE_SM
256 }
257 EuvBadge {
258 label: SETTINGS_BADGE_PREVIEW_PRIMARY.to_string()
259 tone: EuvTone::Primary
260 tokens: tokens
261 }
262 EuvBadge {
263 label: SETTINGS_BADGE_PREVIEW_SUCCESS.to_string()
264 tone: EuvTone::Success
265 tokens: tokens
266 }
267 EuvBadge {
268 label: SETTINGS_BADGE_PREVIEW_WARNING.to_string()
269 tone: EuvTone::Warning
270 tokens: tokens
271 }
272 EuvBadge {
273 label: SETTINGS_BADGE_PREVIEW_DANGER.to_string()
274 tone: EuvTone::Destructive
275 tokens: tokens
276 }
277 }
278 EuvActionRow {
279 EuvButton {
280 label: SETTINGS_BTN_PREVIEW_PRI.to_string()
281 tokens: tokens
282 sm()
283 }
284 EuvButton {
285 label: SETTINGS_BTN_PREVIEW_SEC.to_string()
286 tokens: tokens
287 secondary()
288 sm()
289 }
290 EuvButton {
291 label: SETTINGS_BTN_PREVIEW_OUT.to_string()
292 tokens: tokens
293 outline()
294 sm()
295 }
296 }
297 }
298 }
299 };
300 let ctx: Context = current_context();
301 ctx.get_scene().with_write(
302 |tree: &mut SceneTree| {
303 tree.attach_scope(card_node, mode_scope);
304 },
305 (),
306 );
307 card_node
308}
309
310pub(crate) fn mount_settings_chrome_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
321 let p: ThemePalette = tokens.get_palette();
322 let auto_hide_sig: Signal<bool> = state.get_auto_hide_chrome();
323 let show_fps_sig: Signal<bool> = state.get_show_fps_hud();
324 let swipe_sig: Signal<bool> = state.get_swipe_routing();
325 view! {
326 EuvCard {
327 title: SETTINGS_NAV_TITLE.to_string()
328 tokens: tokens
329 subtitle: SETTINGS_NAV_SUB
330 column {
331 style: {
332 width: Length::Percent(100.0)
333 gap: SPACE_SM
334 }
335 EuvSwitch {
336 checked: auto_hide_sig
337 label: SETTINGS_AUTO_HIDE_LABEL.to_string()
338 tokens: tokens
339 }
340 text {
341 style: {
342 width: Length::Percent(100.0)
343 font_size: 12.0
344 color: p.get_muted_foreground()
345 }
346 { SETTINGS_AUTO_HIDE_DESC }
347 }
348 }
349 column {
350 style: {
351 width: Length::Percent(100.0)
352 gap: SPACE_SM
353 }
354 EuvSwitch {
355 checked: show_fps_sig
356 label: SETTINGS_SHOW_FPS_LABEL.to_string()
357 tokens: tokens
358 }
359 text {
360 style: {
361 width: Length::Percent(100.0)
362 font_size: 12.0
363 color: p.get_muted_foreground()
364 }
365 { SETTINGS_SHOW_FPS_DESC }
366 }
367 }
368 column {
369 style: {
370 width: Length::Percent(100.0)
371 gap: SPACE_SM
372 }
373 EuvSwitch {
374 checked: swipe_sig
375 label: SETTINGS_SWIPE_ROUTING_LABEL.to_string()
376 tokens: tokens
377 }
378 text {
379 style: {
380 width: Length::Percent(100.0)
381 font_size: 12.0
382 color: p.get_muted_foreground()
383 }
384 { SETTINGS_SWIPE_ROUTING_DESC }
385 }
386 }
387 }
388 }
389}
390
391pub(crate) fn mount_settings_motion_card(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
402 let p: ThemePalette = tokens.get_palette();
403 let g: ThemeGeometry = tokens.get_geometry();
404 let reduced_motion_sig: Signal<bool> = state.get_reduced_motion();
405 view! {
406 EuvCard {
407 title: SETTINGS_MOTION_TITLE.to_string()
408 tokens: tokens
409 subtitle: SETTINGS_MOTION_SUB
410 column {
411 style: {
412 width: Length::Percent(100.0)
413 gap: SPACE_SM
414 }
415 EuvSwitch {
416 checked: reduced_motion_sig
417 label: SETTINGS_REDUCED_MOTION_LABEL.to_string()
418 tokens: tokens
419 }
420 text {
421 style: {
422 width: Length::Percent(100.0)
423 font_size: 12.0
424 color: p.get_muted_foreground()
425 }
426 { SETTINGS_REDUCED_MOTION_DESC }
427 }
428 }
429 column {
430 style: {
431 width: Length::Percent(100.0)
432 gap: SPACE_SM
433 }
434 text {
435 style: {
436 width: Length::Percent(100.0)
437 font_size: 13.5
438 font_weight: FontWeight::SemiBold
439 color: p.get_foreground()
440 }
441 { SETTINGS_MOTION_RHYTHM_TITLE }
442 }
443 column {
444 style: {
445 width: Length::Percent(100.0)
446 padding: Edges::all(SPACE_MD)
447 gap: SPACE_XS
448 background: p.get_background()
449 border: (g.get_border_width(), p.get_border())
450 radius: g.get_radius_md()
451 overflow: Overflow::Hidden
452 }
453 text {
454 style: {
455 width: Length::Percent(100.0)
456 font_size: 12.5
457 font_weight: FontWeight::SemiBold
458 color: p.get_primary()
459 }
460 { SETTINGS_MOTION_MICRO_TITLE }
461 }
462 text {
463 style: {
464 width: Length::Percent(100.0)
465 font_size: 12.0
466 color: p.get_muted_foreground()
467 }
468 { SETTINGS_MOTION_MICRO_DESC }
469 }
470 }
471 column {
472 style: {
473 width: Length::Percent(100.0)
474 padding: Edges::all(SPACE_MD)
475 gap: SPACE_XS
476 background: p.get_background()
477 border: (g.get_border_width(), p.get_border())
478 radius: g.get_radius_md()
479 overflow: Overflow::Hidden
480 }
481 text {
482 style: {
483 width: Length::Percent(100.0)
484 font_size: 12.5
485 font_weight: FontWeight::SemiBold
486 color: p.get_primary()
487 }
488 { SETTINGS_MOTION_STD_TITLE }
489 }
490 text {
491 style: {
492 width: Length::Percent(100.0)
493 font_size: 12.0
494 color: p.get_muted_foreground()
495 }
496 { SETTINGS_MOTION_STD_DESC }
497 }
498 }
499 column {
500 style: {
501 width: Length::Percent(100.0)
502 padding: Edges::all(SPACE_MD)
503 gap: SPACE_XS
504 background: p.get_background()
505 border: (g.get_border_width(), p.get_border())
506 radius: g.get_radius_md()
507 overflow: Overflow::Hidden
508 }
509 text {
510 style: {
511 width: Length::Percent(100.0)
512 font_size: 12.5
513 font_weight: FontWeight::SemiBold
514 color: p.get_primary()
515 }
516 { SETTINGS_MOTION_EMPH_TITLE }
517 }
518 text {
519 style: {
520 width: Length::Percent(100.0)
521 font_size: 12.0
522 color: p.get_muted_foreground()
523 }
524 { SETTINGS_MOTION_EMPH_DESC }
525 }
526 }
527 text {
528 style: {
529 width: Length::Percent(100.0)
530 font_size: 11.5
531 italic: true
532 color: p.get_muted_foreground()
533 }
534 { SETTINGS_MOTION_EASING_NOTE }
535 }
536 }
537 }
538 }
539}
540
541pub(crate) fn mount_settings_runtime_card(
553 state: &ShowcaseState,
554 action_log: Signal<String>,
555 tokens: ThemeTokens,
556) -> NodeId {
557 let p: ThemePalette = tokens.get_palette();
558 let g: ThemeGeometry = tokens.get_geometry();
559 let platform: PlatformKind = current_platform();
560 let vp_sig: Signal<Size> = use_viewport_size();
561 let safe_area_sig: Signal<SafeAreaInsets> = use_safe_area();
562 let state_reset: ShowcaseState = state.clone();
563 let platform_line: String = format!("{platform:?}");
564 let vp_line = move || -> String {
565 let vp: Size = vp_sig.get();
566 format!("{:.0}x{:.0} px", vp.get_width(), vp.get_height())
567 };
568 let sa_line = move || -> String {
569 let sa: SafeAreaInsets = safe_area_sig.get();
570 format!(
571 "T{:.0} R{:.0} B{:.0} L{:.0}",
572 sa.get_top(),
573 sa.get_right(),
574 sa.get_bottom(),
575 sa.get_left()
576 )
577 };
578 let action_log_text = move || -> String { action_log.get() };
579 let on_open_github = move |_: &UiEvent| {
580 let _: bool = open_external_url(PROJECT_GITHUB_URL);
581 let _: bool = action_log.set(SETTINGS_ACTION_LOG_GITHUB.to_string());
582 };
583 let on_reset_defaults = move |_: &UiEvent| {
584 state_reset.reset_preferences_to_defaults();
585 let _: bool = action_log.set(SETTINGS_ACTION_LOG_RESET.to_string());
586 };
587 view! {
588 EuvCard {
589 title: SETTINGS_RUNTIME_TITLE.to_string()
590 tokens: tokens
591 subtitle: SETTINGS_RUNTIME_SUB
592 grid {
593 style: {
594 width: Length::Percent(100.0)
595 columns: 2
596 gap: SPACE_SM
597 }
598 column {
599 style: {
600 width: Length::Percent(100.0)
601 padding: Edges::all(SPACE_SM)
602 gap: SPACE_XS
603 background: p.get_background()
604 border: (g.get_border_width(), p.get_border())
605 radius: g.get_radius_sm()
606 overflow: Overflow::Hidden
607 }
608 text {
609 style: {
610 width: Length::Percent(100.0)
611 font_size: 11.5
612 color: p.get_muted_foreground()
613 }
614 { SETTINGS_KPI_PLATFORM }
615 }
616 text {
617 style: {
618 width: Length::Percent(100.0)
619 font_size: 13.0
620 font_weight: FontWeight::SemiBold
621 color: p.get_foreground()
622 }
623 { platform_line }
624 }
625 }
626 column {
627 style: {
628 width: Length::Percent(100.0)
629 padding: Edges::all(SPACE_SM)
630 gap: SPACE_XS
631 background: p.get_background()
632 border: (g.get_border_width(), p.get_border())
633 radius: g.get_radius_sm()
634 overflow: Overflow::Hidden
635 }
636 text {
637 style: {
638 width: Length::Percent(100.0)
639 font_size: 11.5
640 color: p.get_muted_foreground()
641 }
642 { SETTINGS_KPI_RENDERER }
643 }
644 text {
645 style: {
646 width: Length::Percent(100.0)
647 font_size: 13.0
648 font_weight: FontWeight::SemiBold
649 color: p.get_foreground()
650 }
651 { SETTINGS_KPI_RENDERER_VAL }
652 }
653 }
654 column {
655 style: {
656 width: Length::Percent(100.0)
657 padding: Edges::all(SPACE_SM)
658 gap: SPACE_XS
659 background: p.get_background()
660 border: (g.get_border_width(), p.get_border())
661 radius: g.get_radius_sm()
662 overflow: Overflow::Hidden
663 }
664 text {
665 style: {
666 width: Length::Percent(100.0)
667 font_size: 11.5
668 color: p.get_muted_foreground()
669 }
670 { SETTINGS_KPI_VIEWPORT }
671 }
672 text {
673 style: {
674 width: Length::Percent(100.0)
675 font_size: 13.0
676 font_weight: FontWeight::SemiBold
677 color: p.get_foreground()
678 }
679 { vp_line }
680 }
681 }
682 column {
683 style: {
684 width: Length::Percent(100.0)
685 padding: Edges::all(SPACE_SM)
686 gap: SPACE_XS
687 background: p.get_background()
688 border: (g.get_border_width(), p.get_border())
689 radius: g.get_radius_sm()
690 overflow: Overflow::Hidden
691 }
692 text {
693 style: {
694 width: Length::Percent(100.0)
695 font_size: 11.5
696 color: p.get_muted_foreground()
697 }
698 { SETTINGS_KPI_SAFE_AREA }
699 }
700 text {
701 style: {
702 width: Length::Percent(100.0)
703 font_size: 13.0
704 font_weight: FontWeight::SemiBold
705 color: p.get_foreground()
706 }
707 { sa_line }
708 }
709 }
710 }
711 EuvActionRow {
712 EuvButton {
713 label: SETTINGS_BTN_GITHUB.to_string()
714 tokens: tokens
715 secondary()
716 sm()
717 on_click: on_open_github
718 }
719 EuvButton {
720 label: SETTINGS_BTN_RESET.to_string()
721 tokens: tokens
722 outline()
723 sm()
724 on_click: on_reset_defaults
725 }
726 }
727 text {
728 style: {
729 width: Length::Percent(100.0)
730 font_size: 12.0
731 font_family: FontFamily::Monospace
732 color: p.get_primary()
733 }
734 { action_log_text }
735 }
736 }
737 }
738}
739
740pub fn mount_settings_page(state: &ShowcaseState, tokens: ThemeTokens) -> NodeId {
751 let action_log: Signal<String> = Signal::new(SETTINGS_ACTION_LOG_READY.to_string());
752 let appearance_card: NodeId = mount_settings_appearance_card(state, tokens);
753 let chrome_card: NodeId = mount_settings_chrome_card(state, tokens);
754 let motion_card: NodeId = mount_settings_motion_card(state, tokens);
755 let runtime_card: NodeId = mount_settings_runtime_card(state, action_log, tokens);
756 let top_grid: NodeId = mount_responsive_grid(vec![chrome_card, motion_card], 2);
757 view! {
758 EuvPage {
759 title: SETTINGS_TITLE.to_string()
760 subtitle: SETTINGS_SUBTITLE.to_string()
761 tokens: tokens
762 { appearance_card }
763 { top_grid }
764 { runtime_card }
765 }
766 }
767}