diff options
Diffstat (limited to '')
-rw-r--r-- | runtime/src/command/action.rs (renamed from native/src/command/action.rs) | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/native/src/command/action.rs b/runtime/src/command/action.rs index a51b8c21..6c74f0ef 100644 --- a/native/src/command/action.rs +++ b/runtime/src/command/action.rs @@ -1,10 +1,12 @@ use crate::clipboard; +use crate::core::widget; +use crate::font; use crate::system; -use crate::widget; use crate::window; use iced_futures::MaybeSend; +use std::borrow::Cow; use std::fmt; /// An action that a [`Command`] can perform. @@ -26,7 +28,16 @@ pub enum Action<T> { System(system::Action<T>), /// Run a widget action. - Widget(widget::Action<T>), + Widget(Box<dyn widget::Operation<T>>), + + /// Load a font from its bytes. + LoadFont { + /// The bytes of the font to load. + bytes: Cow<'static, [u8]>, + + /// The message to produce when the font has been loaded. + tagger: Box<dyn Fn(Result<(), font::Error>) -> T>, + }, } impl<T> Action<T> { @@ -48,7 +59,13 @@ impl<T> Action<T> { Self::Clipboard(action) => Action::Clipboard(action.map(f)), Self::Window(window) => Action::Window(window.map(f)), Self::System(system) => Action::System(system.map(f)), - Self::Widget(widget) => Action::Widget(widget.map(f)), + Self::Widget(operation) => { + Action::Widget(Box::new(widget::operation::map(operation, f))) + } + Self::LoadFont { bytes, tagger } => Action::LoadFont { + bytes, + tagger: Box::new(move |result| f(tagger(result))), + }, } } } @@ -63,6 +80,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"), + Self::LoadFont { .. } => write!(f, "Action::LoadFont"), } } } |