#![doc(
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
pub mod clipboard;
pub mod dnd;
pub mod font;
pub mod keyboard;
pub mod overlay;
pub mod platform_specific;
pub mod program;
pub mod system;
pub mod task;
pub mod user_interface;
pub mod window;
#[cfg(feature = "multi-window")]
pub mod multi_window;
#[cfg(feature = "debug")]
#[path = "debug/basic.rs"]
mod debug;
#[cfg(not(feature = "debug"))]
#[path = "debug/null.rs"]
mod debug;
pub use iced_core as core;
pub use iced_futures as futures;
pub use debug::Debug;
pub use program::Program;
pub use task::Task;
pub use user_interface::UserInterface;
use crate::core::{widget, Color};
use crate::futures::futures::channel::oneshot;
use std::borrow::Cow;
use std::fmt;
pub enum Action<T> {
Output(T),
LoadFont {
bytes: Cow<'static, [u8]>,
channel: oneshot::Sender<Result<(), font::Error>>,
},
Widget(Box<dyn widget::Operation>),
Clipboard(clipboard::Action),
Window(window::Action),
System(system::Action),
Exit,
Dnd(crate::dnd::DndAction),
PlatformSpecific(crate::platform_specific::Action),
}
impl<T> Action<T> {
pub fn widget(operation: impl widget::Operation + 'static) -> Self {
Self::Widget(Box::new(operation))
}
fn output<O>(self) -> Result<T, Action<O>> {
match self {
Action::Output(output) => Ok(output),
Action::LoadFont { bytes, channel } => {
Err(Action::LoadFont { bytes, channel })
}
Action::Widget(operation) => Err(Action::Widget(operation)),
Action::Clipboard(action) => Err(Action::Clipboard(action)),
Action::Window(action) => Err(Action::Window(action)),
Action::System(action) => Err(Action::System(action)),
Action::Exit => Err(Action::Exit),
Action::Dnd(a) => Err(Action::Dnd(a)),
Action::PlatformSpecific(a) => Err(Action::PlatformSpecific(a)),
}
}
}
impl<T> fmt::Debug for Action<T>
where
T: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Action::Output(output) => write!(f, "Action::Output({output:?})"),
Action::LoadFont { .. } => {
write!(f, "Action::LoadFont")
}
Action::Widget { .. } => {
write!(f, "Action::Widget")
}
Action::Clipboard(action) => {
write!(f, "Action::Clipboard({action:?})")
}
Action::Window(_) => write!(f, "Action::Window"),
Action::System(action) => write!(f, "Action::System({action:?})"),
Action::Exit => write!(f, "Action::Exit"),
Action::PlatformSpecific(action) => {
write!(f, "Action::PlatformSpecific({:?})", action)
}
Action::Dnd(_) => write!(f, "Action::Dnd"),
}
}
}
pub fn exit<T>() -> Task<T> {
task::effect(Action::Exit)
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Appearance {
pub background_color: iced_core::Color,
pub text_color: iced_core::Color,
pub icon_color: iced_core::Color,
}
pub trait DefaultStyle {
fn default_style(&self) -> Appearance;
}
impl DefaultStyle for iced_core::Theme {
fn default_style(&self) -> Appearance {
default(self)
}
}
pub fn default(theme: &iced_core::Theme) -> Appearance {
let palette = theme.extended_palette();
Appearance {
background_color: palette.background.base.color,
text_color: palette.background.base.text,
icon_color: palette.background.base.text,
}
}