From c22269bff3085012d326a0df77bf27ad5bcb41b7 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 16 Mar 2024 05:33:47 +0100 Subject: Introduce `Program` API --- examples/checkbox/src/main.rs | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) (limited to 'examples/checkbox/src') diff --git a/examples/checkbox/src/main.rs b/examples/checkbox/src/main.rs index ee745c03..ed7b7f3a 100644 --- a/examples/checkbox/src/main.rs +++ b/examples/checkbox/src/main.rs @@ -1,12 +1,13 @@ -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(Example::update, Example::view) + .title("Checkbox - Iced") + .fonts([include_bytes!("../fonts/icons.ttf").as_slice().into()]) + .run() } #[derive(Default)] @@ -21,28 +22,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) { - ( - 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 { +impl Example { + fn update(&mut self, message: Message) { match message { Message::DefaultToggled(default) => { self.default = default; @@ -53,10 +36,7 @@ impl Application for Example { Message::CustomToggled(custom) => { self.custom = custom; } - Message::FontLoaded(_) => (), } - - Command::none() } fn view(&self) -> Element { -- cgit From bb71e8481ed59f991b9bd9dc55ea7e011ba0aac6 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 16 Mar 2024 16:12:07 +0100 Subject: Make `sandbox` helper take a `title` as well --- examples/checkbox/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples/checkbox/src') diff --git a/examples/checkbox/src/main.rs b/examples/checkbox/src/main.rs index ed7b7f3a..c9ee502e 100644 --- a/examples/checkbox/src/main.rs +++ b/examples/checkbox/src/main.rs @@ -4,8 +4,7 @@ use iced::{Element, Font, Length}; const ICON_FONT: Font = Font::with_name("icons"); pub fn main() -> iced::Result { - iced::sandbox(Example::update, Example::view) - .title("Checkbox - Iced") + iced::sandbox("Checkbox - Iced", Example::update, Example::view) .fonts([include_bytes!("../fonts/icons.ttf").as_slice().into()]) .run() } -- cgit From cfc0383bbfff083786840e3f1fd499e5991fa629 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 16 Mar 2024 16:58:48 +0100 Subject: Replace `Program::fonts` with simpler `font` method --- examples/checkbox/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/checkbox/src') diff --git a/examples/checkbox/src/main.rs b/examples/checkbox/src/main.rs index c9ee502e..8d18cb81 100644 --- a/examples/checkbox/src/main.rs +++ b/examples/checkbox/src/main.rs @@ -5,7 +5,7 @@ const ICON_FONT: Font = Font::with_name("icons"); pub fn main() -> iced::Result { iced::sandbox("Checkbox - Iced", Example::update, Example::view) - .fonts([include_bytes!("../fonts/icons.ttf").as_slice().into()]) + .font(include_bytes!("../fonts/icons.ttf").as_slice()) .run() } -- cgit