2019-11-22 19:36:57 +01:00
|
|
|
//! Iced is a cross-platform GUI library focused on simplicity and type-safety.
|
|
|
|
|
//! Inspired by [Elm].
|
|
|
|
|
//!
|
|
|
|
|
//! # Features
|
|
|
|
|
//! * Simple, easy-to-use, batteries-included API
|
|
|
|
|
//! * Type-safe, reactive programming model
|
|
|
|
|
//! * [Cross-platform support] (Windows, macOS, Linux, and the Web)
|
|
|
|
|
//! * Responsive layout
|
|
|
|
|
//! * Built-in widgets (including [text inputs], [scrollables], and more!)
|
|
|
|
|
//! * Custom widget support (create your own!)
|
|
|
|
|
//! * [Debug overlay with performance metrics]
|
|
|
|
|
//! * First-class support for async actions (use futures!)
|
|
|
|
|
//! * [Modular ecosystem] split into reusable parts:
|
|
|
|
|
//! * A [renderer-agnostic native runtime] enabling integration with existing
|
|
|
|
|
//! systems
|
|
|
|
|
//! * A [built-in renderer] supporting Vulkan, Metal, DX11, and DX12
|
|
|
|
|
//! * A [windowing shell]
|
|
|
|
|
//! * A [web runtime] leveraging the DOM
|
|
|
|
|
//!
|
|
|
|
|
//! Check out the [repository] and the [examples] for more details!
|
|
|
|
|
//!
|
2022-05-02 20:25:47 +02:00
|
|
|
//! [Cross-platform support]: https://github.com/iced-rs/iced/blob/master/docs/images/todos_desktop.jpg?raw=true
|
2023-09-07 05:05:43 +02:00
|
|
|
//! [text inputs]: https://iced.rs/examples/text_input.mp4
|
|
|
|
|
//! [scrollables]: https://iced.rs/examples/scrollable.mp4
|
|
|
|
|
//! [Debug overlay with performance metrics]: https://iced.rs/examples/debug.mp4
|
2022-05-02 20:25:47 +02:00
|
|
|
//! [Modular ecosystem]: https://github.com/iced-rs/iced/blob/master/ECOSYSTEM.md
|
2024-02-15 03:22:53 +01:00
|
|
|
//! [renderer-agnostic native runtime]: https://github.com/iced-rs/iced/tree/0.12/runtime
|
2019-11-22 19:36:57 +01:00
|
|
|
//! [`wgpu`]: https://github.com/gfx-rs/wgpu-rs
|
2024-02-15 03:22:53 +01:00
|
|
|
//! [built-in renderer]: https://github.com/iced-rs/iced/tree/0.12/wgpu
|
|
|
|
|
//! [windowing shell]: https://github.com/iced-rs/iced/tree/0.12/winit
|
2019-11-22 19:36:57 +01:00
|
|
|
//! [`dodrio`]: https://github.com/fitzgen/dodrio
|
2022-05-02 20:25:47 +02:00
|
|
|
//! [web runtime]: https://github.com/iced-rs/iced_web
|
2024-02-15 03:22:53 +01:00
|
|
|
//! [examples]: https://github.com/iced-rs/iced/tree/0.12/examples
|
2022-05-02 20:25:47 +02:00
|
|
|
//! [repository]: https://github.com/iced-rs/iced
|
2019-11-22 19:36:57 +01:00
|
|
|
//!
|
|
|
|
|
//! # Overview
|
|
|
|
|
//! Inspired by [The Elm Architecture], Iced expects you to split user
|
|
|
|
|
//! interfaces into four different concepts:
|
|
|
|
|
//!
|
|
|
|
|
//! * __State__ — the state of your application
|
|
|
|
|
//! * __Messages__ — user interactions or meaningful events that you care
|
|
|
|
|
//! about
|
|
|
|
|
//! * __View logic__ — a way to display your __state__ as widgets that
|
|
|
|
|
//! may produce __messages__ on user interaction
|
|
|
|
|
//! * __Update logic__ — a way to react to __messages__ and update your
|
|
|
|
|
//! __state__
|
|
|
|
|
//!
|
|
|
|
|
//! We can build something to see how this works! Let's say we want a simple
|
|
|
|
|
//! counter that can be incremented and decremented using two buttons.
|
|
|
|
|
//!
|
|
|
|
|
//! We start by modelling the __state__ of our application:
|
|
|
|
|
//!
|
|
|
|
|
//! ```
|
|
|
|
|
//! struct Counter {
|
|
|
|
|
//! // The counter value
|
|
|
|
|
//! value: i32,
|
|
|
|
|
//! }
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! Next, we need to define the possible user interactions of our counter:
|
|
|
|
|
//! the button presses. These interactions are our __messages__:
|
|
|
|
|
//!
|
|
|
|
|
//! ```
|
|
|
|
|
//! #[derive(Debug, Clone, Copy)]
|
|
|
|
|
//! pub enum Message {
|
|
|
|
|
//! IncrementPressed,
|
|
|
|
|
//! DecrementPressed,
|
|
|
|
|
//! }
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! Now, let's show the actual counter by putting it all together in our
|
|
|
|
|
//! __view logic__:
|
|
|
|
|
//!
|
|
|
|
|
//! ```
|
|
|
|
|
//! # struct Counter {
|
|
|
|
|
//! # // The counter value
|
|
|
|
|
//! # value: i32,
|
|
|
|
|
//! # }
|
|
|
|
|
//! #
|
|
|
|
|
//! # #[derive(Debug, Clone, Copy)]
|
|
|
|
|
//! # pub enum Message {
|
|
|
|
|
//! # IncrementPressed,
|
|
|
|
|
//! # DecrementPressed,
|
|
|
|
|
//! # }
|
|
|
|
|
//! #
|
2022-07-27 06:49:20 +02:00
|
|
|
//! use iced::widget::{button, column, text, Column};
|
2019-11-22 19:36:57 +01:00
|
|
|
//!
|
|
|
|
|
//! impl Counter {
|
2023-08-16 20:21:57 +02:00
|
|
|
//! pub fn view(&self) -> Column<Message> {
|
2019-11-22 19:36:57 +01:00
|
|
|
//! // We use a column: a simple vertical layout
|
2022-07-27 06:49:20 +02:00
|
|
|
//! column![
|
|
|
|
|
//! // The increment button. We tell it to produce an
|
|
|
|
|
//! // `IncrementPressed` message when pressed
|
|
|
|
|
//! button("+").on_press(Message::IncrementPressed),
|
|
|
|
|
//!
|
|
|
|
|
//! // We show the value of the counter here
|
2022-07-27 06:56:09 +02:00
|
|
|
//! text(self.value).size(50),
|
2022-07-27 06:49:20 +02:00
|
|
|
//!
|
|
|
|
|
//! // The decrement button. We tell it to produce a
|
2023-01-12 13:16:53 +01:00
|
|
|
//! // `DecrementPressed` message when pressed
|
2022-07-27 06:49:20 +02:00
|
|
|
//! button("-").on_press(Message::DecrementPressed),
|
|
|
|
|
//! ]
|
2019-11-22 19:36:57 +01:00
|
|
|
//! }
|
|
|
|
|
//! }
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! Finally, we need to be able to react to any produced __messages__ and change
|
|
|
|
|
//! our __state__ accordingly in our __update logic__:
|
|
|
|
|
//!
|
|
|
|
|
//! ```
|
|
|
|
|
//! # struct Counter {
|
|
|
|
|
//! # // The counter value
|
|
|
|
|
//! # value: i32,
|
|
|
|
|
//! # }
|
|
|
|
|
//! #
|
|
|
|
|
//! # #[derive(Debug, Clone, Copy)]
|
|
|
|
|
//! # pub enum Message {
|
|
|
|
|
//! # IncrementPressed,
|
|
|
|
|
//! # DecrementPressed,
|
|
|
|
|
//! # }
|
|
|
|
|
//! impl Counter {
|
|
|
|
|
//! // ...
|
|
|
|
|
//!
|
|
|
|
|
//! pub fn update(&mut self, message: Message) {
|
|
|
|
|
//! match message {
|
|
|
|
|
//! Message::IncrementPressed => {
|
|
|
|
|
//! self.value += 1;
|
|
|
|
|
//! }
|
|
|
|
|
//! Message::DecrementPressed => {
|
|
|
|
|
//! self.value -= 1;
|
|
|
|
|
//! }
|
|
|
|
|
//! }
|
|
|
|
|
//! }
|
|
|
|
|
//! }
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
|
|
|
|
//! And that's everything! We just wrote a whole user interface. Iced is now
|
|
|
|
|
//! able to:
|
|
|
|
|
//!
|
|
|
|
|
//! 1. Take the result of our __view logic__ and layout its widgets.
|
|
|
|
|
//! 1. Process events from our system and produce __messages__ for our
|
|
|
|
|
//! __update logic__.
|
|
|
|
|
//! 1. Draw the resulting user interface.
|
|
|
|
|
//!
|
|
|
|
|
//! # Usage
|
2020-04-01 04:35:24 +02:00
|
|
|
//! The [`Application`] and [`Sandbox`] traits should get you started quickly,
|
|
|
|
|
//! streamlining all the process described above!
|
2019-11-22 19:36:57 +01:00
|
|
|
//!
|
|
|
|
|
//! [Elm]: https://elm-lang.org/
|
|
|
|
|
//! [The Elm Architecture]: https://guide.elm-lang.org/architecture/
|
2021-12-08 08:04:46 +01:00
|
|
|
#![doc(
|
2021-12-09 15:10:38 +07:00
|
|
|
html_logo_url = "https://raw.githubusercontent.com/iced-rs/iced/9ab6923e943f784985e9ef9ca28b10278297225d/docs/logo.svg"
|
2021-12-08 08:04:46 +01:00
|
|
|
)]
|
2023-09-09 20:58:45 +02:00
|
|
|
#![forbid(rust_2018_idioms, unsafe_code)]
|
2022-07-09 18:03:59 +02:00
|
|
|
#![deny(
|
|
|
|
|
missing_debug_implementations,
|
|
|
|
|
missing_docs,
|
|
|
|
|
unused_results,
|
2023-09-09 20:58:45 +02:00
|
|
|
rustdoc::broken_intra_doc_links
|
2022-07-09 18:03:59 +02:00
|
|
|
)]
|
2023-05-11 17:28:51 +02:00
|
|
|
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
2024-01-08 16:00:17 +01:00
|
|
|
#![cfg_attr(docsrs, feature(doc_cfg))]
|
2023-03-04 05:37:11 +01:00
|
|
|
use iced_widget::graphics;
|
|
|
|
|
use iced_widget::renderer;
|
|
|
|
|
use iced_winit as shell;
|
|
|
|
|
use iced_winit::core;
|
2023-03-05 06:35:20 +01:00
|
|
|
use iced_winit::runtime;
|
2023-03-04 05:37:11 +01:00
|
|
|
|
|
|
|
|
pub use iced_futures::futures;
|
2022-07-09 18:03:59 +02:00
|
|
|
|
2023-09-19 20:48:50 +02:00
|
|
|
#[cfg(feature = "highlighter")]
|
|
|
|
|
pub use iced_highlighter as highlighter;
|
|
|
|
|
|
2020-09-08 00:35:17 +02:00
|
|
|
mod error;
|
2019-10-03 00:01:45 +02:00
|
|
|
|
2022-05-26 19:02:15 +02:00
|
|
|
pub mod application;
|
2024-03-16 05:33:47 +01:00
|
|
|
pub mod program;
|
2019-11-25 14:17:13 +01:00
|
|
|
pub mod settings;
|
2022-01-28 18:43:20 +07:00
|
|
|
pub mod time;
|
2020-01-16 05:54:22 +01:00
|
|
|
pub mod window;
|
2019-11-25 14:17:13 +01:00
|
|
|
|
2023-03-04 05:37:11 +01:00
|
|
|
#[cfg(feature = "advanced")]
|
|
|
|
|
pub mod advanced;
|
|
|
|
|
|
2023-07-12 12:23:18 -07:00
|
|
|
#[cfg(feature = "multi-window")]
|
2022-04-01 17:16:15 -03:00
|
|
|
pub mod multi_window;
|
|
|
|
|
|
2023-03-04 05:37:11 +01:00
|
|
|
pub use crate::core::alignment;
|
2024-01-20 13:29:25 +01:00
|
|
|
pub use crate::core::border;
|
|
|
|
|
pub use crate::core::color;
|
2023-05-19 03:32:21 +02:00
|
|
|
pub use crate::core::gradient;
|
2024-03-07 00:14:41 +01:00
|
|
|
pub use crate::core::theme;
|
2023-03-04 05:37:11 +01:00
|
|
|
pub use crate::core::{
|
2024-01-20 13:29:25 +01:00
|
|
|
Alignment, Background, Border, Color, ContentFit, Degrees, Gradient,
|
2024-03-07 00:14:41 +01:00
|
|
|
Length, Padding, Pixels, Point, Radians, Rectangle, Shadow, Size, Theme,
|
2023-10-24 05:34:03 +02:00
|
|
|
Transformation, Vector,
|
2023-03-04 05:37:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pub mod clipboard {
|
|
|
|
|
//! Access the clipboard.
|
2024-02-07 17:25:40 +01:00
|
|
|
pub use crate::runtime::clipboard::{
|
|
|
|
|
read, read_primary, write, write_primary,
|
|
|
|
|
};
|
2023-03-04 05:37:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub mod executor {
|
|
|
|
|
//! Choose your preferred executor to power your application.
|
|
|
|
|
pub use iced_futures::Executor;
|
|
|
|
|
|
|
|
|
|
/// A default cross-platform executor.
|
|
|
|
|
///
|
|
|
|
|
/// - On native platforms, it will use:
|
|
|
|
|
/// - `iced_futures::backend::native::tokio` when the `tokio` feature is enabled.
|
|
|
|
|
/// - `iced_futures::backend::native::async-std` when the `async-std` feature is
|
|
|
|
|
/// enabled.
|
|
|
|
|
/// - `iced_futures::backend::native::smol` when the `smol` feature is enabled.
|
|
|
|
|
/// - `iced_futures::backend::native::thread_pool` otherwise.
|
|
|
|
|
///
|
|
|
|
|
/// - On Wasm, it will use `iced_futures::backend::wasm::wasm_bindgen`.
|
|
|
|
|
pub type Default = iced_futures::backend::default::Executor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub mod font {
|
|
|
|
|
//! Load and use fonts.
|
|
|
|
|
pub use crate::core::font::*;
|
2023-03-05 06:35:20 +01:00
|
|
|
pub use crate::runtime::font::*;
|
2023-03-04 05:37:11 +01:00
|
|
|
}
|
|
|
|
|
|
2023-09-07 02:45:15 +02:00
|
|
|
pub mod event {
|
|
|
|
|
//! Handle events of a user interface.
|
|
|
|
|
pub use crate::core::event::{Event, MacOS, PlatformSpecific, Status};
|
|
|
|
|
pub use iced_futures::event::{listen, listen_raw, listen_with};
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-04 05:37:11 +01:00
|
|
|
pub mod keyboard {
|
|
|
|
|
//! Listen and react to keyboard events.
|
2024-01-16 13:28:00 +01:00
|
|
|
pub use crate::core::keyboard::key;
|
|
|
|
|
pub use crate::core::keyboard::{Event, Key, Location, Modifiers};
|
2023-09-07 02:45:15 +02:00
|
|
|
pub use iced_futures::keyboard::{on_key_press, on_key_release};
|
2023-03-04 05:37:11 +01:00
|
|
|
}
|
2020-05-27 05:05:13 +02:00
|
|
|
|
2023-03-04 05:37:11 +01:00
|
|
|
pub mod mouse {
|
|
|
|
|
//! Listen and react to mouse events.
|
2023-06-08 20:11:59 +02:00
|
|
|
pub use crate::core::mouse::{
|
|
|
|
|
Button, Cursor, Event, Interaction, ScrollDelta,
|
|
|
|
|
};
|
2023-03-04 05:37:11 +01:00
|
|
|
}
|
2020-05-27 05:05:13 +02:00
|
|
|
|
2023-11-29 00:14:27 +01:00
|
|
|
pub mod command {
|
|
|
|
|
//! Run asynchronous actions.
|
|
|
|
|
pub use crate::runtime::command::{channel, Command};
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-05 04:15:10 +01:00
|
|
|
pub mod subscription {
|
|
|
|
|
//! Listen to external events in your application.
|
|
|
|
|
pub use iced_futures::subscription::{
|
2023-09-07 02:45:15 +02:00
|
|
|
channel, run, run_with_id, unfold, Subscription,
|
2023-03-05 04:15:10 +01:00
|
|
|
};
|
|
|
|
|
}
|
2020-05-27 05:05:13 +02:00
|
|
|
|
2023-03-04 05:37:11 +01:00
|
|
|
#[cfg(feature = "system")]
|
|
|
|
|
pub mod system {
|
|
|
|
|
//! Retrieve system information.
|
2023-03-05 06:35:20 +01:00
|
|
|
pub use crate::runtime::system::Information;
|
2023-03-04 05:37:11 +01:00
|
|
|
pub use crate::shell::system::*;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub mod overlay {
|
|
|
|
|
//! Display interactive elements on top of other widgets.
|
|
|
|
|
|
2023-09-09 12:24:47 +02:00
|
|
|
/// A generic overlay.
|
2023-03-04 05:37:11 +01:00
|
|
|
///
|
2023-09-09 12:24:47 +02:00
|
|
|
/// This is an alias of an [`overlay::Element`] with a default `Renderer`.
|
2023-03-04 05:37:11 +01:00
|
|
|
///
|
2023-09-09 12:24:47 +02:00
|
|
|
/// [`overlay::Element`]: crate::core::overlay::Element
|
2024-01-21 17:56:01 +01:00
|
|
|
pub type Element<
|
|
|
|
|
'a,
|
|
|
|
|
Message,
|
|
|
|
|
Theme = crate::Renderer,
|
|
|
|
|
Renderer = crate::Renderer,
|
|
|
|
|
> = crate::core::overlay::Element<'a, Message, Theme, Renderer>;
|
2023-03-04 05:37:11 +01:00
|
|
|
|
|
|
|
|
pub use iced_widget::overlay::*;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub mod touch {
|
|
|
|
|
//! Listen and react to touch events.
|
|
|
|
|
pub use crate::core::touch::{Event, Finger};
|
|
|
|
|
}
|
2020-05-27 05:05:13 +02:00
|
|
|
|
2023-08-26 01:34:42 +02:00
|
|
|
#[allow(hidden_glob_reexports)]
|
2023-03-04 05:37:11 +01:00
|
|
|
pub mod widget {
|
|
|
|
|
//! Use the built-in widgets or create your own.
|
|
|
|
|
pub use iced_widget::*;
|
|
|
|
|
|
|
|
|
|
// We hide the re-exported modules by `iced_widget`
|
|
|
|
|
mod core {}
|
|
|
|
|
mod graphics {}
|
|
|
|
|
mod native {}
|
|
|
|
|
mod renderer {}
|
|
|
|
|
mod style {}
|
2023-06-27 19:41:03 +02:00
|
|
|
mod runtime {}
|
2023-03-04 05:37:11 +01:00
|
|
|
}
|
2022-05-14 01:47:55 +02:00
|
|
|
|
2019-11-21 18:00:27 +01:00
|
|
|
pub use application::Application;
|
2023-11-29 00:14:27 +01:00
|
|
|
pub use command::Command;
|
2020-09-08 00:35:17 +02:00
|
|
|
pub use error::Error;
|
2022-08-02 04:20:47 +02:00
|
|
|
pub use event::Event;
|
2020-01-20 05:43:09 +01:00
|
|
|
pub use executor::Executor;
|
2023-02-04 11:12:15 +01:00
|
|
|
pub use font::Font;
|
2024-03-16 05:33:47 +01:00
|
|
|
pub use program::Program;
|
2024-01-21 17:56:01 +01:00
|
|
|
pub use renderer::Renderer;
|
2019-11-25 14:17:13 +01:00
|
|
|
pub use settings::Settings;
|
2022-08-02 04:20:47 +02:00
|
|
|
pub use subscription::Subscription;
|
2020-01-20 05:43:09 +01:00
|
|
|
|
2023-03-04 05:37:11 +01:00
|
|
|
/// A generic widget.
|
|
|
|
|
///
|
|
|
|
|
/// This is an alias of an `iced_native` element with a default `Renderer`.
|
2024-01-21 17:56:01 +01:00
|
|
|
pub type Element<
|
|
|
|
|
'a,
|
|
|
|
|
Message,
|
|
|
|
|
Theme = crate::Theme,
|
|
|
|
|
Renderer = crate::Renderer,
|
|
|
|
|
> = crate::core::Element<'a, Message, Theme, Renderer>;
|
2023-03-04 05:37:11 +01:00
|
|
|
|
|
|
|
|
/// The result of running an [`Application`].
|
|
|
|
|
///
|
|
|
|
|
/// [`Application`]: crate::Application
|
|
|
|
|
pub type Result = std::result::Result<(), Error>;
|
2024-03-16 05:33:47 +01:00
|
|
|
|
|
|
|
|
/// Runs a basic iced application with default [`Settings`] given
|
|
|
|
|
/// - its window title,
|
|
|
|
|
/// - its update logic,
|
|
|
|
|
/// - and its view logic.
|
|
|
|
|
///
|
|
|
|
|
/// # Example
|
|
|
|
|
/// ```no_run
|
|
|
|
|
/// use iced::widget::{button, column, text, Column};
|
|
|
|
|
///
|
|
|
|
|
/// pub fn main() -> iced::Result {
|
|
|
|
|
/// iced::run("A counter", update, view)
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// #[derive(Debug, Clone)]
|
|
|
|
|
/// enum Message {
|
|
|
|
|
/// Increment,
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// fn update(value: &mut u64, message: Message) {
|
|
|
|
|
/// match message {
|
|
|
|
|
/// Message::Increment => *value += 1,
|
|
|
|
|
/// }
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// fn view(value: &u64) -> Column<Message> {
|
|
|
|
|
/// column![
|
|
|
|
|
/// text(value),
|
|
|
|
|
/// button("+").on_press(Message::Increment),
|
|
|
|
|
/// ]
|
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
|
|
|
|
pub fn run<State, Message>(
|
2024-03-16 15:53:03 +01:00
|
|
|
title: impl program::Title<State> + 'static,
|
2024-03-16 19:14:13 +01:00
|
|
|
update: impl program::Update<State, Message> + 'static,
|
2024-03-16 05:33:47 +01:00
|
|
|
view: impl for<'a> program::View<'a, State, Message> + 'static,
|
|
|
|
|
) -> Result
|
|
|
|
|
where
|
|
|
|
|
State: Default + 'static,
|
|
|
|
|
Message: std::fmt::Debug + Send + 'static,
|
|
|
|
|
{
|
2024-03-16 19:14:13 +01:00
|
|
|
application(title, update, view).run()
|
2024-03-16 05:33:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[doc(inline)]
|
2024-03-16 19:14:13 +01:00
|
|
|
pub use program::application;
|