Struct 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>

Source

pub fn with_window(window: WindowDesc<T>) -> Self

Create a new AppLauncher with the provided window.

Examples found in repository?
examples/layout.rs (line 82)
79pub fn main() {
80    let window = WindowDesc::new(build_app()).title("Very flexible");
81
82    AppLauncher::with_window(window)
83        .log_to_console()
84        .launch(0)
85        .expect("launch failed");
86}
More examples
Hide additional examples
examples/either.rs (line 52)
50pub fn main() {
51    let main_window = WindowDesc::new(ui_builder()).title("Switcheroo");
52    AppLauncher::with_window(main_window)
53        .log_to_console()
54        .launch(AppState::default())
55        .expect("launch failed");
56}
examples/custom_widget.rs (line 158)
156pub fn main() {
157    let window = WindowDesc::new(CustomWidget {}).title(LocalizedString::new("Fancy Colors"));
158    AppLauncher::with_window(window)
159        .log_to_console()
160        .launch("Druid + Piet".to_string())
161        .expect("launch failed");
162}
examples/split_demo.rs (line 85)
82pub fn main() {
83    let window = WindowDesc::new(build_app())
84        .title(LocalizedString::new("split-demo-window-title").with_placeholder("Split Demo"));
85    AppLauncher::with_window(window)
86        .log_to_console()
87        .launch(0u32)
88        .expect("launch failed");
89}
examples/scroll.rs (line 30)
27pub fn main() {
28    let window = WindowDesc::new(build_widget())
29        .title(LocalizedString::new("scroll-demo-window-title").with_placeholder("Scroll demo"));
30    AppLauncher::with_window(window)
31        .log_to_console()
32        .launch(0u32)
33        .expect("launch failed");
34}
examples/identity.rs (line 51)
45pub fn main() {
46    let window = WindowDesc::new(make_ui()).title("identity example");
47    let data = OurData {
48        counter_one: 0,
49        counter_two: 0,
50    };
51    AppLauncher::with_window(window)
52        .log_to_console()
53        .launch(data)
54        .expect("launch failed");
55}
Source

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?
examples/event_viewer.rs (lines 340-345)
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}
Source

pub fn delegate(self, delegate: impl AppDelegate<T> + 'static) -> Self

Set the AppDelegate.

Examples found in repository?
examples/blocking_function.rs (line 109)
105fn main() {
106    let main_window =
107        WindowDesc::new(ui_builder()).title(LocalizedString::new("Blocking functions"));
108    AppLauncher::with_window(main_window)
109        .delegate(Delegate {})
110        .log_to_console()
111        .launch(AppState::default())
112        .expect("launch failed");
113}
More examples
Hide additional examples
examples/open_save.rs (line 33)
28pub fn main() {
29    let main_window = WindowDesc::new(ui_builder())
30        .title(LocalizedString::new("open-save-demo").with_placeholder("Opening/Saving Demo"));
31    let data = "Type here.".to_owned();
32    AppLauncher::with_window(main_window)
33        .delegate(Delegate)
34        .log_to_console()
35        .launch(data)
36        .expect("launch failed");
37}
examples/multiwin.rs (lines 43-45)
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}
examples/markdown_preview.rs (line 110)
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}
Source

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.

Source

pub fn log_to_console(self) -> Self

Calls start_console_logging with true.

