diff options
author | 2024-03-16 05:33:47 +0100 | |
---|---|---|
committer | 2024-03-16 05:33:47 +0100 | |
commit | c22269bff3085012d326a0df77bf27ad5bcb41b7 (patch) | |
tree | 1083f21d012ab2bac88fb51537d4dc431bc7f170 /examples/download_progress | |
parent | 0524e9b4571d264018656418f02a1f9e27e268d7 (diff) | |
download | iced-c22269bff3085012d326a0df77bf27ad5bcb41b7.tar.gz iced-c22269bff3085012d326a0df77bf27ad5bcb41b7.tar.bz2 iced-c22269bff3085012d326a0df77bf27ad5bcb41b7.zip |
Introduce `Program` API
Diffstat (limited to 'examples/download_progress')
-rw-r--r-- | examples/download_progress/src/main.rs | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/examples/download_progress/src/main.rs b/examples/download_progress/src/main.rs index 675e9e26..bddf0d28 100644 --- a/examples/download_progress/src/main.rs +++ b/examples/download_progress/src/main.rs @@ -1,14 +1,13 @@ -use iced::executor; -use iced::widget::{button, column, container, progress_bar, text, Column}; -use iced::{ - Alignment, Application, Command, Element, Length, Settings, Subscription, - Theme, -}; - mod download; +use iced::widget::{button, column, container, progress_bar, text, Column}; +use iced::{Alignment, Element, Length, Subscription}; + pub fn main() -> iced::Result { - Example::run(Settings::default()) + iced::sandbox(Example::update, Example::view) + .subscription(Example::subscription) + .title("Download Progress - Iced") + .run() } #[derive(Debug)] @@ -24,27 +23,15 @@ pub enum Message { DownloadProgressed((usize, download::Progress)), } -impl Application for Example { - type Message = Message; - type Theme = Theme; - type Executor = executor::Default; - type Flags = (); - - fn new(_flags: ()) -> (Example, Command<Message>) { - ( - Example { - downloads: vec![Download::new(0)], - last_id: 0, - }, - Command::none(), - ) - } - - fn title(&self) -> String { - String::from("Download progress - Iced") +impl Example { + fn new() -> Self { + Self { + downloads: vec![Download::new(0)], + last_id: 0, + } } - fn update(&mut self, message: Message) -> Command<Message> { + fn update(&mut self, message: Message) { match message { Message::Add => { self.last_id += 1; @@ -63,9 +50,7 @@ impl Application for Example { download.progress(progress); } } - }; - - Command::none() + } } fn subscription(&self) -> Subscription<Message> { @@ -93,6 +78,12 @@ impl Application for Example { } } +impl Default for Example { + fn default() -> Self { + Self::new() + } +} + #[derive(Debug)] struct Download { id: usize, |