pub struct AppLauncher<T> { /* private fields */ }
Expand description
Handles initial setup of an application, and starts the runloop.
Implementations§
Source§impl<T: Data> AppLauncher<T>
impl<T: Data> AppLauncher<T>
Sourcepub fn with_window(window: WindowDesc<T>) -> Self
pub fn with_window(window: WindowDesc<T>) -> Self
Create a new AppLauncher
with the provided window.
Examples found in repository?
More examples
- examples/blocking_function.rs
- examples/panels.rs
- examples/svg.rs
- examples/anim.rs
- examples/scroll_colors.rs
- examples/view_switcher.rs
- examples/lens.rs
- examples/open_save.rs
- examples/switches.rs
- examples/transparency.rs
- examples/invalidation.rs
- examples/multiwin.rs
- examples/timer.rs
- examples/styled_text.rs
- examples/disabled.rs
- examples/z_stack.rs
- examples/list.rs
- examples/calc.rs
- examples/hello.rs
- examples/slider.rs
- examples/textbox.rs
- examples/markdown_preview.rs
- examples/sub_window.rs
- examples/tabs.rs
- examples/event_viewer.rs
- examples/game_of_life.rs
- examples/input_region.rs
- examples/flex.rs
- examples/async_event.rs
- examples/text.rs
Sourcepub fn configure_env(self, f: impl Fn(&mut Env, &T) + 'static) -> Self
pub fn configure_env(self, f: impl Fn(&mut Env, &T) + 'static) -> Self
Provide an optional closure that will be given mutable access to the environment and immutable access to the app state before launch.
This can be used to set or override theme values.
Examples found in repository?
331pub fn main() {
332 //describe the main window
333 let main_window = WindowDesc::new(build_root_widget())
334 .title("Event Viewer")
335 .window_size((760.0, 680.0));
336
337 //start the application
338 AppLauncher::with_window(main_window)
339 .log_to_console()
340 .configure_env(|env, _| {
341 env.set(theme::UI_FONT, FontDescriptor::default().with_size(12.0));
342 env.set(theme::TEXT_COLOR, TEXT_COLOR);
343 env.set(theme::WIDGET_PADDING_HORIZONTAL, 2.0);
344 env.set(theme::WIDGET_PADDING_VERTICAL, 2.0);
345 })
346 .launch(AppState {
347 text_input: String::new(),
348 events: Arc::new(Vec::new()),
349 })
350 .expect("Failed to launch application");
351}
Sourcepub fn delegate(self, delegate: impl AppDelegate<T> + 'static) -> Self
pub fn delegate(self, delegate: impl AppDelegate<T> + 'static) -> Self
Set the AppDelegate
.
Examples found in repository?
More examples
38pub fn main() {
39 let main_window = WindowDesc::new(ui_builder()).menu(make_menu).title(
40 LocalizedString::new("multiwin-demo-window-title").with_placeholder("Many windows!"),
41 );
42 AppLauncher::with_window(main_window)
43 .delegate(Delegate {
44 windows: Vec::new(),
45 })
46 .log_to_console()
47 .launch(State::default())
48 .expect("launch failed");
49}
94pub fn main() {
95 // describe the main window
96 let main_window = WindowDesc::new(build_root_widget())
97 .title(WINDOW_TITLE)
98 .menu(make_menu)
99 .window_size((700.0, 600.0));
100
101 // create the initial app state
102 let initial_state = AppState {
103 raw: TEXT.to_owned(),
104 rendered: rebuild_rendered_text(TEXT),
105 };
106
107 // start the application
108 AppLauncher::with_window(main_window)
109 .log_to_console()
110 .delegate(Delegate)
111 .launch(initial_state)
112 .expect("Failed to launch application");
113}
Sourcepub fn start_console_logging(self, enable: bool) -> Self
pub fn start_console_logging(self, enable: bool) -> Self
Initialize a minimal tracing subscriber with DEBUG max level for printing logs out to stderr.
This is meant for quick-and-dirty debugging. If you want more serious trace handling, it’s probably better to implement it yourself.
§Panics
Panics if enable
is true
and the subscriber fails to initialize,
for example if a tracing
/tracing_wasm
global logger was already set.
Never panics when enable
is false
, or have any other side effect.
Passing in false is useful if you want to enable a global logger as feature but log to console otherwise.
Sourcepub fn log_to_console(self) -> Self
pub fn log_to_console(self) -> Self
Calls start_console_logging
with true
.
Examples found in repository?
More examples
- examples/blocking_function.rs
- examples/panels.rs
- examples/svg.rs
- examples/anim.rs
- examples/scroll_colors.rs
- examples/view_switcher.rs
- examples/open_save.rs
- examples/switches.rs
- examples/transparency.rs
- examples/invalidation.rs
- examples/multiwin.rs
- examples/timer.rs
- examples/styled_text.rs
- examples/disabled.rs
- examples/z_stack.rs
- examples/list.rs
- examples/calc.rs
- examples/hello.rs
- examples/slider.rs
- examples/textbox.rs
- examples/markdown_preview.rs
- examples/sub_window.rs
- examples/tabs.rs
- examples/event_viewer.rs
- examples/game_of_life.rs
- examples/input_region.rs
- examples/flex.rs
- examples/async_event.rs
- examples/text.rs
Sourcepub fn localization_resources(
self,
resources: Vec<String>,
base_dir: String,
) -> Self
pub fn localization_resources( self, resources: Vec<String>, base_dir: String, ) -> Self
Use custom localization resource
resources
is a list of file names that contain strings. base_dir
is a path to a directory that includes per-locale subdirectories.
This directory should be of the structure base_dir/{locale}/{resource}
,
where ‘{locale}’ is a valid BCP47 language tag, and {resource} is a .ftl
included in resources
.
Sourcepub fn get_external_handle(&self) -> ExtEventSink
pub fn get_external_handle(&self) -> ExtEventSink
Returns an ExtEventSink
that can be moved between threads,
and can be used to submit commands back to the application.
Examples found in repository?
31pub fn main() {
32 let window = WindowDesc::new(make_ui()).title("External Event Demo");
33
34 let launcher = AppLauncher::with_window(window);
35
36 // If we want to create commands from another thread `launcher.get_external_handle()`
37 // should be used. For sending commands from within widgets you can always call
38 // `ctx.submit_command`
39 let event_sink = launcher.get_external_handle();
40 // We create a new thread and generate colours in it.
41 // This happens on a second thread so that we can run the UI in the
42 // main thread. Generating some colours nicely follows the pattern for what
43 // should be done like this: generating something over time
44 // (like this or reacting to external events), or something that takes a
45 // long time and shouldn't block main UI updates.
46 thread::spawn(move || generate_colors(event_sink));
47
48 launcher
49 .log_to_console()
50 .launch(Color::BLACK)
51 .expect("launch failed");
52}
Sourcepub fn launch(self, data: T) -> Result<(), PlatformError>
pub fn launch(self, data: T) -> Result<(), PlatformError>
Build the windows and start the runloop.
Returns an error if a window cannot be instantiated. This is usually a fatal error.
Examples found in repository?
More examples
- examples/blocking_function.rs
- examples/panels.rs
- examples/svg.rs
- examples/anim.rs
- examples/scroll_colors.rs
- examples/view_switcher.rs
- examples/lens.rs
- examples/open_save.rs
- examples/switches.rs
- examples/transparency.rs
- examples/invalidation.rs
- examples/multiwin.rs
- examples/timer.rs
- examples/styled_text.rs
- examples/disabled.rs
- examples/z_stack.rs
- examples/list.rs
- examples/calc.rs
- examples/hello.rs
- examples/slider.rs
- examples/textbox.rs
- examples/markdown_preview.rs
- examples/sub_window.rs
- examples/tabs.rs
- examples/event_viewer.rs
- examples/game_of_life.rs
- examples/input_region.rs
- examples/flex.rs
- examples/async_event.rs
- examples/text.rs