summaryrefslogtreecommitdiffstats
path: root/examples/checkbox
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-16 05:33:47 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-16 05:33:47 +0100
commitc22269bff3085012d326a0df77bf27ad5bcb41b7 (patch)
tree1083f21d012ab2bac88fb51537d4dc431bc7f170 /examples/checkbox
parent0524e9b4571d264018656418f02a1f9e27e268d7 (diff)
downloadiced-c22269bff3085012d326a0df77bf27ad5bcb41b7.tar.gz
iced-c22269bff3085012d326a0df77bf27ad5bcb41b7.tar.bz2
iced-c22269bff3085012d326a0df77bf27ad5bcb41b7.zip
Introduce `Program` API
Diffstat (limited to 'examples/checkbox')
-rw-r--r--examples/checkbox/src/main.rs34
1 files changed, 7 insertions, 27 deletions
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<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 +36,7 @@ impl Application for Example {
Message::CustomToggled(custom) => {
self.custom = custom;
}
- Message::FontLoaded(_) => (),
}
-
- Command::none()
}
fn view(&self) -> Element<Message> {