summaryrefslogtreecommitdiffstats
path: root/runtime/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/lib.rs')
-rw-r--r--runtime/src/lib.rs80
1 files changed, 77 insertions, 3 deletions
diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs
index 5f054c46..5fde3039 100644
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -10,7 +10,6 @@
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
pub mod clipboard;
-pub mod command;
pub mod font;
pub mod keyboard;
pub mod overlay;
@@ -22,6 +21,8 @@ pub mod window;
#[cfg(feature = "multi-window")]
pub mod multi_window;
+mod task;
+
// We disable debug capabilities on release builds unless the `debug` feature
// is explicitly enabled.
#[cfg(feature = "debug")]
@@ -34,8 +35,81 @@ mod debug;
pub use iced_core as core;
pub use iced_futures as futures;
-pub use command::Command;
pub use debug::Debug;
-pub use font::Font;
pub use program::Program;
+pub use task::Task;
pub use user_interface::UserInterface;
+
+use crate::core::widget;
+use crate::futures::futures::channel::oneshot;
+
+use std::borrow::Cow;
+use std::fmt;
+
+/// An action that the iced runtime can perform.
+pub enum Action<T> {
+ /// Output some value.
+ Output(T),
+
+ /// Load a font from its bytes.
+ LoadFont {
+ /// The bytes of the font to load.
+ bytes: Cow<'static, [u8]>,
+ /// The channel to send back the load result.
+ channel: oneshot::Sender<Result<(), font::Error>>,
+ },
+
+ /// Run a widget operation.
+ Widget(Box<dyn widget::Operation<()> + Send>),
+
+ /// Run a clipboard action.
+ Clipboard(clipboard::Action),
+
+ /// Run a window action.
+ Window(window::Action),
+
+ /// Run a system action.
+ System(system::Action),
+}
+
+impl<T> Action<T> {
+ /// Creates a new [`Action::Widget`] with the given [`widget::Operation`].
+ pub fn widget(operation: impl widget::Operation<()> + 'static) -> Self {
+ Self::Widget(Box::new(operation))
+ }
+
+ fn output<O>(self) -> Result<T, Action<O>> {
+ match self {
+ Action::Output(output) => Ok(output),
+ Action::LoadFont { bytes, channel } => {
+ Err(Action::LoadFont { bytes, channel })
+ }
+ Action::Widget(operation) => Err(Action::Widget(operation)),
+ Action::Clipboard(action) => Err(Action::Clipboard(action)),
+ Action::Window(action) => Err(Action::Window(action)),
+ Action::System(action) => Err(Action::System(action)),
+ }
+ }
+}
+
+impl<T> fmt::Debug for Action<T>
+where
+ T: fmt::Debug,
+{
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Action::Output(output) => write!(f, "Action::Output({output:?})"),
+ Action::LoadFont { .. } => {
+ write!(f, "Action::LoadFont")
+ }
+ Action::Widget { .. } => {
+ write!(f, "Action::Widget")
+ }
+ Action::Clipboard(action) => {
+ write!(f, "Action::Clipboard({action:?})")
+ }
+ Action::Window(_) => write!(f, "Action::Window"),
+ Action::System(action) => write!(f, "Action::System({action:?})"),
+ }
+ }
+}