Support async actions in iced_winit

This commit is contained in:
Héctor Ramón Jiménez 2019-11-17 07:09:46 +01:00
parent e640b87590
commit 02c20e6202
7 changed files with 110 additions and 47 deletions

View file

@ -1,12 +1,12 @@
use iced::{
button, scrollable, Align, Application, Button, Container, Element, Image,
Length, Scrollable, Text,
button, scrollable, Align, Application, Button, Command, Container,
Element, Image, Length, Scrollable, Text,
};
pub fn main() {
env_logger::init();
Example::default().run()
Example::run()
}
#[derive(Default)]
@ -25,16 +25,22 @@ pub enum Message {
impl Application for Example {
type Message = Message;
fn new() -> (Example, Command<Message>) {
(Example::default(), Command::none())
}
fn title(&self) -> String {
String::from("Scroll - Iced")
}
fn update(&mut self, message: Message) {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::AddItem => {
self.item_count += 1;
}
}
Command::none()
}
fn view(&mut self) -> Element<Message> {

View file

@ -1,11 +1,11 @@
use iced::{
button, scrollable, text::HorizontalAlignment, text_input, Align,
Application, Background, Button, Checkbox, Color, Column, Container,
Element, Font, Length, Row, Scrollable, Text, TextInput,
Application, Background, Button, Checkbox, Color, Column, Command,
Container, Element, Font, Length, Row, Scrollable, Text, TextInput,
};
pub fn main() {
Todos::default().run()
Todos::run()
}
#[derive(Debug, Default)]
@ -29,11 +29,15 @@ pub enum Message {
impl Application for Todos {
type Message = Message;
fn new() -> (Todos, Command<Message>) {
(Todos::default(), Command::none())
}
fn title(&self) -> String {
String::from("Todos - Iced")
}
fn update(&mut self, message: Message) {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::InputChanged(value) => {
self.input_value = value;
@ -58,6 +62,8 @@ impl Application for Todos {
}
dbg!(self);
Command::none()
}
fn view(&mut self) -> Element<Message> {

View file

@ -1,13 +1,14 @@
use iced::{
button, scrollable, slider, text::HorizontalAlignment, text_input,
Application, Background, Button, Checkbox, Color, Column, Container,
Element, Image, Length, Radio, Row, Scrollable, Slider, Text, TextInput,
Application, Background, Button, Checkbox, Color, Column, Command,
Container, Element, Image, Length, Radio, Row, Scrollable, Slider, Text,
TextInput,
};
pub fn main() {
env_logger::init();
Tour::new().run()
Tour::run()
}
pub struct Tour {
@ -18,26 +19,27 @@ pub struct Tour {
debug: bool,
}
impl Tour {
pub fn new() -> Tour {
Tour {
steps: Steps::new(),
scroll: scrollable::State::new(),
back_button: button::State::new(),
next_button: button::State::new(),
debug: true,
}
}
}
impl Application for Tour {
type Message = Message;
fn new() -> (Tour, Command<Message>) {
(
Tour {
steps: Steps::new(),
scroll: scrollable::State::new(),
back_button: button::State::new(),
next_button: button::State::new(),
debug: true,
},
Command::none(),
)
}
fn title(&self) -> String {
format!("{} - Iced", self.steps.title())
}
fn update(&mut self, event: Message) {
fn update(&mut self, event: Message) -> Command<Message> {
match event {
Message::BackPressed => {
self.steps.go_back();
@ -49,6 +51,8 @@ impl Application for Tour {
self.steps.update(step_msg, &mut self.debug);
}
}
Command::none()
}
fn view(&mut self) -> Element<Message> {