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()
}
}
➡️ Next: Controlling Widgets By Commands
📘 Back: Table of contents