summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2024-06-16 20:24:41 +0200
committerLibravatar GitHub <noreply@github.com>2024-06-16 20:24:41 +0200
commit95d4adb55e485c01eec839736f328be26f2ccab6 (patch)
tree2676e3cb8ec17c5bf1cd561d97932ae302551dfd /examples
parente6d0b3bda5042a1017a5944a5227c97e0ed6caf9 (diff)
parentb5c5a016c4f2b608a740b37c494186557a064f48 (diff)
downloadiced-95d4adb55e485c01eec839736f328be26f2ccab6.tar.gz
iced-95d4adb55e485c01eec839736f328be26f2ccab6.tar.bz2
iced-95d4adb55e485c01eec839736f328be26f2ccab6.zip
Merge pull request #2463 from iced-rs/task-api
`Task` API
Diffstat (limited to '')
-rw-r--r--examples/editor/src/main.rs26
-rw-r--r--examples/events/src/main.rs10
-rw-r--r--examples/exit/src/main.rs6
-rw-r--r--examples/game_of_life/src/main.rs8
-rw-r--r--examples/integration/src/controls.rs6
-rw-r--r--examples/loading_spinners/src/easing.rs5
-rw-r--r--examples/modal/src/main.rs18
-rw-r--r--examples/multi_window/src/main.rs166
-rw-r--r--examples/pokedex/src/main.rs14
-rw-r--r--examples/screenshot/src/main.rs18
-rw-r--r--examples/scrollable/src/main.rs12
-rw-r--r--examples/system_information/src/main.rs9
-rw-r--r--examples/toast/src/main.rs22
-rw-r--r--examples/todos/src/main.rs2
-rw-r--r--examples/visible_bounds/src/main.rs14
-rw-r--r--examples/websocket/src/main.rs22
16 files changed, 169 insertions, 189 deletions
diff --git a/examples/editor/src/main.rs b/examples/editor/src/main.rs
index c20a7d67..ec65e2fa 100644
--- a/examples/editor/src/main.rs
+++ b/examples/editor/src/main.rs
@@ -4,7 +4,7 @@ use iced::widget::{
button, column, container, horizontal_space, pick_list, row, text,
text_editor, tooltip,
};
-use iced::{Alignment, Command, Element, Font, Length, Subscription, Theme};
+use iced::{Alignment, Element, Font, Length, Subscription, Task, Theme};
use std::ffi;
use std::io;
@@ -51,26 +51,26 @@ impl Editor {
}
}
- fn load() -> Command<Message> {
- Command::perform(
+ fn load() -> Task<Message> {
+ Task::perform(
load_file(format!("{}/src/main.rs", env!("CARGO_MANIFEST_DIR"))),
Message::FileOpened,
)
}
- fn update(&mut self, message: Message) -> Command<Message> {
+ fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::ActionPerformed(action) => {
self.is_dirty = self.is_dirty || action.is_edit();
self.content.perform(action);
- Command::none()
+ Task::none()
}
Message::ThemeSelected(theme) => {
self.theme = theme;
- Command::none()
+ Task::none()
}
Message::NewFile => {
if !self.is_loading {
@@ -78,15 +78,15 @@ impl Editor {
self.content = text_editor::Content::new();
}
- Command::none()
+ Task::none()
}
Message::OpenFile => {
if self.is_loading {
- Command::none()
+ Task::none()
} else {
self.is_loading = true;
- Command::perform(open_file(), Message::FileOpened)
+ Task::perform(open_file(), Message::FileOpened)
}
}
Message::FileOpened(result) => {
@@ -98,15 +98,15 @@ impl Editor {
self.content = text_editor::Content::with_text(&contents);
}
- Command::none()
+ Task::none()
}
Message::SaveFile => {
if self.is_loading {
- Command::none()
+ Task::none()
} else {
self.is_loading = true;
- Command::perform(
+ Task::perform(
save_file(self.file.clone(), self.content.text()),
Message::FileSaved,
)
@@ -120,7 +120,7 @@ impl Editor {
self.is_dirty = false;
}
- Command::none()
+ Task::none()
}
}
}
diff --git a/examples/events/src/main.rs b/examples/events/src/main.rs
index bacd8e6e..504ed5d8 100644
--- a/examples/events/src/main.rs
+++ b/examples/events/src/main.rs
@@ -2,7 +2,7 @@ use iced::alignment;
use iced::event::{self, Event};
use iced::widget::{button, center, checkbox, text, Column};
use iced::window;
-use iced::{Alignment, Command, Element, Length, Subscription};
+use iced::{Alignment, Element, Length, Subscription, Task};
pub fn main() -> iced::Result {
iced::program("Events - Iced", Events::update, Events::view)
@@ -25,7 +25,7 @@ enum Message {
}
impl Events {
- fn update(&mut self, message: Message) -> Command<Message> {
+ fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::EventOccurred(event) if self.enabled => {
self.last.push(event);
@@ -34,19 +34,19 @@ impl Events {
let _ = self.last.remove(0);
}
- Command::none()
+ Task::none()
}
Message::EventOccurred(event) => {
if let Event::Window(window::Event::CloseRequested) = event {
window::close(window::Id::MAIN)
} else {
- Command::none()
+ Task::none()
}
}
Message::Toggled(enabled) => {
self.enabled = enabled;
- Command::none()
+ Task::none()
}
Message::Exit => window::close(window::Id::MAIN),
}
diff --git a/examples/exit/src/main.rs b/examples/exit/src/main.rs
index 2de97e20..8ba180a5 100644
--- a/examples/exit/src/main.rs
+++ b/examples/exit/src/main.rs
@@ -1,6 +1,6 @@
use iced::widget::{button, center, column};
use iced::window;
-use iced::{Alignment, Command, Element};
+use iced::{Alignment, Element, Task};
pub fn main() -> iced::Result {
iced::program("Exit - Iced", Exit::update, Exit::view).run()
@@ -18,13 +18,13 @@ enum Message {
}
impl Exit {
- fn update(&mut self, message: Message) -> Command<Message> {
+ fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::Confirm => window::close(window::Id::MAIN),
Message::Exit => {
self.show_confirm = true;
- Command::none()
+ Task::none()
}
}
}
diff --git a/examples/game_of_life/src/main.rs b/examples/game_of_life/src/main.rs
index 8f1f7a54..7e6d461d 100644
--- a/examples/game_of_life/src/main.rs
+++ b/examples/game_of_life/src/main.rs
@@ -9,7 +9,7 @@ use iced::time;
use iced::widget::{
button, checkbox, column, container, pick_list, row, slider, text,
};
-use iced::{Alignment, Command, Element, Length, Subscription, Theme};
+use iced::{Alignment, Element, Length, Subscription, Task, Theme};
use std::time::Duration;
pub fn main() -> iced::Result {
@@ -56,7 +56,7 @@ impl GameOfLife {
}
}
- fn update(&mut self, message: Message) -> Command<Message> {
+ fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::Grid(message, version) => {
if version == self.version {
@@ -75,7 +75,7 @@ impl GameOfLife {
let version = self.version;
- return Command::perform(task, move |message| {
+ return Task::perform(task, move |message| {
Message::Grid(message, version)
});
}
@@ -103,7 +103,7 @@ impl GameOfLife {
}
}
- Command::none()
+ Task::none()
}
fn subscription(&self) -> Subscription<Message> {
diff --git a/examples/integration/src/controls.rs b/examples/integration/src/controls.rs
index 1958b2f3..d0654996 100644
--- a/examples/integration/src/controls.rs
+++ b/examples/integration/src/controls.rs
@@ -2,7 +2,7 @@ use iced_wgpu::Renderer;
use iced_widget::{column, container, row, slider, text, text_input};
use iced_winit::core::alignment;
use iced_winit::core::{Color, Element, Length, Theme};
-use iced_winit::runtime::{Command, Program};
+use iced_winit::runtime::{Program, Task};
pub struct Controls {
background_color: Color,
@@ -33,7 +33,7 @@ impl Program for Controls {
type Message = Message;
type Renderer = Renderer;
- fn update(&mut self, message: Message) -> Command<Message> {
+ fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::BackgroundColorChanged(color) => {
self.background_color = color;
@@ -43,7 +43,7 @@ impl Program for Controls {
}
}
- Command::none()
+ Task::none()
}
fn view(&self) -> Element<Message, Theme, Renderer> {
diff --git a/examples/loading_spinners/src/easing.rs b/examples/loading_spinners/src/easing.rs
index 665b3329..45089ef6 100644
--- a/examples/loading_spinners/src/easing.rs
+++ b/examples/loading_spinners/src/easing.rs
@@ -119,10 +119,7 @@ impl Builder {
fn point(p: impl Into<Point>) -> lyon_algorithms::geom::Point<f32> {
let p: Point = p.into();
- lyon_algorithms::geom::point(
- p.x.min(1.0).max(0.0),
- p.y.min(1.0).max(0.0),
- )
+ lyon_algorithms::geom::point(p.x.clamp(0.0, 1.0), p.y.clamp(0.0, 1.0))
}
}
diff --git a/examples/modal/src/main.rs b/examples/modal/src/main.rs
index a012c310..d185cf3b 100644
--- a/examples/modal/src/main.rs
+++ b/examples/modal/src/main.rs
@@ -5,7 +5,7 @@ use iced::widget::{
self, button, center, column, container, horizontal_space, mouse_area,
opaque, pick_list, row, stack, text, text_input,
};
-use iced::{Alignment, Color, Command, Element, Length, Subscription};
+use iced::{Alignment, Color, Element, Length, Subscription, Task};
use std::fmt;
@@ -39,7 +39,7 @@ impl App {
event::listen().map(Message::Event)
}
- fn update(&mut self, message: Message) -> Command<Message> {
+ fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::ShowModal => {
self.show_modal = true;
@@ -47,26 +47,26 @@ impl App {
}
Message::HideModal => {
self.hide_modal();
- Command::none()
+ Task::none()
}
Message::Email(email) => {
self.email = email;
- Command::none()
+ Task::none()
}
Message::Password(password) => {
self.password = password;
- Command::none()
+ Task::none()
}
Message::Plan(plan) => {
self.plan = plan;
- Command::none()
+ Task::none()
}
Message::Submit => {
if !self.email.is_empty() && !self.password.is_empty() {
self.hide_modal();
}
- Command::none()
+ Task::none()
}
Message::Event(event) => match event {
Event::Keyboard(keyboard::Event::KeyPressed {
@@ -85,9 +85,9 @@ impl App {
..
}) => {
self.hide_modal();
- Command::none()
+ Task::none()
}
- _ => Command::none(),
+ _ => Task::none(),
},
}
}
diff --git a/examples/multi_window/src/main.rs b/examples/multi_window/src/main.rs
index eb74c94a..b82ad1f3 100644
--- a/examples/multi_window/src/main.rs
+++ b/examples/multi_window/src/main.rs
@@ -1,16 +1,15 @@
-use iced::event;
use iced::executor;
use iced::multi_window::{self, Application};
use iced::widget::{
- button, center, column, container, scrollable, text, text_input,
+ button, center, column, container, horizontal_space, scrollable, text,
+ text_input,
};
use iced::window;
use iced::{
- Alignment, Command, Element, Length, Point, Settings, Subscription, Theme,
- Vector,
+ Alignment, Element, Length, Settings, Subscription, Task, Theme, Vector,
};
-use std::collections::HashMap;
+use std::collections::BTreeMap;
fn main() -> iced::Result {
Example::run(Settings::default())
@@ -18,8 +17,7 @@ fn main() -> iced::Result {
#[derive(Default)]
struct Example {
- windows: HashMap<window::Id, Window>,
- next_window_pos: window::Position,
+ windows: BTreeMap<window::Id, Window>,
}
#[derive(Debug)]
@@ -33,13 +31,12 @@ struct Window {
#[derive(Debug, Clone)]
enum Message {
+ OpenWindow,
+ WindowOpened(window::Id),
+ WindowClosed(window::Id),
ScaleInputChanged(window::Id, String),
ScaleChanged(window::Id, String),
TitleChanged(window::Id, String),
- CloseWindow(window::Id),
- WindowOpened(window::Id, Option<Point>),
- WindowClosed(window::Id),
- NewWindow,
}
impl multi_window::Application for Example {
@@ -48,13 +45,12 @@ impl multi_window::Application for Example {
type Theme = Theme;
type Flags = ();
- fn new(_flags: ()) -> (Self, Command<Message>) {
+ fn new(_flags: ()) -> (Self, Task<Message>) {
(
Example {
- windows: HashMap::from([(window::Id::MAIN, Window::new(1))]),
- next_window_pos: window::Position::Default,
+ windows: BTreeMap::from([(window::Id::MAIN, Window::new(1))]),
},
- Command::none(),
+ Task::none(),
)
}
@@ -62,79 +58,88 @@ impl multi_window::Application for Example {
self.windows
.get(&window)
.map(|window| window.title.clone())
- .unwrap_or("Example".to_string())
+ .unwrap_or_default()
}
- fn update(&mut self, message: Message) -> Command<Message> {
+ fn update(&mut self, message: Message) -> Task<Message> {
match message {
- Message::ScaleInputChanged(id, scale) => {
- let window =
- self.windows.get_mut(&id).expect("Window not found!");
- window.scale_input = scale;
-
- Command::none()
- }
- Message::ScaleChanged(id, scale) => {
- let window =
- self.windows.get_mut(&id).expect("Window not found!");
-
- window.current_scale = scale
- .parse::<f64>()
- .unwrap_or(window.current_scale)
- .clamp(0.5, 5.0);
-
- Command::none()
+ Message::OpenWindow => {
+ let Some(last_window) = self.windows.keys().last() else {
+ return Task::none();
+ };
+
+ window::fetch_position(*last_window)
+ .then(|last_position| {
+ let position = last_position.map_or(
+ window::Position::Default,
+ |last_position| {
+ window::Position::Specific(
+ last_position + Vector::new(20.0, 20.0),
+ )
+ },
+ );
+
+ window::open(window::Settings {
+ position,
+ ..window::Settings::default()
+ })
+ })
+ .map(Message::WindowOpened)
}
- Message::TitleChanged(id, title) => {
- let window =
- self.windows.get_mut(&id).expect("Window not found.");
+ Message::WindowOpened(id) => {
+ let window = Window::new(self.windows.len() + 1);
+ let focus_input = text_input::focus(window.input_id.clone());
- window.title = title;
+ self.windows.insert(id, window);
- Command::none()
+ focus_input
}
- Message::CloseWindow(id) => window::close(id),
Message::WindowClosed(id) => {
self.windows.remove(&id);
- Command::none()
+
+ Task::none()
}
- Message::WindowOpened(id, position) => {
- if let Some(position) = position {
- self.next_window_pos = window::Position::Specific(
- position + Vector::new(20.0, 20.0),
- );
+ Message::ScaleInputChanged(id, scale) => {
+ if let Some(window) = self.windows.get_mut(&id) {
+ window.scale_input = scale;
}
- if let Some(window) = self.windows.get(&id) {
- text_input::focus(window.input_id.clone())
- } else {
- Command::none()
- }
+ Task::none()
}
- Message::NewWindow => {
- let count = self.windows.len() + 1;
-
- let (id, spawn_window) = window::spawn(window::Settings {
- position: self.next_window_pos,
- exit_on_close_request: count % 2 == 0,
- ..Default::default()
- });
+ Message::ScaleChanged(id, scale) => {
+ if let Some(window) = self.windows.get_mut(&id) {
+ window.current_scale = scale
+ .parse::<f64>()
+ .unwrap_or(window.current_scale)
+ .clamp(0.5, 5.0);
+ }
- self.windows.insert(id, Window::new(count));
+ Task::none()
+ }
+ Message::TitleChanged(id, title) => {
+ if let Some(window) = self.windows.get_mut(&id) {
+ window.title = title;
+ }
- spawn_window
+ Task::none()
}
}
}
- fn view(&self, window: window::Id) -> Element<Message> {
- let content = self.windows.get(&window).unwrap().view(window);
-
- center(content).into()
+ fn view(&self, window_id: window::Id) -> Element<Message> {
+ if let Some(window) = self.windows.get(&window_id) {
+ center(window.view(window_id)).into()
+ } else {
+ horizontal_space().into()
+ }
}
- fn theme(&self, window: window::Id) -> Self::Theme {
- self.windows.get(&window).unwrap().theme.clone()
+ fn theme(&self, window: window::Id) -> Theme {
+ if let Some(window) = self.windows.get(&window) {
+ window.theme.clone()
+ } else {
+ Theme::default()
+ }
}
fn scale_factor(&self, window: window::Id) -> f64 {
@@ -145,24 +150,7 @@ impl multi_window::Application for Example {
}
fn subscription(&self) -> Subscription<Self::Message> {
- event::listen_with(|event, _, window| {
- if let iced::Event::Window(window_event) = event {
- match window_event {
- window::Event::CloseRequested => {
- Some(Message::CloseWindow(window))
- }
- window::Event::Opened { position, .. } => {
- Some(Message::WindowOpened(window, position))
- }
- window::Event::Closed => {
- Some(Message::WindowClosed(window))
- }
- _ => None,
- }
- } else {
- None
- }
- })
+ window::close_events().map(Message::WindowClosed)
}
}
@@ -172,11 +160,7 @@ impl Window {
title: format!("Window_{}", count),
scale_input: "1.0".to_string(),
current_scale: 1.0,
- theme: if count % 2 == 0 {
- Theme::Light
- } else {
- Theme::Dark
- },
+ theme: Theme::ALL[count % Theme::ALL.len()].clone(),
input_id: text_input::Id::unique(),
}
}
@@ -200,7 +184,7 @@ impl Window {
];
let new_window_button =
- button(text("New Window")).on_press(Message::NewWindow);
+ button(text("New Window")).on_press(Message::OpenWindow);
let content = scrollable(
column![scale_input, title_input, new_window_button]
diff --git a/examples/pokedex/src/main.rs b/examples/pokedex/src/main.rs
index cffa3727..e62ed70b 100644
--- a/examples/pokedex/src/main.rs
+++ b/examples/pokedex/src/main.rs
@@ -1,6 +1,6 @@
use iced::futures;
use iced::widget::{self, center, column, image, row, text};
-use iced::{Alignment, Command, Element, Length};
+use iced::{Alignment, Element, Length, Task};
pub fn main() -> iced::Result {
iced::program(Pokedex::title, Pokedex::update, Pokedex::view)
@@ -25,8 +25,8 @@ enum Message {
}
impl Pokedex {
- fn search() -> Command<Message> {
- Command::perform(Pokemon::search(), Message::PokemonFound)
+ fn search() -> Task<Message> {
+ Task::perform(Pokemon::search(), Message::PokemonFound)
}
fn title(&self) -> String {
@@ -39,20 +39,20 @@ impl Pokedex {
format!("{subtitle} - Pokédex")
}
- fn update(&mut self, message: Message) -> Command<Message> {
+ fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::PokemonFound(Ok(pokemon)) => {
*self = Pokedex::Loaded { pokemon };
- Command::none()
+ Task::none()
}
Message::PokemonFound(Err(_error)) => {
*self = Pokedex::Errored;
- Command::none()
+ Task::none()
}
Message::Search => match self {
- Pokedex::Loading => Command::none(),
+ Pokedex::Loading => Task::none(),
_ => {
*self = Pokedex::Loading;
diff --git a/examples/screenshot/src/main.rs b/examples/screenshot/src/main.rs
index fb19e556..78d3e9ff 100644
--- a/examples/screenshot/src/main.rs
+++ b/examples/screenshot/src/main.rs
@@ -4,7 +4,7 @@ use iced::widget::{button, column, container, image, row, text, text_input};
use iced::window;
use iced::window::screenshot::{self, Screenshot};
use iced::{
- Alignment, Command, ContentFit, Element, Length, Rectangle, Subscription,
+ Alignment, ContentFit, Element, Length, Rectangle, Subscription, Task,
};
use ::image as img;
@@ -34,7 +34,7 @@ struct Example {
enum Message {
Crop,
Screenshot,
- ScreenshotData(Screenshot),
+ Screenshotted(Screenshot),
Png,
PngSaved(Result<String, PngError>),
XInputChanged(Option<u32>),
@@ -44,22 +44,20 @@ enum Message {
}
impl Example {
- fn update(&mut self, message: Message) -> Command<Message> {
+ fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::Screenshot => {
- return iced::window::screenshot(
- window::Id::MAIN,
- Message::ScreenshotData,
- );
+ return iced::window::screenshot(window::Id::MAIN)
+ .map(Message::Screenshotted);
}
- Message::ScreenshotData(screenshot) => {
+ Message::Screenshotted(screenshot) => {
self.screenshot = Some(screenshot);
}
Message::Png => {
if let Some(screenshot) = &self.screenshot {
self.png_saving = true;
- return Command::perform(
+ return Task::perform(
save_to_png(screenshot.clone()),
Message::PngSaved,
);
@@ -103,7 +101,7 @@ impl Example {
}
}
- Command::none()
+ Task::none()
}
fn view(&self) -> Element<'_, Message> {
diff --git a/examples/scrollable/src/main.rs b/examples/scrollable/src/main.rs
index bbb6497f..a0dcf82c 100644
--- a/examples/scrollable/src/main.rs
+++ b/examples/scrollable/src/main.rs
@@ -3,7 +3,7 @@ use iced::widget::{
button, column, container, horizontal_space, progress_bar, radio, row,
scrollable, slider, text, vertical_space, Scrollable,
};
-use iced::{Alignment, Border, Color, Command, Element, Length, Theme};
+use iced::{Alignment, Border, Color, Element, Length, Task, Theme};
use once_cell::sync::Lazy;
@@ -59,7 +59,7 @@ impl ScrollableDemo {
}
}
- fn update(&mut self, message: Message) -> Command<Message> {
+ fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::SwitchDirection(direction) => {
self.current_scroll_offset = scrollable::RelativeOffset::START;
@@ -82,17 +82,17 @@ impl ScrollableDemo {
Message::ScrollbarWidthChanged(width) => {
self.scrollbar_width = width;
- Command::none()
+ Task::none()
}
Message::ScrollbarMarginChanged(margin) => {
self.scrollbar_margin = margin;
- Command::none()
+ Task::none()
}
Message::ScrollerWidthChanged(width) => {
self.scroller_width = width;
- Command::none()
+ Task::none()
}
Message::ScrollToBeginning => {
self.current_scroll_offset = scrollable::RelativeOffset::START;
@@ -113,7 +113,7 @@ impl ScrollableDemo {
Message::Scrolled(viewport) => {
self.current_scroll_offset = viewport.relative_offset();
- Command::none()
+ Task::none()
}
}
}
diff --git a/examples/system_information/src/main.rs b/examples/system_information/src/main.rs
index 8ce12e1c..e2808edd 100644
--- a/examples/system_information/src/main.rs
+++ b/examples/system_information/src/main.rs
@@ -1,5 +1,5 @@
use iced::widget::{button, center, column, text};
-use iced::{system, Command, Element};
+use iced::{system, Element, Task};
pub fn main() -> iced::Result {
iced::program("System Information - Iced", Example::update, Example::view)
@@ -24,19 +24,20 @@ enum Message {
}
impl Example {
- fn update(&mut self, message: Message) -> Command<Message> {
+ fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::Refresh => {
*self = Self::Loading;
- return system::fetch_information(Message::InformationReceived);
+ return system::fetch_information()
+ .map(Message::InformationReceived);
}
Message::InformationReceived(information) => {
*self = Self::Loaded { information };
}
}
- Command::none()
+ Task::none()
}
fn view(&self) -> Element<Message> {
diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs
index 700b6b10..aee2479e 100644
--- a/examples/toast/src/main.rs
+++ b/examples/toast/src/main.rs
@@ -4,7 +4,7 @@ use iced::keyboard::key;
use iced::widget::{
self, button, center, column, pick_list, row, slider, text, text_input,
};
-use iced::{Alignment, Command, Element, Length, Subscription};
+use iced::{Alignment, Element, Length, Subscription, Task};
use toast::{Status, Toast};
@@ -49,7 +49,7 @@ impl App {
event::listen().map(Message::Event)
}
- fn update(&mut self, message: Message) -> Command<Message> {
+ fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::Add => {
if !self.editing.title.is_empty()
@@ -57,27 +57,27 @@ impl App {
{
self.toasts.push(std::mem::take(&mut self.editing));
}
- Command::none()
+ Task::none()
}
Message::Close(index) => {
self.toasts.remove(index);
- Command::none()
+ Task::none()
}
Message::Title(title) => {
self.editing.title = title;
- Command::none()
+ Task::none()
}
Message::Body(body) => {
self.editing.body = body;
- Command::none()
+ Task::none()
}
Message::Status(status) => {
self.editing.status = status;
- Command::none()
+ Task::none()
}
Message::Timeout(timeout) => {
self.timeout_secs = timeout as u64;
- Command::none()
+ Task::none()
}
Message::Event(Event::Keyboard(keyboard::Event::KeyPressed {
key: keyboard::Key::Named(key::Named::Tab),
@@ -88,7 +88,7 @@ impl App {
key: keyboard::Key::Named(key::Named::Tab),
..
})) => widget::focus_next(),
- Message::Event(_) => Command::none(),
+ Message::Event(_) => Task::none(),
}
}
@@ -347,7 +347,7 @@ mod toast {
state: &mut Tree,
layout: Layout<'_>,
renderer: &Renderer,
- operation: &mut dyn Operation<Message>,
+ operation: &mut dyn Operation<()>,
) {
operation.container(None, layout.bounds(), &mut |operation| {
self.content.as_widget().operate(
@@ -589,7 +589,7 @@ mod toast {
&mut self,
layout: Layout<'_>,
renderer: &Renderer,
- operation: &mut dyn widget::Operation<Message>,
+ operation: &mut dyn widget::Operation<()>,
) {
operation.container(None, layout.bounds(), &mut |operation| {
self.toasts
diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs
index dd1e5213..c21e1a96 100644
--- a/examples/todos/src/main.rs
+++ b/examples/todos/src/main.rs
@@ -5,7 +5,7 @@ use iced::widget::{
scrollable, text, text_input, Text,
};
use iced::window;
-use iced::{Command, Element, Font, Length, Subscription};
+use iced::{Element, Font, Length, Subscription, Task as Command};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
diff --git a/examples/visible_bounds/src/main.rs b/examples/visible_bounds/src/main.rs
index 8030f5b4..b43c0cca 100644
--- a/examples/visible_bounds/src/main.rs
+++ b/examples/visible_bounds/src/main.rs
@@ -5,8 +5,8 @@ use iced::widget::{
};
use iced::window;
use iced::{
- Alignment, Color, Command, Element, Font, Length, Point, Rectangle,
- Subscription, Theme,
+ Alignment, Color, Element, Font, Length, Point, Rectangle, Subscription,
+ Task, Theme,
};
pub fn main() -> iced::Result {
@@ -33,14 +33,14 @@ enum Message {
}
impl Example {
- fn update(&mut self, message: Message) -> Command<Message> {
+ fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::MouseMoved(position) => {
self.mouse_position = Some(position);
- Command::none()
+ Task::none()
}
- Message::Scrolled | Message::WindowResized => Command::batch(vec![
+ Message::Scrolled | Message::WindowResized => Task::batch(vec![
container::visible_bounds(OUTER_CONTAINER.clone())
.map(Message::OuterBoundsFetched),
container::visible_bounds(INNER_CONTAINER.clone())
@@ -49,12 +49,12 @@ impl Example {
Message::OuterBoundsFetched(outer_bounds) => {
self.outer_bounds = outer_bounds;
- Command::none()
+ Task::none()
}
Message::InnerBoundsFetched(inner_bounds) => {
self.inner_bounds = inner_bounds;
- Command::none()
+ Task::none()
}
}
}
diff --git a/examples/websocket/src/main.rs b/examples/websocket/src/main.rs
index ba1e1029..8c0fa1d0 100644
--- a/examples/websocket/src/main.rs
+++ b/examples/websocket/src/main.rs
@@ -4,7 +4,7 @@ use iced::alignment::{self, Alignment};
use iced::widget::{
self, button, center, column, row, scrollable, text, text_input,
};
-use iced::{color, Command, Element, Length, Subscription};
+use iced::{color, Element, Length, Subscription, Task};
use once_cell::sync::Lazy;
pub fn main() -> iced::Result {
@@ -30,19 +30,19 @@ enum Message {
}
impl WebSocket {
- fn load() -> Command<Message> {
- Command::batch([
- Command::perform(echo::server::run(), |_| Message::Server),
+ fn load() -> Task<Message> {
+ Task::batch([
+ Task::perform(echo::server::run(), |_| Message::Server),
widget::focus_next(),
])
}
- fn update(&mut self, message: Message) -> Command<Message> {
+ fn update(&mut self, message: Message) -> Task<Message> {
match message {
Message::NewMessageChanged(new_message) => {
self.new_message = new_message;
- Command::none()
+ Task::none()
}
Message::Send(message) => match &mut self.state {
State::Connected(connection) => {
@@ -50,9 +50,9 @@ impl WebSocket {
connection.send(message);
- Command::none()
+ Task::none()
}
- State::Disconnected => Command::none(),
+ State::Disconnected => Task::none(),
},
Message::Echo(event) => match event {
echo::Event::Connected(connection) => {
@@ -60,14 +60,14 @@ impl WebSocket {
self.messages.push(echo::Message::connected());
- Command::none()
+ Task::none()
}
echo::Event::Disconnected => {
self.state = State::Disconnected;
self.messages.push(echo::Message::disconnected());
- Command::none()
+ Task::none()
}
echo::Event::MessageReceived(message) => {
self.messages.push(message);
@@ -78,7 +78,7 @@ impl WebSocket {
)
}
},
- Message::Server => Command::none(),
+ Message::Server => Task::none(),
}
}