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 Exit,
75}
76
77impl<T> Action<T> {
78 pub fn widget(operation: impl core::widget::Operation + 'static) -> Self {
80 Self::Widget(Box::new(operation))
81 }
82
83 fn output<O>(self) -> Result<T, Action<O>> {
84 match self {
85 Action::Output(output) => Ok(output),
86 Action::Widget(operation) => Err(Action::Widget(operation)),
87 Action::Clipboard(action) => Err(Action::Clipboard(action)),
88 Action::Window(action) => Err(Action::Window(action)),
89 Action::System(action) => Err(Action::System(action)),
90 Action::Font(action) => Err(Action::Font(action)),
91 Action::Image(action) => Err(Action::Image(action)),
92 Action::Event { window, event } => Err(Action::Event { window, event }),
93 Action::Tick => Err(Action::Tick),
94 Action::Reload => Err(Action::Reload),
95 Action::Exit => Err(Action::Exit),
96 }
97 }
98}
99
100impl<T> fmt::Debug for Action<T>
101where
102 T: fmt::Debug,
103{
104 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
105 match self {
106 Action::Output(output) => write!(f, "Action::Output({output:?})"),
107 Action::Widget { .. } => {
108 write!(f, "Action::Widget")
109 }
110 Action::Clipboard(action) => {
111 write!(f, "Action::Clipboard({action:?})")
112 }
113 Action::Window(_) => write!(f, "Action::Window"),
114 Action::System(action) => write!(f, "Action::System({action:?})"),
115 Action::Font(action) => {
116 write!(f, "Action::Font({action:?})")
117 }
118 Action::Image(_) => write!(f, "Action::Image"),
119 Action::Event { window, event } => write!(
120 f,
121 "Action::Event {{ window: {window:?}, event: {event:?} }}"
122 ),
123 Action::Tick => write!(f, "Action::Tick"),
124 Action::Reload => write!(f, "Action::Reload"),
125 Action::Exit => write!(f, "Action::Exit"),
126 }
127 }
128}
129
130pub fn exit<T>() -> Task<T> {
135 task::effect(Action::Exit)
136}