Introduce Program API
This commit is contained in:
parent
0524e9b457
commit
c22269bff3
43 changed files with 1141 additions and 831 deletions
|
|
@ -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(),
|
||||
)
|
||||
impl Example {
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
downloads: vec![Download::new(0)],
|
||||
last_id: 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Download progress - Iced")
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue