2019-11-22 19:36:57 +01:00
|
|
|
//! A renderer-agnostic native GUI runtime.
|
2019-09-20 19:15:31 +02:00
|
|
|
//!
|
2024-02-15 03:33:43 +01:00
|
|
|
//! 
|
2019-09-20 19:15:31 +02:00
|
|
|
//!
|
2023-09-09 12:24:47 +02:00
|
|
|
//! `iced_runtime` takes [`iced_core`] and builds a native runtime on top of it.
|
2019-09-20 19:15:31 +02:00
|
|
|
//!
|
2024-09-18 02:38:49 +02:00
|
|
|
//! [`iced_core`]: https://github.com/iced-rs/iced/tree/0.13/core
|
2021-12-08 08:04:46 +01:00
|
|
|
#![doc(
|
2021-12-09 15:10:38 +07:00
|
|
|
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
|
2021-12-08 08:04:46 +01:00
|
|
|
)]
|
2025-10-08 04:37:13 +02:00
|
|
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
2021-03-10 01:59:02 +01:00
|
|
|
pub mod clipboard;
|
2023-02-04 11:12:15 +01:00
|
|
|
pub mod font;
|
2025-10-25 00:07:13 +02:00
|
|
|
pub mod image;
|
2020-04-30 05:04:45 +02:00
|
|
|
pub mod keyboard;
|
2022-02-16 19:20:26 -03:00
|
|
|
pub mod system;
|
2024-07-05 01:13:28 +02:00
|
|
|
pub mod task;
|
2022-01-11 13:47:43 +07:00
|
|
|
pub mod user_interface;
|
2025-08-23 05:15:57 +02:00
|
|
|
pub mod widget;
|
2020-01-10 01:28:45 +01:00
|
|
|
pub mod window;
|
2019-09-20 19:15:31 +02:00
|
|
|
|
2023-03-04 05:37:11 +01:00
|
|
|
pub use iced_core as core;
|
|
|
|
|
pub use iced_futures as futures;
|
2020-01-20 04:47:36 +01:00
|
|
|
|
2024-06-14 01:47:39 +02:00
|
|
|
pub use task::Task;
|
2022-01-11 13:47:43 +07:00
|
|
|
pub use user_interface::UserInterface;
|
2025-11-20 00:20:24 +01:00
|
|
|
pub use window::Window;
|
2024-06-14 01:47:39 +02:00
|
|
|
|
|
|
|
|
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.
|
2025-08-23 05:15:57 +02:00
|
|
|
Widget(Box<dyn core::widget::Operation>),
|
2024-06-14 01:47:39 +02:00
|
|
|
|
|
|
|
|
/// Run a clipboard action.
|
|
|
|
|
Clipboard(clipboard::Action),
|
|
|
|
|
|
|
|
|
|
/// Run a window action.
|
|
|
|
|
Window(window::Action),
|
|
|
|
|
|
|
|
|
|
/// Run a system action.
|
|
|
|
|
System(system::Action),
|
2024-06-19 01:53:40 +02:00
|
|
|
|
2025-10-25 00:07:13 +02:00
|
|
|
/// An image action.
|
|
|
|
|
Image(image::Action),
|
|
|
|
|
|
2025-06-06 22:58:59 +02:00
|
|
|
/// Recreate all user interfaces and redraw all windows.
|
|
|
|
|
Reload,
|
|
|
|
|
|
2024-06-19 01:53:40 +02:00
|
|
|
/// Exits the runtime.
|
|
|
|
|
///
|
|
|
|
|
/// This will normally close any application windows and
|
|
|
|
|
/// terminate the runtime loop.
|
|
|
|
|
Exit,
|
2024-06-14 01:47:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> Action<T> {
|
2025-08-23 05:15:57 +02:00
|
|
|
/// Creates a new [`Action::Widget`] with the given [`widget::Operation`](core::widget::Operation).
|
|
|
|
|
pub fn widget(operation: impl core::widget::Operation + 'static) -> Self {
|
2024-06-14 01:47:39 +02:00
|
|
|
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)),
|
2025-10-25 00:07:13 +02:00
|
|
|
Action::Image(action) => Err(Action::Image(action)),
|
2025-06-06 22:58:59 +02:00
|
|
|
Action::Reload => Err(Action::Reload),
|
2024-06-19 01:53:40 +02:00
|
|
|
Action::Exit => Err(Action::Exit),
|
2024-06-14 01:47:39 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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:?})"),
|
2025-10-25 00:07:13 +02:00
|
|
|
Action::Image(_) => write!(f, "Action::Image"),
|
2025-06-06 22:58:59 +02:00
|
|
|
Action::Reload => write!(f, "Action::Reload"),
|
2024-06-19 01:53:40 +02:00
|
|
|
Action::Exit => write!(f, "Action::Exit"),
|
2024-06-14 01:47:39 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-19 01:53:40 +02:00
|
|
|
|
|
|
|
|
/// Creates a [`Task`] that exits the iced runtime.
|
|
|
|
|
///
|
|
|
|
|
/// This will normally close any application windows and
|
|
|
|
|
/// terminate the runtime loop.
|
|
|
|
|
pub fn exit<T>() -> Task<T> {
|
2024-07-05 01:13:28 +02:00
|
|
|
task::effect(Action::Exit)
|
2024-06-19 01:53:40 +02:00
|
|
|
}
|