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>

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)
79
80
81
82
83
84
85
86
pub fn main() {
    let window = WindowDesc::new(build_app()).title("Very flexible");

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

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

Set the AppDelegate.

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

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

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

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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 Twhere U: From<T>,

const: unstable · 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.

§

impl<T> RoundFrom<T> for T

§

fn round_from(x: T) -> T

Performs the conversion.
§

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

§

fn round_into(self) -> U

Performs the conversion.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · 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