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;
30
31use std::fmt;
32
33pub enum Action<T> {
35 Output(T),
37
38 Widget(Box<dyn core::widget::Operation>),
40
41 Clipboard(clipboard::Action),
43
44 Window(window::Action),
46
47 System(system::Action),
49
50 Font(font::Action),
52
53 Image(image::Action),
55
56 Event {
58 window: core::window::Id,
60 event: Event,
62 },
63
64 Tick,
66
67 Reload,
69
70 Announce(String),
75
76 Exit,
81}
82
83impl<T> Action<T> {
84 pub fn widget(operation: impl core::widget::Operation + 'static) -> Self {
86 Self::Widget(Box::new(operation))
87 }
88
89 fn output<O>(self) -> Result<T, Action<O>> {
90 match self {
91 Action::Output(output) => Ok(output),
92 Action::Widget(operation) => Err(Action::Widget(operation)),
93 Action::Clipboard(action) => Err(Action::Clipboard(action)),
94 Action::Window(action) => Err(Action::Window(action)),
95 Action::System(action) => Err(Action::System(action)),
96 Action::Font(action) => Err(Action::Font(action)),
97 Action::Image(action) => Err(Action::Image(action)),
98 Action::Event { window, event } => Err(Action::Event { window, event }),
99 Action::Tick => Err(Action::Tick),
100 Action::Reload => Err(Action::Reload),
101 Action::Exit => Err(Action::Exit),
102 Action::Announce(text) => Err(Action::Announce(text)),
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::Widget { .. } => {
115 write!(f, "Action::Widget")
116 }
117 Action::Clipboard(action) => {
118 write!(f, "Action::Clipboard({action:?})")
119 }
120 Action::Window(_) => write!(f, "Action::Window"),
121 Action::System(action) => write!(f, "Action::System({action:?})"),
122 Action::Font(action) => {
123 write!(f, "Action::Font({action:?})")
124 }
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 Action::Announce(text) => {
134 write!(f, "Action::Announce({text:?})")
135 }
136 }
137 }
138}
139
140#[cfg(feature = "a11y")]
145#[cfg_attr(docsrs, doc(cfg(feature = "a11y")))]
146pub fn announce<T>(text: impl Into<String>) -> Task<T> {
147 task::effect(Action::Announce(text.into()))
148}
149
150pub fn exit<T>() -> Task<T> {
155 task::effect(Action::Exit)
156}