Skip to main content

workflow_egui/frame/
options.rs

1use crate::imports::*;
2
3/// Configuration for launching an application, covering the window caption,
4/// web canvas target, available modules and platform-specific eframe options.
5pub struct Options<T> {
6    /// Window title (native) caption for the application.
7    pub caption: String,
8    /// DOM id of the HTML canvas to mount the application into (web).
9    pub canvas_id: String,
10    /// Optional set of application modules to register.
11    pub modules: Option<Vec<Module<T>>>,
12    /// Identifier of the module to activate on startup, if any.
13    pub default_module: Option<TypeId>,
14
15    /// eframe native window options (native targets only).
16    #[cfg(not(target_arch = "wasm32"))]
17    pub native_options: eframe::NativeOptions,
18    #[cfg(target_arch = "wasm32")]
19    pub web_options: eframe::WebOptions,
20}
21
22impl<T> Options<T>
23where
24    T: App,
25{
26    /// Create options with the given window caption and web canvas id, leaving
27    /// modules and platform options at their defaults.
28    pub fn new(caption: String, canvas_id: String) -> Self {
29        Options {
30            caption,
31            canvas_id,
32            modules: None,
33            default_module: None,
34            #[cfg(not(target_arch = "wasm32"))]
35            native_options: Default::default(),
36            #[cfg(target_arch = "wasm32")]
37            web_options: Default::default(), // .. Default::default()
38        }
39    }
40
41    #[cfg(not(target_arch = "wasm32"))]
42    /// Override the eframe native window options (native targets only).
43    pub fn with_native_options(mut self, native_options: eframe::NativeOptions) -> Self {
44        self.native_options = native_options;
45        self
46    }
47
48    #[cfg(target_arch = "wasm32")]
49    pub fn with_web_options(mut self, web_options: eframe::WebOptions) -> Self {
50        self.web_options = web_options;
51        self
52    }
53
54    /// Register the application's modules and select the one identified by
55    /// `default_module` as the initially active module.
56    pub fn with_modules(mut self, default_module: TypeId, modules: Vec<Module<T>>) -> Self {
57        self.default_module = Some(default_module);
58        self.modules = Some(modules);
59        self
60    }
61}