From 238154af4ac8dda7f12dd90aa7be106e933bcb30 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 4 Feb 2023 11:12:15 +0100 Subject: Implement `font::load` command in `iced_native` --- native/src/command/action.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'native/src/command/action.rs') diff --git a/native/src/command/action.rs b/native/src/command/action.rs index a51b8c21..d1589c05 100644 --- a/native/src/command/action.rs +++ b/native/src/command/action.rs @@ -1,10 +1,12 @@ use crate::clipboard; +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. @@ -27,6 +29,15 @@ pub enum Action { /// Run a widget action. Widget(widget::Action), + + /// 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) -> T>, + }, } impl Action { @@ -49,6 +60,10 @@ impl Action { 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::LoadFont { bytes, tagger } => Action::LoadFont { + bytes, + tagger: Box::new(move |result| f(tagger(result))), + }, } } } @@ -63,6 +78,7 @@ impl fmt::Debug for Action { 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"), } } } -- cgit From 8af69be47e88896b3c5f70174db609eee0c67971 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 5 Mar 2023 06:23:40 +0100 Subject: Converge `Command` types from `iced_futures` and `iced_native` --- native/src/command/action.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'native/src/command/action.rs') diff --git a/native/src/command/action.rs b/native/src/command/action.rs index d1589c05..6c74f0ef 100644 --- a/native/src/command/action.rs +++ b/native/src/command/action.rs @@ -1,7 +1,7 @@ use crate::clipboard; +use crate::core::widget; use crate::font; use crate::system; -use crate::widget; use crate::window; use iced_futures::MaybeSend; @@ -28,7 +28,7 @@ pub enum Action { System(system::Action), /// Run a widget action. - Widget(widget::Action), + Widget(Box>), /// Load a font from its bytes. LoadFont { @@ -59,7 +59,9 @@ impl Action { 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))), -- cgit From 99e0a71504456976ba88040f5d1d3bbc347694ea Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 5 Mar 2023 06:35:20 +0100 Subject: Rename `iced_native` to `iced_runtime` --- native/src/command/action.rs | 86 -------------------------------------------- 1 file changed, 86 deletions(-) delete mode 100644 native/src/command/action.rs (limited to 'native/src/command/action.rs') diff --git a/native/src/command/action.rs b/native/src/command/action.rs deleted file mode 100644 index 6c74f0ef..00000000 --- a/native/src/command/action.rs +++ /dev/null @@ -1,86 +0,0 @@ -use crate::clipboard; -use crate::core::widget; -use crate::font; -use crate::system; -use crate::window; - -use iced_futures::MaybeSend; - -use std::borrow::Cow; -use std::fmt; - -/// An action that a [`Command`] can perform. -/// -/// [`Command`]: crate::Command -pub enum Action { - /// Run a [`Future`] to completion. - /// - /// [`Future`]: iced_futures::BoxFuture - Future(iced_futures::BoxFuture), - - /// Run a clipboard action. - Clipboard(clipboard::Action), - - /// Run a window action. - Window(window::Action), - - /// Run a system action. - System(system::Action), - - /// Run a widget action. - Widget(Box>), - - /// 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) -> T>, - }, -} - -impl Action { - /// Applies a transformation to the result of a [`Command`]. - /// - /// [`Command`]: crate::Command - pub fn map( - self, - f: impl Fn(T) -> A + 'static + MaybeSend + Sync, - ) -> Action - where - A: 'static, - T: 'static, - { - use iced_futures::futures::FutureExt; - - match self { - Self::Future(future) => Action::Future(Box::pin(future.map(f))), - 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(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))), - }, - } - } -} - -impl fmt::Debug for Action { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::Future(_) => write!(f, "Action::Future"), - Self::Clipboard(action) => { - write!(f, "Action::Clipboard({action:?})") - } - 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"), - } - } -} -- cgit