1#![doc(
9 html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
10)]
11#![cfg_attr(docsrs, feature(doc_cfg))]
12pub mod clipboard;
13pub mod font;
14pub mod image;
15pub mod keyboard;
16pub mod system;
17pub mod task;
18pub mod user_interface;
19pub mod widget;
20pub mod window;
21
22pub use iced_core as core;
23pub use iced_futures as futures;
24
25pub use task::Task;
26pub use user_interface::UserInterface;
27pub use window::Window;
28
29use crate::core::Event;
30use crate::futures::futures::channel::oneshot;
31
32use std::borrow::Cow;
33use std::fmt;
34
35pub enum Action<T> {
37 Output(T),
39
40 LoadFont {
42 bytes: Cow<'static, [u8]>,
44 channel: oneshot::Sender<Result<(), font::Error>>,
46 },
47
48 Widget(Box<dyn core::widget::Operation>),
50
51 Clipboard(clipboard::Action),
53
54 Window(window::Action),
56
57 System(system::Action),
59
60 Image(image::Action),
62
63 Event {
65 window: core::window::Id,
67 event: Event,
69 },
70
71 Tick,
73
74 Reload,
76
77 Exit,
82}
83
84impl<T> Action<T> {
85 pub fn widget(operation: impl core::widget::Operation + 'static) -> Self {
87 Self::Widget(Box::new(operation))
88 }
89
90 fn output<O>(self) -> Result<T, Action<O>> {
91 match self {
92 Action::Output(output) => Ok(output),
93 Action::LoadFont { bytes, channel } => Err(Action::LoadFont { bytes, channel }),
94 Action::Widget(operation) => Err(Action::Widget(operation)),
95 Action::Clipboard(action) => Err(Action::Clipboard(action)),
96 Action::Window(action) => Err(Action::Window(action)),
97 Action::System(action) => Err(Action::System(action)),
98 Action::Image(action) => Err(Action::Image(action)),
99 Action::Event { window, event } => Err(Action::Event { window, event }),
100 Action::Tick => Err(Action::Tick),
101 Action::Reload => Err(Action::Reload),
102 Action::Exit => Err(Action::Exit),
103 }
104 }
105}
106
107impl<T> fmt::Debug for Action<T>
108where
109 T: fmt::Debug,
110{
111 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
112 match self {
113 Action::Output(output) => write!(f, "Action::Output({output:?})"),
114 Action::LoadFont { .. } => {
115 write!(f, "Action::LoadFont")
116 }
117 Action::Widget { .. } => {
118 write!(f, "Action::Widget")
119 }
120 Action::Clipboard(action) => {
121 write!(f, "Action::Clipboard({action:?})")
122 }
123 Action::Window(_) => write!(f, "Action::Window"),
124 Action::System(action) => write!(f, "Action::System({action:?})"),
125 Action::Image(_) => write!(f, "Action::Image"),
126 Action::Event { window, event } => write!(
127 f,
128 "Action::Event {{ window: {window:?}, event: {event:?} }}"
129 ),
130 Action::Tick => write!(f, "Action::Tick"),
131 Action::Reload => write!(f, "Action::Reload"),
132 Action::Exit => write!(f, "Action::Exit"),
133 }
134 }
135}
136
137pub fn exit<T>() -> Task<T> {
142 task::effect(Action::Exit)
143}