Struct druid::AppLauncher
source · 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?
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
pub fn main() {
//describe the main window
let main_window = WindowDesc::new(build_root_widget())
.title("Event Viewer")
.window_size((760.0, 680.0));
//start the application
AppLauncher::with_window(main_window)
.log_to_console()
.configure_env(|env, _| {
env.set(theme::UI_FONT, FontDescriptor::default().with_size(12.0));
env.set(theme::TEXT_COLOR, TEXT_COLOR);
env.set(theme::WIDGET_PADDING_HORIZONTAL, 2.0);
env.set(theme::WIDGET_PADDING_VERTICAL, 2.0);
})
.launch(AppState {
text_input: String::new(),
events: Arc::new(Vec::new()),
})
.expect("Failed to launch application");
}
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
38 39 40 41 42 43 44 45 46 47 48 49
pub fn main() {
let main_window = WindowDesc::new(ui_builder()).menu(make_menu).title(
LocalizedString::new("multiwin-demo-window-title").with_placeholder("Many windows!"),
);
AppLauncher::with_window(main_window)
.delegate(Delegate {
windows: Vec::new(),
})
.log_to_console()
.launch(State::default())
.expect("launch failed");
}
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
pub fn main() {
// describe the main window
let main_window = WindowDesc::new(build_root_widget())
.title(WINDOW_TITLE)
.menu(make_menu)
.window_size((700.0, 600.0));
// create the initial app state
let initial_state = AppState {
raw: TEXT.to_owned(),
rendered: rebuild_rendered_text(TEXT),
};
// start the application
AppLauncher::with_window(main_window)
.log_to_console()
.delegate(Delegate)
.launch(initial_state)
.expect("Failed to launch application");
}
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?
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
pub fn main() {
let window = WindowDesc::new(make_ui()).title("External Event Demo");
let launcher = AppLauncher::with_window(window);
// If we want to create commands from another thread `launcher.get_external_handle()`
// should be used. For sending commands from within widgets you can always call
// `ctx.submit_command`
let event_sink = launcher.get_external_handle();
// We create a new thread and generate colours in it.
// This happens on a second thread so that we can run the UI in the
// main thread. Generating some colours nicely follows the pattern for what
// should be done like this: generating something over time
// (like this or reacting to external events), or something that takes a
// long time and shouldn't block main UI updates.
thread::spawn(move || generate_colors(event_sink));
launcher
.log_to_console()
.launch(Color::BLACK)
.expect("launch failed");
}
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