diff --git a/Cargo.lock b/Cargo.lock index 5e14e0ff70..811f63810c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -115,6 +115,13 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" +[[package]] +name = "animations" +version = "0.1.0" +dependencies = [ + "iced", +] + [[package]] name = "anstyle" version = "1.0.10" diff --git a/Cargo.toml b/Cargo.toml index d365e14696..c9e604f9c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,6 +67,8 @@ auto-detect-theme = ["iced_core/auto-detect-theme"] strict-assertions = ["iced_renderer/strict-assertions"] # Redraws on every runtime event, and not only when a widget requests it unconditional-rendering = ["iced_winit/unconditional-rendering"] +# Enables widget animations +animations = ["iced_widget/animations"] [dependencies] iced_core.workspace = true diff --git a/examples/animations/Cargo.toml b/examples/animations/Cargo.toml new file mode 100644 index 0000000000..d08ab4094e --- /dev/null +++ b/examples/animations/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "animations" +version = "0.1.0" +authors = ["LazyTanuki"] +edition = "2021" +publish = false + +[dependencies] +iced.workspace = true +iced.features = ["animations"] diff --git a/examples/animations/README.md b/examples/animations/README.md new file mode 100644 index 0000000000..e952e8d8d4 --- /dev/null +++ b/examples/animations/README.md @@ -0,0 +1,12 @@ +# Animations + +An application to showcase Iced widgets that have default animations. + +The __[`main`]__ file contains all the code of the example. + +You can run it with `cargo run`: +``` +cargo run --package animations +``` + +[`main`]: src/main.rs diff --git a/examples/animations/src/main.rs b/examples/animations/src/main.rs new file mode 100644 index 0000000000..54a30c7a83 --- /dev/null +++ b/examples/animations/src/main.rs @@ -0,0 +1,49 @@ +use iced::{ + widget::{column, Toggler}, + Element, Task, Theme, +}; + +pub fn main() -> iced::Result { + iced::application("Animated widgets", Animations::update, Animations::view) + .theme(Animations::theme) + .run() +} + +#[derive(Default)] +struct Animations { + toggled: bool, +} + +#[derive(Debug, Clone)] +enum Message { + Toggle(bool), +} + +impl Animations { + fn update(&mut self, message: Message) -> Task { + match message { + Message::Toggle(t) => { + self.toggled = t; + Task::none() + } + } + } + + fn view(&self) -> Element { + let main_text = iced::widget::text( + "You can find all widgets with default animations here.", + ); + let toggle = Toggler::new(self.toggled) + .label("Toggle me!") + .on_toggle(Message::Toggle); + column![main_text, toggle] + .spacing(10) + .padding(50) + .max_width(800) + .into() + } + + fn theme(&self) -> Theme { + Theme::Light + } +}