Examples found in repository?
examples/layout.rs (line 83)
79pub fn main() {
80    let window = WindowDesc::new(build_app()).title("Very flexible");
81
82    AppLauncher::with_window(window)
83        .log_to_console()
84        .launch(0)
85        .expect("launch failed");
86}
More examples
Hide additional examples
examples/either.rs (line 53)
50pub fn main() {
51    let main_window = WindowDesc::new(ui_builder()).title("Switcheroo");
52    AppLauncher::with_window(main_window)
53        .log_to_console()
54        .launch(AppState::default())
55        .expect("launch failed");
56}
examples/custom_widget.rs (line 159)
156pub fn main() {
157    let window = WindowDesc::new(CustomWidget {}).title(LocalizedString::new("Fancy Colors"));
158    AppLauncher::with_window(window)
159        .log_to_console()
160        .launch("Druid + Piet".to_string())
161        .expect("launch failed");
162}
examples/split_demo.rs (line 86)
82pub fn main() {
83    let window = WindowDesc::new(build_app())
84        .title(LocalizedString::new("split-demo-window-title").with_placeholder("Split Demo"));
85    AppLauncher::with_window(window)
86        .log_to_console()
87        .launch(0u32)
88        .expect("launch failed");
89}
examples/scroll.rs (line 31)
27pub fn main() {
28    let window = WindowDesc::new(build_widget())
29        .title(LocalizedString::new("scroll-demo-window-title").with_placeholder("Scroll demo"));
30    AppLauncher::with_window(window)
31        .log_to_console()
32        .launch(0u32)
33        .expect("launch failed");
34}
examples/identity.rs (line 52)
45pub fn main() {
46    let window = WindowDesc::new(make_ui()).title("identity example");
47    let data = OurData {
48        counter_one: 0,
49        counter_two: 0,
50    };
51    AppLauncher::with_window(window)
52        .log_to_console()
53        .launch(data)
54        .expect("launch failed");
55}
Source

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.

Source

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?
examples/async_event.rs (line 39)
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}
Source

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?
examples/layout.rs (line 84)
79pub fn main() {
80    let window = WindowDesc::new(build_app()).title("Very flexible");
81
82    AppLauncher::with_window(window)
83        .log_to_console()
84        .launch(0)
85        .expect("launch failed");
86}
More examples
Hide additional examples
examples/either.rs (line 54)
50pub fn main() {
51    let main_window = WindowDesc::new(ui_builder()).title("Switcheroo");
52    AppLauncher::with_window(main_window)
53        .log_to_console()
54        .launch(AppState::default())
55        .expect("launch failed");
56}
examples/custom_widget.rs (line 160)
156pub fn main() {
157    let window = WindowDesc::new(CustomWidget {}).title(LocalizedString::new("Fancy Colors"));
158    AppLauncher::with_window(window)
159        .log_to_console()
160        .launch("Druid + Piet".to_string())
161        .expect("launch failed");
162}
examples/split_demo.rs (line 87)
82pub fn main() {
83    let window = WindowDesc::new(build_app())
84        .title(LocalizedString::new("split-demo-window-title").with_placeholder("Split Demo"));
85    AppLauncher::with_window(window)
86        .log_to_console()
87        .launch(0u32)
88        .expect("launch failed");
89}
examples/scroll.rs (line 32)
27pub fn main() {
28    let window = WindowDesc::new(build_widget())
29        .title(LocalizedString::new("scroll-demo-window-title").with_placeholder("Scroll demo"));
30    AppLauncher::with_window(window)
31        .log_to_console()
32        .launch(0u32)
33        .expect("launch failed");
34}
examples/identity.rs (line 53)
45pub fn main() {
46    let window = WindowDesc::new(make_ui()).title("identity example");
47    let data = OurData {
48        counter_one: 0,
49        counter_two: 0,
50    };
51    AppLauncher::with_window(window)
52        .log_to_console()
53        .launch(data)
54        .expect("launch failed");
55}

Auto Trait Implementations§

§

impl<T> Freeze for AppLauncher<T>

§

impl<T> !RefUnwindSafe for AppLauncher<T>

§

impl<T> !Send for AppLauncher<T>

§

impl<T> !Sync for AppLauncher<T>

§

impl<T> Unpin for AppLauncher<T>
where T: Unpin,

§

impl<T> !UnwindSafe for AppLauncher<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> RoundFrom<T> for T

Source§

fn round_from(x: T) -> T

Performs the conversion.
Source§

impl<T, U> RoundInto<U> for T
where U: RoundFrom<T>,

Source§

fn round_into(self) -> U

Performs the conversion.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more