Skip to content

Commit 3e22619

Browse files
committed
Add animations example
1 parent 863963b commit 3e22619

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ auto-detect-theme = ["iced_core/auto-detect-theme"]
6767
strict-assertions = ["iced_renderer/strict-assertions"]
6868
# Redraws on every runtime event, and not only when a widget requests it
6969
unconditional-rendering = ["iced_winit/unconditional-rendering"]
70+
# Enables widget animations
71+
animations = ["iced_widget/animations"]
7072

7173
[dependencies]
7274
iced_core.workspace = true

examples/animations/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "animations"
3+
version = "0.1.0"
4+
authors = ["LazyTanuki"]
5+
edition = "2021"
6+
publish = false
7+
8+
[dependencies]
9+
iced.workspace = true
10+
iced.features = ["animations"]

examples/animations/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Animations
2+
3+
An application to showcase Iced widgets that have default animations.
4+
5+
The __[`main`]__ file contains all the code of the example.
6+
7+
You can run it with `cargo run`:
8+
```
9+
cargo run --package animations
10+
```
11+
12+
[`main`]: src/main.rs

examples/animations/src/main.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use iced::{
2+
widget::{column, Toggler},
3+
Element, Task, Theme,
4+
};
5+
6+
pub fn main() -> iced::Result {
7+
iced::application("Animated widgets", Animations::update, Animations::view)
8+
.theme(Animations::theme)
9+
.run()
10+
}
11+
12+
#[derive(Default)]
13+
struct Animations {
14+
toggled: bool,
15+
}
16+
17+
#[derive(Debug, Clone)]
18+
enum Message {
19+
Toggle(bool),
20+
}
21+
22+
impl Animations {
23+
fn update(&mut self, message: Message) -> Task<Message> {
24+
match message {
25+
Message::Toggle(t) => {
26+
self.toggled = t;
27+
Task::none()
28+
}
29+
}
30+
}
31+
32+
fn view(&self) -> Element<Message> {
33+
let main_text = iced::widget::text(
34+
"You can find all widgets with default animations here.",
35+
);
36+
let toggle = Toggler::new(self.toggled)
37+
.label("Toggle me!")
38+
.on_toggle(Message::Toggle);
39+
column![main_text, toggle]
40+
.spacing(10)
41+
.padding(50)
42+
.max_width(800)
43+
.into()
44+
}
45+
46+
fn theme(&self) -> Theme {
47+
Theme::Light
48+
}
49+
}

0 commit comments

Comments
 (0)