Use Program API in modal example
This commit is contained in:
parent
59ef24f2c2
commit
32e1b2c5fc
1 changed files with 22 additions and 30 deletions
|
|
@ -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,14 +32,8 @@ 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>) {
|
||||
(
|
||||
impl App {
|
||||
fn new() -> Self {
|
||||
App {
|
||||
toasts: vec![Toast {
|
||||
title: "Example Toast".into(),
|
||||
|
|
@ -49,17 +41,11 @@ impl Application for App {
|
|||
status: Status::Primary,
|
||||
}],
|
||||
timeout_secs: toast::DEFAULT_TIMEOUT,
|
||||
..Default::default()
|
||||
},
|
||||
Command::none(),
|
||||
)
|
||||
editing: Toast::default(),
|
||||
}
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Toast - Iced")
|
||||
}
|
||||
|
||||
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};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue