1//! A renderer-agnostic native GUI runtime.
2//!
3//! 
4//!
5//! `iced_runtime` takes [`iced_core`] and builds a native runtime on top of it.
6//!
7//! [`iced_core`]: https://github.com/iced-rs/iced/tree/0.13/core
8#![doc(
9 html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
10)]
11#![cfg_attr(docsrs, feature(doc_auto_cfg))]
12pub mod clipboard;
13pub mod font;
14pub mod keyboard;
15pub mod overlay;
16pub mod system;
17pub mod task;
18pub mod user_interface;
19pub mod window;
2021pub use iced_core as core;
22pub use iced_debug as debug;
23pub use iced_futures as futures;
2425pub use task::Task;
26pub use user_interface::UserInterface;
2728use crate::core::widget;
29use crate::futures::futures::channel::oneshot;
3031use std::borrow::Cow;
32use std::fmt;
3334/// An action that the iced runtime can perform.
35pub enum Action<T> {
36/// Output some value.
37Output(T),
3839/// Load a font from its bytes.
40LoadFont {
41/// The bytes of the font to load.
42bytes: Cow<'static, [u8]>,
43/// The channel to send back the load result.
44channel: oneshot::Sender<Result<(), font::Error>>,
45 },
4647/// Run a widget operation.
48Widget(Box<dyn widget::Operation>),
4950/// Run a clipboard action.
51Clipboard(clipboard::Action),
5253/// Run a window action.
54Window(window::Action),
5556/// Run a system action.
57System(system::Action),
5859/// Recreate all user interfaces and redraw all windows.
60Reload,
6162/// Exits the runtime.
63 ///
64 /// This will normally close any application windows and
65 /// terminate the runtime loop.
66Exit,
67}
6869impl<T> Action<T> {
70/// Creates a new [`Action::Widget`] with the given [`widget::Operation`].
71pub fn widget(operation: impl widget::Operation + 'static) -> Self {
72Self::Widget(Box::new(operation))
73 }
7475fn output<O>(self) -> Result<T, Action<O>> {
76match self {
77 Action::Output(output) => Ok(output),
78 Action::LoadFont { bytes, channel } => {
79Err(Action::LoadFont { bytes, channel })
80 }
81 Action::Widget(operation) => Err(Action::Widget(operation)),
82 Action::Clipboard(action) => Err(Action::Clipboard(action)),
83 Action::Window(action) => Err(Action::Window(action)),
84 Action::System(action) => Err(Action::System(action)),
85 Action::Reload => Err(Action::Reload),
86 Action::Exit => Err(Action::Exit),
87 }
88 }
89}
9091impl<T> fmt::Debug for Action<T>
92where
93T: fmt::Debug,
94{
95fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
96match self {
97 Action::Output(output) => write!(f, "Action::Output({output:?})"),
98 Action::LoadFont { .. } => {
99write!(f, "Action::LoadFont")
100 }
101 Action::Widget { .. } => {
102write!(f, "Action::Widget")
103 }
104 Action::Clipboard(action) => {
105write!(f, "Action::Clipboard({action:?})")
106 }
107 Action::Window(_) => write!(f, "Action::Window"),
108 Action::System(action) => write!(f, "Action::System({action:?})"),
109 Action::Reload => write!(f, "Action::Reload"),
110 Action::Exit => write!(f, "Action::Exit"),
111 }
112 }
113}
114115/// Creates a [`Task`] that exits the iced runtime.
116///
117/// This will normally close any application windows and
118/// terminate the runtime loop.
119pub fn exit<T>() -> Task<T> {
120 task::effect(Action::Exit)
121}