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 platform_specific;
17pub mod system;
18pub mod task;
19pub mod user_interface;
20pub mod widget;
21pub mod window;
22
23pub use iced_core as core;
24pub use iced_futures as futures;
25
26pub use task::Task;
27pub use user_interface::UserInterface;
28pub use window::Window;
29
30use crate::core::Event;
31use crate::futures::futures::channel::oneshot;
32
33use std::borrow::Cow;
34use std::fmt;
35
36pub enum Action<T> {
38 Output(T),
40
41 LoadFont {
43 bytes: Cow<'static, [u8]>,
45 channel: oneshot::Sender<Result<(), font::Error>>,
47 },
48
49 Widget(Box<dyn core::widget::Operation>),
51
52 Clipboard(clipboard::Action),
54
55 Window(window::Action),
57
58 System(system::Action),
60
61 Image(image::Action),
63
64 Event {
66 window: core::window::Id,
68 event: Event,
70 },
71
72 Tick,
74
75 Reload,
77
78 PlatformSpecific(platform_specific::Action),
80
81 Exit,
86}
87
88impl<T> Action<T> {
89 pub fn widget(operation: impl core::widget::Operation + 'static) -> Self {
91 Self::Widget(Box::new(operation))
92 }
93
94 fn output<O>(self) -> Result<T, Action<O>> {
95 match self {
96 Action::Output(output) => Ok(output),
97 Action::LoadFont { bytes, channel } => Err(Action::LoadFont { bytes, channel }),
98 Action::Widget(operation) => Err(Action::Widget(operation)),
99 Action::Clipboard(action) => Err(Action::Clipboard(action)),
100 Action::Window(action) => Err(Action::Window(action)),
101 Action::System(action) => Err(Action::System(action)),
102 Action::Image(action) => Err(Action::Image(action)),
103 Action::Event { window, event } => Err(Action::Event { window, event }),
104 Action::Tick => Err(Action::Tick),
105 Action::Reload => Err(Action::Reload),
106 Action::PlatformSpecific(action) => Err(Action::PlatformSpecific(action)),
107 Action::Exit => Err(Action::Exit),
108 }
109 }
110}
111
112impl<T> fmt::Debug for Action<T>
113where
114 T: fmt::Debug,
115{
116 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
117 match self {
118 Action::Output(output) => write!(f, "Action::Output({output:?})"),
119 Action::LoadFont { .. } => {
120 write!(f, "Action::LoadFont")
121 }
122 Action::Widget { .. } => {
123 write!(f, "Action::Widget")
124 }
125 Action::Clipboard(action) => {
126 write!(f, "Action::Clipboard({action:?})")
127 }
128 Action::Window(_) => write!(f, "Action::Window"),
129 Action::System(action) => write!(f, "Action::System({action:?})"),
130 Action::Image(_) => write!(f, "Action::Image"),
131 Action::Event { window, event } => write!(
132 f,
133 "Action::Event {{ window: {window:?}, event: {event:?} }}"
134 ),
135 Action::Tick => write!(f, "Action::Tick"),
136 Action::Reload => write!(f, "Action::Reload"),
137 Action::PlatformSpecific(action) => {
138 write!(f, "Action::PlatformSpecific({action:?})")
139 }
140 Action::Exit => write!(f, "Action::Exit"),
141 }
142 }
143}
144
145pub fn exit<T>() -> Task<T> {
150 task::effect(Action::Exit)
151}