Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 2.46 KB

from_sandbox_to_application.md

File metadata and controls

48 lines (36 loc) · 2.46 KB

From Sandbox To Application

To have more control over our app, we can use Application trait, which is a generalization of Sandbox trait. There are two main differences between Application and Sandbox. One thing is the associated types. We have to specify Executor, Theme and Flags in addition to Message in Sandbox. Basically, we use the suggested defaults for these associated types. The other is that we have to return Command in new method and update method. We just return Command::none() for both methods.

use iced::{executor, Application, Command, Settings};

fn main() -> iced::Result {
    MyApp::run(Settings::default())
}

struct MyApp;

impl Application for MyApp {
    type Executor = executor::Default;
    type Message = ();
    type Theme = iced::Theme;
    type Flags = ();

    fn new(_flags: Self::Flags) -> (Self, iced::Command<Self::Message>) {
        (Self, Command::none())
    }

    fn title(&self) -> String {
        String::from("My App")
    }

    fn update(&mut self, _message: Self::Message) -> iced::Command<Self::Message> {
        Command::none()
    }

    fn view(&self) -> iced::Element<Self::Message> {
        "Hello World!".into()
    }
}

From sandbox to application

➡️ Next: Controlling Widgets By Commands

📘 Back: Table of contents