Use Program API in modal example

This commit is contained in:
Héctor Ramón Jiménez 2024-03-17 18:45:22 +01:00
parent 59ef24f2c2
commit 32e1b2c5fc
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -1,21 +1,19 @@
use iced::event::{self, Event}; use iced::event::{self, Event};
use iced::executor;
use iced::keyboard; use iced::keyboard;
use iced::keyboard::key; use iced::keyboard::key;
use iced::widget::{ use iced::widget::{
self, button, column, container, pick_list, row, slider, text, text_input, self, button, column, container, pick_list, row, slider, text, text_input,
}; };
use iced::{ use iced::{Alignment, Command, Element, Length, Subscription};
Alignment, Application, Command, Element, Length, Settings, Subscription,
};
use toast::{Status, Toast}; use toast::{Status, Toast};
pub fn main() -> iced::Result { 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 { struct App {
toasts: Vec<Toast>, toasts: Vec<Toast>,
editing: Toast, editing: Toast,
@ -34,14 +32,8 @@ enum Message {
Event(Event), Event(Event),
} }
impl Application for App { impl App {
type Executor = executor::Default; fn new() -> Self {
type Message = Message;
type Theme = iced::Theme;
type Flags = ();
fn new(_flags: ()) -> (Self, Command<Message>) {
(
App { App {
toasts: vec![Toast { toasts: vec![Toast {
title: "Example Toast".into(), title: "Example Toast".into(),
@ -49,17 +41,11 @@ impl Application for App {
status: Status::Primary, status: Status::Primary,
}], }],
timeout_secs: toast::DEFAULT_TIMEOUT, timeout_secs: toast::DEFAULT_TIMEOUT,
..Default::default() editing: Toast::default(),
}, }
Command::none(),
)
} }
fn title(&self) -> String { fn subscription(&self) -> Subscription<Message> {
String::from("Toast - Iced")
}
fn subscription(&self) -> Subscription<Self::Message> {
event::listen().map(Message::Event) event::listen().map(Message::Event)
} }
@ -172,6 +158,12 @@ impl Application for App {
} }
} }
impl Default for App {
fn default() -> Self {
Self::new()
}
}
mod toast { mod toast {
use std::fmt; use std::fmt;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};