diff options
author | 2024-03-16 17:09:00 +0100 | |
---|---|---|
committer | 2024-03-16 17:09:00 +0100 | |
commit | 503a48e89977437bf8b7bf485f416a15a2e83ed0 (patch) | |
tree | 30306bbaee7a31090ace9d7725d46c2c0027fe6b /examples/checkbox/src/main.rs | |
parent | 0524e9b4571d264018656418f02a1f9e27e268d7 (diff) | |
parent | cfc0383bbfff083786840e3f1fd499e5991fa629 (diff) | |
download | iced-503a48e89977437bf8b7bf485f416a15a2e83ed0.tar.gz iced-503a48e89977437bf8b7bf485f416a15a2e83ed0.tar.bz2 iced-503a48e89977437bf8b7bf485f416a15a2e83ed0.zip |
Merge pull request #2331 from iced-rs/program-api
`Program` API
Diffstat (limited to 'examples/checkbox/src/main.rs')
-rw-r--r-- | examples/checkbox/src/main.rs | 33 |
1 files changed, 6 insertions, 27 deletions
diff --git a/examples/checkbox/src/main.rs b/examples/checkbox/src/main.rs index ee745c03..8d18cb81 100644 --- a/examples/checkbox/src/main.rs +++ b/examples/checkbox/src/main.rs @@ -1,12 +1,12 @@ -use iced::executor; -use iced::font::{self, Font}; use iced::widget::{checkbox, column, container, row, text}; -use iced::{Application, Command, Element, Length, Settings, Theme}; +use iced::{Element, Font, Length}; const ICON_FONT: Font = Font::with_name("icons"); pub fn main() -> iced::Result { - Example::run(Settings::default()) + iced::sandbox("Checkbox - Iced", Example::update, Example::view) + .font(include_bytes!("../fonts/icons.ttf").as_slice()) + .run() } #[derive(Default)] @@ -21,28 +21,10 @@ enum Message { DefaultToggled(bool), CustomToggled(bool), StyledToggled(bool), - FontLoaded(Result<(), font::Error>), } -impl Application for Example { - type Message = Message; - type Flags = (); - type Executor = executor::Default; - type Theme = Theme; - - fn new(_flags: Self::Flags) -> (Self, Command<Message>) { - ( - Self::default(), - font::load(include_bytes!("../fonts/icons.ttf").as_slice()) - .map(Message::FontLoaded), - ) - } - - fn title(&self) -> String { - String::from("Checkbox - Iced") - } - - fn update(&mut self, message: Message) -> Command<Message> { +impl Example { + fn update(&mut self, message: Message) { match message { Message::DefaultToggled(default) => { self.default = default; @@ -53,10 +35,7 @@ impl Application for Example { Message::CustomToggled(custom) => { self.custom = custom; } - Message::FontLoaded(_) => (), } - - Command::none() } fn view(&self) -> Element<Message> { |