diff options
author | 2022-07-28 02:46:51 +0200 | |
---|---|---|
committer | 2022-07-28 02:46:51 +0200 | |
commit | 80688689aa4b15bc23824df899974a9094a77b07 (patch) | |
tree | bbfce1c91b9ee22990503a55d31d04cadf4093b7 /native/src/command | |
parent | a003e797e8a1bb5d365c1db5de6af88e61a47329 (diff) | |
download | iced-80688689aa4b15bc23824df899974a9094a77b07.tar.gz iced-80688689aa4b15bc23824df899974a9094a77b07.tar.bz2 iced-80688689aa4b15bc23824df899974a9094a77b07.zip |
Draft widget operations
Diffstat (limited to '')
-rw-r--r-- | native/src/command.rs | 10 | ||||
-rw-r--r-- | native/src/command/action.rs | 7 |
2 files changed, 17 insertions, 0 deletions
diff --git a/native/src/command.rs b/native/src/command.rs index 89d0f045..b0b12805 100644 --- a/native/src/command.rs +++ b/native/src/command.rs @@ -3,6 +3,8 @@ mod action; pub use action::Action; +use crate::widget; + use iced_futures::MaybeSend; use std::fmt; @@ -24,6 +26,13 @@ impl<T> Command<T> { Self(iced_futures::Command::single(action)) } + /// Creates a [`Command`] that performs a [`widget::Operation`]. + pub fn widget(operation: impl widget::Operation<T> + 'static) -> Self { + Self(iced_futures::Command::single(Action::Widget( + widget::Action::new(operation), + ))) + } + /// Creates a [`Command`] that performs the action of the given future. pub fn perform<A>( future: impl Future<Output = T> + 'static + MaybeSend, @@ -51,6 +60,7 @@ impl<T> Command<T> { ) -> Command<A> where T: 'static, + A: 'static, { let Command(command) = self; diff --git a/native/src/command/action.rs b/native/src/command/action.rs index 1bb03cef..3fb02899 100644 --- a/native/src/command/action.rs +++ b/native/src/command/action.rs @@ -1,5 +1,6 @@ use crate::clipboard; use crate::system; +use crate::widget; use crate::window; use iced_futures::MaybeSend; @@ -23,6 +24,9 @@ pub enum Action<T> { /// Run a system action. System(system::Action<T>), + + /// Run a widget action. + Widget(widget::Action<T>), } impl<T> Action<T> { @@ -34,6 +38,7 @@ impl<T> Action<T> { f: impl Fn(T) -> A + 'static + MaybeSend + Sync, ) -> Action<A> where + A: 'static, T: 'static, { use iced_futures::futures::FutureExt; @@ -43,6 +48,7 @@ impl<T> Action<T> { Self::Clipboard(action) => Action::Clipboard(action.map(f)), Self::Window(window) => Action::Window(window), Self::System(system) => Action::System(system.map(f)), + Self::Widget(widget) => Action::Widget(widget.map(f)), } } } @@ -56,6 +62,7 @@ impl<T> fmt::Debug for Action<T> { } Self::Window(action) => write!(f, "Action::Window({:?})", action), Self::System(action) => write!(f, "Action::System({:?})", action), + Self::Widget(_action) => write!(f, "Action::Widget"), } } } |