iced_runtime/
lib.rs
1#![doc(
9 html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
10)]
11#![cfg_attr(docsrs, feature(doc_auto_cfg))]
12pub mod clipboard;
13pub mod dnd;
14pub mod font;
15pub mod keyboard;
16pub mod overlay;
17pub mod platform_specific;
18pub mod program;
19pub mod system;
20pub mod task;
21pub mod user_interface;
22pub mod window;
23
24#[cfg(feature = "multi-window")]
25pub mod multi_window;
26
27#[cfg(feature = "debug")]
30#[path = "debug/basic.rs"]
31mod debug;
32#[cfg(not(feature = "debug"))]
33#[path = "debug/null.rs"]
34mod debug;
35
36pub use iced_core as core;
37pub use iced_futures as futures;
38
39pub use debug::Debug;
40pub use program::Program;
41pub use task::Task;
42pub use user_interface::UserInterface;
43
44use crate::core::{widget, Color};
45use crate::futures::futures::channel::oneshot;
46
47use std::borrow::Cow;
48use std::fmt;
49
50pub enum Action<T> {
52 Output(T),
54
55 LoadFont {
57 bytes: Cow<'static, [u8]>,
59 channel: oneshot::Sender<Result<(), font::Error>>,
61 },
62
63 Widget(Box<dyn widget::Operation>),
65
66 Clipboard(clipboard::Action),
68
69 Window(window::Action),
71
72 System(system::Action),
74
75 Exit,
80
81 Dnd(crate::dnd::DndAction),
83
84 PlatformSpecific(crate::platform_specific::Action),
86}
87
88impl<T> Action<T> {
89 pub fn widget(operation: impl 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 } => {
98 Err(Action::LoadFont { bytes, channel })
99 }
100 Action::Widget(operation) => Err(Action::Widget(operation)),
101 Action::Clipboard(action) => Err(Action::Clipboard(action)),
102 Action::Window(action) => Err(Action::Window(action)),
103 Action::System(action) => Err(Action::System(action)),
104 Action::Exit => Err(Action::Exit),
105 Action::Dnd(a) => Err(Action::Dnd(a)),
106 Action::PlatformSpecific(a) => Err(Action::PlatformSpecific(a)),
107 }
108 }
109}
110
111impl<T> fmt::Debug for Action<T>
112where
113 T: fmt::Debug,
114{
115 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
116 match self {
117 Action::Output(output) => write!(f, "Action::Output({output:?})"),
118 Action::LoadFont { .. } => {
119 write!(f, "Action::LoadFont")
120 }
121 Action::Widget { .. } => {
122 write!(f, "Action::Widget")
123 }
124 Action::Clipboard(action) => {
125 write!(f, "Action::Clipboard({action:?})")
126 }
127 Action::Window(_) => write!(f, "Action::Window"),
128 Action::System(action) => write!(f, "Action::System({action:?})"),
129 Action::Exit => write!(f, "Action::Exit"),
130 Action::PlatformSpecific(action) => {
131 write!(f, "Action::PlatformSpecific({:?})", action)
132 }
133 Action::Dnd(_) => write!(f, "Action::Dnd"),
134 }
135 }
136}
137
138pub fn exit<T>() -> Task<T> {
143 task::effect(Action::Exit)
144}
145
146#[derive(Debug, Clone, Copy, PartialEq)]
148pub struct Appearance {
149 pub background_color: iced_core::Color,
151
152 pub text_color: iced_core::Color,
154
155 pub icon_color: iced_core::Color,
157}
158
159pub trait DefaultStyle {
161 fn default_style(&self) -> Appearance;
163}
164
165impl DefaultStyle for iced_core::Theme {
166 fn default_style(&self) -> Appearance {
167 default(self)
168 }
169}
170
171pub fn default(theme: &iced_core::Theme) -> Appearance {
173 let palette = theme.extended_palette();
174
175 Appearance {
176 background_color: palette.background.base.color,
177 text_color: palette.background.base.text,
178 icon_color: palette.background.base.text,
179 }
180}