summaryrefslogtreecommitdiffstats
path: root/examples/toast
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-17 18:45:22 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-17 18:45:22 +0100
commit32e1b2c5fcb7b8c3698d97b4e189acaa363f63dd (patch)
treed29f5bad5a7bc72e3be7e83c5a29eb630b144043 /examples/toast
parent59ef24f2c27f762a5dff37e1cfd06c6f1cbb68cc (diff)
downloadiced-32e1b2c5fcb7b8c3698d97b4e189acaa363f63dd.tar.gz
iced-32e1b2c5fcb7b8c3698d97b4e189acaa363f63dd.tar.bz2
iced-32e1b2c5fcb7b8c3698d97b4e189acaa363f63dd.zip
Use `Program` API in `modal` example
Diffstat (limited to 'examples/toast')
-rw-r--r--examples/toast/src/main.rs52
1 files changed, 22 insertions, 30 deletions
diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs
index 5a07da3e..29a1c15c 100644
--- a/examples/toast/src/main.rs
+++ b/examples/toast/src/main.rs
@@ -1,21 +1,19 @@
use iced::event::{self, Event};
-use iced::executor;
use iced::keyboard;
use iced::keyboard::key;
use iced::widget::{
self, button, column, container, pick_list, row, slider, text, text_input,
};
-use iced::{
- Alignment, Application, Command, Element, Length, Settings, Subscription,
-};
+use iced::{Alignment, Command, Element, Length, Subscription};
use toast::{Status, Toast};
pub fn main() -> iced::Result {
- App::run(Settings::default())
+ iced::program("Toast - Iced", App::update, App::view)
+ .subscription(App::subscription)
+ .run()
}
-#[derive(Default)]
struct App {
toasts: Vec<Toast>,
editing: Toast,
@@ -34,32 +32,20 @@ enum Message {
Event(Event),
}
-impl Application for App {
- type Executor = executor::Default;
- type Message = Message;
- type Theme = iced::Theme;
- type Flags = ();
-
- fn new(_flags: ()) -> (Self, Command<Message>) {
- (
- App {
- toasts: vec![Toast {
- title: "Example Toast".into(),
- body: "Add more toasts in the form below!".into(),
- status: Status::Primary,
- }],
- timeout_secs: toast::DEFAULT_TIMEOUT,
- ..Default::default()
- },
- Command::none(),
- )
- }
-
- fn title(&self) -> String {
- String::from("Toast - Iced")
+impl App {
+ fn new() -> Self {
+ App {
+ toasts: vec![Toast {
+ title: "Example Toast".into(),
+ body: "Add more toasts in the form below!".into(),
+ status: Status::Primary,
+ }],
+ timeout_secs: toast::DEFAULT_TIMEOUT,
+ editing: Toast::default(),
+ }
}
- fn subscription(&self) -> Subscription<Self::Message> {
+ fn subscription(&self) -> Subscription<Message> {
event::listen().map(Message::Event)
}
@@ -172,6 +158,12 @@ impl Application for App {
}
}
+impl Default for App {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
mod toast {
use std::fmt;
use std::time::{Duration, Instant};