Replace Command with a new Task API with chain support

This commit is contained in:
Héctor Ramón Jiménez 2024-06-14 01:47:39 +02:00
parent e6d0b3bda5
commit a25b1af456
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
74 changed files with 1351 additions and 1767 deletions

View file

@ -2,7 +2,7 @@
use crate::core::text;
use crate::graphics::compositor;
use crate::shell::application;
use crate::{Command, Element, Executor, Settings, Subscription};
use crate::{Element, Executor, Settings, Subscription, Task};
pub use application::{Appearance, DefaultStyle};
@ -16,7 +16,7 @@ pub use application::{Appearance, DefaultStyle};
/// document.
///
/// An [`Application`] can execute asynchronous actions by returning a
/// [`Command`] in some of its methods.
/// [`Task`] in some of its methods.
///
/// When using an [`Application`] with the `debug` feature enabled, a debug view
/// can be toggled by pressing `F12`.
@ -62,7 +62,7 @@ pub use application::{Appearance, DefaultStyle};
/// ```no_run
/// use iced::advanced::Application;
/// use iced::executor;
/// use iced::{Command, Element, Settings, Theme, Renderer};
/// use iced::{Task, Element, Settings, Theme, Renderer};
///
/// pub fn main() -> iced::Result {
/// Hello::run(Settings::default())
@ -77,16 +77,16 @@ pub use application::{Appearance, DefaultStyle};
/// type Theme = Theme;
/// type Renderer = Renderer;
///
/// fn new(_flags: ()) -> (Hello, Command<Self::Message>) {
/// (Hello, Command::none())
/// fn new(_flags: ()) -> (Hello, Task<Self::Message>) {
/// (Hello, Task::none())
/// }
///
/// fn title(&self) -> String {
/// String::from("A cool application")
/// }
///
/// fn update(&mut self, _message: Self::Message) -> Command<Self::Message> {
/// Command::none()
/// fn update(&mut self, _message: Self::Message) -> Task<Self::Message> {
/// Task::none()
/// }
///
/// fn view(&self) -> Element<Self::Message> {
@ -123,12 +123,12 @@ where
///
/// Here is where you should return the initial state of your app.
///
/// Additionally, you can return a [`Command`] if you need to perform some
/// Additionally, you can return a [`Task`] if you need to perform some
/// async action in the background on startup. This is useful if you want to
/// load state from a file, perform an initial HTTP request, etc.
///
/// [`run`]: Self::run
fn new(flags: Self::Flags) -> (Self, Command<Self::Message>);
fn new(flags: Self::Flags) -> (Self, Task<Self::Message>);
/// Returns the current title of the [`Application`].
///
@ -142,8 +142,8 @@ where
/// produced by either user interactions or commands, will be handled by
/// this method.
///
/// Any [`Command`] returned will be executed immediately in the background.
fn update(&mut self, message: Self::Message) -> Command<Self::Message>;
/// Any [`Task`] returned will be executed immediately in the background.
fn update(&mut self, message: Self::Message) -> Task<Self::Message>;
/// Returns the widgets to display in the [`Application`].
///
@ -234,7 +234,7 @@ where
type Theme = A::Theme;
type Renderer = A::Renderer;
fn update(&mut self, message: Self::Message) -> Command<Self::Message> {
fn update(&mut self, message: Self::Message) -> Task<Self::Message> {
self.0.update(message)
}
@ -250,7 +250,7 @@ where
{
type Flags = A::Flags;
fn new(flags: Self::Flags) -> (Self, Command<A::Message>) {
fn new(flags: Self::Flags) -> (Self, Task<A::Message>) {
let (app, command) = A::new(flags);
(Instance(app), command)