Skip to main content

waft_winui/
app.rs

1//! A Fluent application: WinUI's theme resources and accent, its icon font, and its page
2//! entrance, composed the way Flutter's `MaterialApp` and `CupertinoApp` compose
3//! [`WidgetsApp`].
4//!
5//! [`FluentApp`] is the widget an app designed with WinUI's controls is built from. It builds a
6//! [`WidgetsApp`] inside a [`ThemeScope`] for the theme chosen from the app's light and dark
7//! themes and the system's brightness, installs the Fluent icon font, and navigates with
8//! [`FluentPageRoute`].
9
10use std::any::TypeId;
11use std::collections::HashMap;
12use std::fmt::{self, Debug};
13
14use waft_embedder::{Brightness, Color, Locale, SystemUiOverlayStyle};
15use waft_foundation::{App, Handle};
16use waft_painting::TextStyle;
17use waft_services::SystemChrome;
18use waft_widgets::{
19    ActionRef, BuildContext, DefaultSelectionStyle, GenerateAppTitle, GlobalKey,
20    InitialRouteListFactory, IntoWidget, KeyRef, LocaleListResolutionCallback,
21    LocaleResolutionCallback, LocalizationsDelegateRef, MediaQuery, NavigationNotification,
22    NavigatorObserverRef, NotificationListenerCallback, RouteFactory, RouteSettingsRef,
23    ScrollBehaviorRef, ScrollConfiguration, ShortcutMap, State, StateData, StatefulWidget,
24    TransitionBuilder, View, WidgetBuilder, WidgetRef, WidgetsApp,
25};
26
27use crate::primitives::install_icon_font;
28use crate::route::FluentPageRoute;
29use crate::scroll_behavior::FluentScrollBehavior;
30use crate::theme::{AccentPalette, TextBlockStyle, Theme, ThemeResources, ThemeScope};
31
32/// A Fluent app's colours: which WinUI theme dictionary its controls resolve against, and the
33/// accent palette they draw with.
34#[derive(Clone, Copy, Debug, PartialEq)]
35pub struct FluentTheme {
36    /// Whether controls resolve in WinUI's light or dark theme dictionary.
37    pub theme: Theme,
38    /// The `SystemAccentColor` shades.
39    pub accent: AccentPalette,
40}
41
42impl FluentTheme {
43    /// WinUI's light theme in the default accent.
44    pub const fn light() -> FluentTheme {
45        FluentTheme {
46            theme: Theme::Light,
47            accent: AccentPalette::WINDOWS_BLUE,
48        }
49    }
50
51    /// WinUI's dark theme in the default accent.
52    pub const fn dark() -> FluentTheme {
53        FluentTheme {
54            theme: Theme::Dark,
55            accent: AccentPalette::WINDOWS_BLUE,
56        }
57    }
58
59    /// The theme `theme` in `accent`.
60    pub const fn new(theme: Theme, accent: AccentPalette) -> FluentTheme {
61        FluentTheme { theme, accent }
62    }
63
64    /// The same theme in `accent`.
65    pub fn accent(mut self, accent: AccentPalette) -> FluentTheme {
66        self.accent = accent;
67        self
68    }
69}
70
71impl Default for FluentTheme {
72    fn default() -> FluentTheme {
73        FluentTheme::light()
74    }
75}
76
77/// Which of a [`FluentApp`]'s themes it shows.
78///
79/// Flutter's `ThemeMode`, in Fluent's name: `System` follows the platform's brightness,
80/// `Light` and `Dark` choose one whatever the platform says.
81#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
82pub enum FluentThemeMode {
83    /// The dark theme for a platform in dark mode, else the light theme.
84    #[default]
85    System,
86    /// Always the light theme.
87    Light,
88    /// Always the dark theme.
89    Dark,
90}
91
92/// An application using Fluent design, WinUI's controls and their theme resources.
93///
94/// The [`FluentApp`] configures the top-level `Navigator` to search for routes as
95/// [`WidgetsApp`] does, and builds each page with [`FluentPageRoute`], so a page enters with
96/// WinUI's `Frame` entrance. It installs the Fluent icon font itself, so a widget of this
97/// library finds its glyphs without an installation step.
98///
99/// ```text
100/// FluentApp::new()
101///     .title("Notes")
102///     .home(NotesPage::new())
103/// ```
104///
105/// See also:
106///
107///  * [`FluentPageRoute`], which plays WinUI's page entrance.
108///  * [`ThemeScope`], which the app puts its pages in.
109///  * [`WidgetsApp`], which defines the app's routing, shortcuts and title.
110pub struct FluentApp {
111    /// See [`waft_widgets::Widget::key`].
112    pub key: Option<KeyRef>,
113
114    /// See [`WidgetsApp::navigator_key`].
115    pub navigator_key: Option<GlobalKey>,
116
117    /// See [`WidgetsApp::home`].
118    pub home: Option<WidgetRef>,
119
120    /// The light theme, and the one the app shows unless the mode and the platform ask for the
121    /// dark one. [`FluentTheme::light`] when not set.
122    pub theme: Option<FluentTheme>,
123
124    /// The theme shown when the mode is [`FluentThemeMode::Dark`], or when the platform is dark
125    /// and the mode is [`FluentThemeMode::System`]. [`theme`](Self::theme) when not set, and
126    /// [`FluentTheme::dark`] when neither is, as a WinUI app follows the system's theme.
127    pub dark_theme: Option<FluentTheme>,
128
129    /// Which theme is shown. [`FluentThemeMode::System`] when not set.
130    pub theme_mode: Option<FluentThemeMode>,
131
132    /// See [`WidgetsApp::routes`].
133    pub routes: HashMap<String, WidgetBuilder>,
134
135    /// See [`WidgetsApp::initial_route`].
136    pub initial_route: Option<String>,
137
138    /// See [`WidgetsApp::on_generate_route`].
139    pub on_generate_route: Option<RouteFactory>,
140
141    /// See [`WidgetsApp::on_generate_initial_routes`].
142    pub on_generate_initial_routes: Option<InitialRouteListFactory>,
143
144    /// See [`WidgetsApp::on_unknown_route`].
145    pub on_unknown_route: Option<RouteFactory>,
146
147    /// See [`WidgetsApp::on_navigation_notification`].
148    pub on_navigation_notification: Option<NotificationListenerCallback<NavigationNotification>>,
149
150    /// See [`WidgetsApp::navigator_observers`].
151    pub navigator_observers: Vec<NavigatorObserverRef>,
152
153    /// See [`WidgetsApp::builder`].
154    pub builder: Option<TransitionBuilder>,
155
156    /// See [`WidgetsApp::title`].
157    pub title: Option<String>,
158
159    /// See [`WidgetsApp::on_generate_title`].
160    pub on_generate_title: Option<GenerateAppTitle>,
161
162    /// The colour old Android versions show the app in, in the app switcher; the accent's `base`
163    /// when not set, as a Material app takes its theme's primary colour.
164    pub color: Option<Color>,
165
166    /// See [`WidgetsApp::locale`].
167    pub locale: Option<Locale>,
168
169    /// See [`WidgetsApp::localizations_delegates`].
170    pub localizations_delegates: Option<Vec<LocalizationsDelegateRef>>,
171
172    /// See [`WidgetsApp::locale_list_resolution_callback`].
173    pub locale_list_resolution_callback: Option<LocaleListResolutionCallback>,
174
175    /// See [`WidgetsApp::locale_resolution_callback`].
176    pub locale_resolution_callback: Option<LocaleResolutionCallback>,
177
178    /// See [`WidgetsApp::supported_locales`].
179    pub supported_locales: Vec<Locale>,
180
181    /// See [`WidgetsApp::show_performance_overlay`].
182    pub show_performance_overlay: bool,
183
184    /// See [`WidgetsApp::show_semantics_debugger`].
185    pub show_semantics_debugger: bool,
186
187    /// See [`WidgetsApp::debug_show_checked_mode_banner`].
188    pub debug_show_checked_mode_banner: bool,
189
190    /// See [`WidgetsApp::shortcuts`].
191    pub shortcuts: Option<ShortcutMap>,
192
193    /// See [`WidgetsApp::actions`].
194    pub actions: Option<HashMap<TypeId, ActionRef>>,
195
196    /// See [`WidgetsApp::restoration_scope_id`].
197    pub restoration_scope_id: Option<String>,
198
199    /// Dart's deprecated `useInheritedMediaQuery`. This setting is ignored.
200    pub use_inherited_media_query: bool,
201}
202
203impl Default for FluentApp {
204    fn default() -> FluentApp {
205        FluentApp {
206            key: None,
207            navigator_key: None,
208            home: None,
209            theme: None,
210            dark_theme: None,
211            theme_mode: None,
212            routes: HashMap::new(),
213            initial_route: None,
214            on_generate_route: None,
215            on_generate_initial_routes: None,
216            on_unknown_route: None,
217            on_navigation_notification: None,
218            navigator_observers: Vec::new(),
219            builder: None,
220            title: None,
221            on_generate_title: None,
222            color: None,
223            locale: None,
224            localizations_delegates: None,
225            locale_list_resolution_callback: None,
226            locale_resolution_callback: None,
227            supported_locales: vec![Locale::new("en").country_code("US")],
228            show_performance_overlay: false,
229            show_semantics_debugger: false,
230            debug_show_checked_mode_banner: true,
231            shortcuts: None,
232            actions: None,
233            restoration_scope_id: None,
234            use_inherited_media_query: false,
235        }
236    }
237}
238
239impl FluentApp {
240    /// Creates a Fluent app with WinUI's light theme.
241    pub fn new() -> FluentApp {
242        FluentApp::default()
243    }
244
245    /// Dart `MaterialApp(key:)`.
246    pub fn key(mut self, key: KeyRef) -> FluentApp {
247        self.key = Some(key);
248        self
249    }
250
251    /// Dart `WidgetsApp(navigatorKey:)`.
252    pub fn navigator_key(mut self, navigator_key: GlobalKey) -> FluentApp {
253        self.navigator_key = Some(navigator_key);
254        self
255    }
256
257    /// Dart `WidgetsApp(home:)`.
258    #[cfg_attr(debug_assertions, track_caller)]
259    pub fn home<K>(mut self, home: impl waft_widgets::IntoWidget<K>) -> FluentApp {
260        self.home = Some(home.into_widget());
261        self
262    }
263
264    /// The theme the app shows, and the one an unset [`theme_mode`](Self::theme_mode) falls
265    /// back to.
266    pub fn theme(mut self, theme: FluentTheme) -> FluentApp {
267        self.theme = Some(theme);
268        self
269    }
270
271    /// The theme shown in dark mode.
272    pub fn dark_theme(mut self, theme: FluentTheme) -> FluentApp {
273        self.dark_theme = Some(theme);
274        self
275    }
276
277    /// Which theme the app shows.
278    pub fn theme_mode(mut self, mode: FluentThemeMode) -> FluentApp {
279        self.theme_mode = Some(mode);
280        self
281    }
282
283    /// Dart `WidgetsApp(routes:)`.
284    pub fn routes(
285        mut self,
286        routes: impl IntoIterator<Item = (String, WidgetBuilder)>,
287    ) -> FluentApp {
288        self.routes = routes.into_iter().collect();
289        self
290    }
291
292    /// Dart `WidgetsApp(initialRoute:)`.
293    pub fn initial_route(mut self, initial_route: impl Into<String>) -> FluentApp {
294        self.initial_route = Some(initial_route.into());
295        self
296    }
297
298    /// Dart `WidgetsApp(onGenerateRoute:)`.
299    pub fn on_generate_route(
300        mut self,
301        on_generate_route: impl Fn(
302            &mut App,
303            &waft_widgets::RouteSettings,
304        ) -> Option<waft_widgets::RouteRef>
305        + 'static,
306    ) -> FluentApp {
307        self.on_generate_route = Some(std::rc::Rc::new(on_generate_route));
308        self
309    }
310
311    /// Dart `WidgetsApp(onGenerateInitialRoutes:)`.
312    pub fn on_generate_initial_routes(
313        mut self,
314        on_generate_initial_routes: impl Fn(&mut App, &str) -> Vec<waft_widgets::RouteRef> + 'static,
315    ) -> FluentApp {
316        self.on_generate_initial_routes = Some(std::rc::Rc::new(on_generate_initial_routes));
317        self
318    }
319
320    /// Dart `WidgetsApp(onUnknownRoute:)`.
321    pub fn on_unknown_route(
322        mut self,
323        on_unknown_route: impl Fn(
324            &mut App,
325            &waft_widgets::RouteSettings,
326        ) -> Option<waft_widgets::RouteRef>
327        + 'static,
328    ) -> FluentApp {
329        self.on_unknown_route = Some(std::rc::Rc::new(on_unknown_route));
330        self
331    }
332
333    /// Dart `WidgetsApp(onNavigationNotification:)`.
334    pub fn on_navigation_notification(
335        mut self,
336        on_navigation_notification: impl Fn(&mut App, &NavigationNotification) -> bool + 'static,
337    ) -> FluentApp {
338        self.on_navigation_notification = Some(std::rc::Rc::new(on_navigation_notification));
339        self
340    }
341
342    /// Dart `WidgetsApp(navigatorObservers:)`.
343    pub fn navigator_observers(
344        mut self,
345        navigator_observers: impl IntoIterator<Item = NavigatorObserverRef>,
346    ) -> FluentApp {
347        self.navigator_observers = navigator_observers.into_iter().collect();
348        self
349    }
350
351    /// Dart `WidgetsApp(builder:)`.
352    pub fn builder(
353        mut self,
354        builder: impl Fn(&mut App, BuildContext, Option<&WidgetRef>) -> WidgetRef + 'static,
355    ) -> FluentApp {
356        self.builder = Some(std::rc::Rc::new(builder));
357        self
358    }
359
360    /// Dart `WidgetsApp(title:)`.
361    pub fn title(mut self, title: impl Into<String>) -> FluentApp {
362        self.title = Some(title.into());
363        self
364    }
365
366    /// Dart `WidgetsApp(onGenerateTitle:)`.
367    pub fn on_generate_title(
368        mut self,
369        on_generate_title: impl Fn(&mut App, BuildContext) -> String + 'static,
370    ) -> FluentApp {
371        self.on_generate_title = Some(std::rc::Rc::new(on_generate_title));
372        self
373    }
374
375    /// The colour the old Android app switcher shows.
376    pub fn color(mut self, color: Color) -> FluentApp {
377        self.color = Some(color);
378        self
379    }
380
381    /// Dart `WidgetsApp(locale:)`.
382    pub fn locale(mut self, locale: Locale) -> FluentApp {
383        self.locale = Some(locale);
384        self
385    }
386
387    /// Dart `WidgetsApp(localizationsDelegates:)`.
388    pub fn localizations_delegates(
389        mut self,
390        delegates: impl IntoIterator<Item = LocalizationsDelegateRef>,
391    ) -> FluentApp {
392        self.localizations_delegates = Some(delegates.into_iter().collect());
393        self
394    }
395
396    /// Dart `WidgetsApp(localeListResolutionCallback:)`.
397    pub fn locale_list_resolution_callback(
398        mut self,
399        callback: impl Fn(Option<&[Locale]>, &[Locale]) -> Option<Locale> + 'static,
400    ) -> FluentApp {
401        self.locale_list_resolution_callback = Some(std::rc::Rc::new(callback));
402        self
403    }
404
405    /// Dart `WidgetsApp(localeResolutionCallback:)`.
406    pub fn locale_resolution_callback(
407        mut self,
408        callback: impl Fn(Option<&Locale>, &[Locale]) -> Option<Locale> + 'static,
409    ) -> FluentApp {
410        self.locale_resolution_callback = Some(std::rc::Rc::new(callback));
411        self
412    }
413
414    /// Dart `WidgetsApp(supportedLocales:)`.
415    pub fn supported_locales(mut self, locales: impl IntoIterator<Item = Locale>) -> FluentApp {
416        self.supported_locales = locales.into_iter().collect();
417        self
418    }
419
420    /// Dart `WidgetsApp(showPerformanceOverlay:)`.
421    pub fn show_performance_overlay(mut self, show: bool) -> FluentApp {
422        self.show_performance_overlay = show;
423        self
424    }
425
426    /// Dart `WidgetsApp(showSemanticsDebugger:)`.
427    pub fn show_semantics_debugger(mut self, show: bool) -> FluentApp {
428        self.show_semantics_debugger = show;
429        self
430    }
431
432    /// Dart `WidgetsApp(debugShowCheckedModeBanner:)`.
433    pub fn debug_show_checked_mode_banner(mut self, show: bool) -> FluentApp {
434        self.debug_show_checked_mode_banner = show;
435        self
436    }
437
438    /// Dart `WidgetsApp(shortcuts:)`.
439    pub fn shortcuts(mut self, shortcuts: ShortcutMap) -> FluentApp {
440        self.shortcuts = Some(shortcuts);
441        self
442    }
443
444    /// Dart `WidgetsApp(actions:)`.
445    pub fn actions(mut self, actions: HashMap<TypeId, ActionRef>) -> FluentApp {
446        self.actions = Some(actions);
447        self
448    }
449
450    /// Dart `WidgetsApp(restorationScopeId:)`.
451    pub fn restoration_scope_id(mut self, id: impl Into<String>) -> FluentApp {
452        self.restoration_scope_id = Some(id.into());
453        self
454    }
455}
456
457impl FluentAppState {
458    /// The theme the app shows now, from its mode and the platform's brightness.
459    fn effective_theme(
460        self: Handle<FluentAppState>,
461        app: &mut App,
462        context: BuildContext,
463    ) -> FluentTheme {
464        let (theme, dark_theme, mode) = {
465            let widget = self.widget(app);
466            (
467                widget.theme,
468                widget.dark_theme,
469                widget.theme_mode.unwrap_or_default(),
470            )
471        };
472        let dark = mode == FluentThemeMode::Dark
473            || (mode == FluentThemeMode::System
474                && MediaQuery::platform_brightness_of(app, context) == Brightness::Dark);
475        if dark {
476            dark_theme.or(theme).unwrap_or_else(FluentTheme::dark)
477        } else {
478            theme.unwrap_or_else(FluentTheme::light)
479        }
480    }
481
482    /// Builds the [`WidgetsApp`] this app is: its routes, its Fluent page routes and its title.
483    fn build_widget_app(
484        self: Handle<FluentAppState>,
485        app: &mut App,
486        context: BuildContext,
487    ) -> WidgetsApp {
488        let theme = self.effective_theme(app, context);
489        let widget = self.widget(app);
490        let color = widget.color.unwrap_or(theme.accent.base);
491
492        // The `WidgetsApp.router` branch waits with `router.dart`; see PORTING.md.
493        let mut widgets_app = WidgetsApp::new(color)
494            .key(GlobalKey::object(self.id()).into())
495            .navigator_observers(widget.navigator_observers.clone())
496            .page_route_builder(|app, settings, builder| {
497                let route = FluentPageRoute::new(app, builder)
498                    .settings(app, RouteSettingsRef::Settings(settings.clone()));
499                route.into_erased()
500            })
501            .routes(widget.routes.clone())
502            .supported_locales(widget.supported_locales.clone())
503            .show_performance_overlay(widget.show_performance_overlay)
504            .show_semantics_debugger(widget.show_semantics_debugger)
505            .debug_show_checked_mode_banner(widget.debug_show_checked_mode_banner)
506            .text_style(default_text_style(&theme));
507
508        if let Some(navigator_key) = widget.navigator_key.clone() {
509            widgets_app = widgets_app.navigator_key(navigator_key);
510        }
511        if let Some(home) = widget.home.clone() {
512            widgets_app = widgets_app.home(home);
513        }
514        if let Some(initial_route) = widget.initial_route.clone() {
515            widgets_app = widgets_app.initial_route(initial_route);
516        }
517        if let Some(on_generate_route) = widget.on_generate_route.clone() {
518            widgets_app = widgets_app
519                .on_generate_route(move |app, settings| on_generate_route(app, settings));
520        }
521        if let Some(on_generate_initial_routes) = widget.on_generate_initial_routes.clone() {
522            widgets_app = widgets_app
523                .on_generate_initial_routes(move |app, name| on_generate_initial_routes(app, name));
524        }
525        if let Some(on_unknown_route) = widget.on_unknown_route.clone() {
526            widgets_app =
527                widgets_app.on_unknown_route(move |app, settings| on_unknown_route(app, settings));
528        }
529        if let Some(on_navigation_notification) = widget.on_navigation_notification.clone() {
530            widgets_app = widgets_app.on_navigation_notification(move |app, notification| {
531                on_navigation_notification(app, notification)
532            });
533        }
534        if let Some(builder) = widget.builder.clone() {
535            widgets_app =
536                widgets_app.builder(move |app, context, child| builder(app, context, child));
537        }
538        if let Some(title) = widget.title.clone() {
539            widgets_app = widgets_app.title(title);
540        }
541        if let Some(on_generate_title) = widget.on_generate_title.clone() {
542            widgets_app =
543                widgets_app.on_generate_title(move |app, context| on_generate_title(app, context));
544        }
545        if let Some(locale) = widget.locale.clone() {
546            widgets_app = widgets_app.locale(locale);
547        }
548        if let Some(delegates) = widget.localizations_delegates.clone() {
549            widgets_app = widgets_app.localizations_delegates(delegates);
550        }
551        if let Some(callback) = widget.locale_resolution_callback.clone() {
552            widgets_app = widgets_app
553                .locale_resolution_callback(move |locale, supported| callback(locale, supported));
554        }
555        if let Some(callback) = widget.locale_list_resolution_callback.clone() {
556            widgets_app = widgets_app.locale_list_resolution_callback(move |locales, supported| {
557                callback(locales, supported)
558            });
559        }
560        if let Some(shortcuts) = widget.shortcuts.clone() {
561            widgets_app = widgets_app.shortcuts(shortcuts);
562        }
563        if let Some(actions) = widget.actions.clone() {
564            widgets_app = widgets_app.actions(actions);
565        }
566        if let Some(restoration_scope_id) = widget.restoration_scope_id.clone() {
567            widgets_app = widgets_app.restoration_scope_id(restoration_scope_id);
568        }
569        widgets_app
570    }
571}
572
573impl StatefulWidget for FluentApp {
574    type State = FluentAppState;
575
576    fn key(&self) -> Option<&KeyRef> {
577        self.key.as_ref()
578    }
579
580    fn create_state(&self) -> FluentAppState {
581        FluentAppState {
582            state: StateData::new(),
583        }
584    }
585}
586
587/// The state of a [`FluentApp`]: its widget's fields through [`State`].
588pub struct FluentAppState {
589    state: StateData<FluentApp>,
590}
591
592impl State for FluentAppState {
593    type Widget = FluentApp;
594    waft_widgets::state_accessors!();
595
596    fn init_state(self: Handle<Self>, app: &mut App) {
597        install_icon_font(app);
598    }
599
600    fn build(self: Handle<Self>, app: &mut App, context: BuildContext) -> WidgetRef {
601        let theme = self.effective_theme(app, context);
602        if let Some(view) = View::maybe_of(app, context) {
603            SystemChrome::set_system_ui_overlay_style(
604                app,
605                view.id(),
606                match theme.theme {
607                    Theme::Dark => &SystemUiOverlayStyle::LIGHT,
608                    Theme::Light => &SystemUiOverlayStyle::DARK,
609                },
610            );
611        }
612        let app = waft_widgets::Builder::new(move |app, context| {
613            self.build_widget_app(app, context).into_widget()
614        })
615        .into_widget();
616        let accent = theme.accent.base;
617        // Dart's `withOpacity`, deprecated there too: its rounding to an 8-bit alpha is part of
618        // the value being ported.
619        #[allow(deprecated)]
620        let selected = accent.with_opacity(0.4);
621        let selection = DefaultSelectionStyle::new(app)
622            .selection_color(selected)
623            .cursor_color(accent)
624            .into_widget();
625        let scrolling = ScrollConfiguration::new(
626            ScrollBehaviorRef::new(FluentScrollBehavior::new()),
627            selection,
628        )
629        .into_widget();
630        ThemeScope::new(theme.theme, scrolling)
631            .accent(theme.accent)
632            .into_widget()
633    }
634}
635
636/// WinUI's body text: the kit's content-control family, 14 points, and the theme's
637/// `TextFillColorPrimary`, which every `Text` without a style inherits.
638fn default_text_style(theme: &FluentTheme) -> TextStyle {
639    let resources = ThemeResources::new(theme.theme, theme.accent);
640    TextBlockStyle::Body.text_style(&resources, resources.text_fill_color_primary)
641}
642
643impl Debug for FluentApp {
644    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
645        formatter
646            .debug_struct("FluentApp")
647            .field("key", &self.key)
648            .field("home", &self.home)
649            .field("theme", &self.theme)
650            .field("darkTheme", &self.dark_theme)
651            .field("themeMode", &self.theme_mode)
652            .field("routes", &self.routes.keys().collect::<Vec<_>>())
653            .field("locale", &self.locale)
654            .field("restorationScopeId", &self.restoration_scope_id)
655            .finish_non_exhaustive()
656    }
657}