Skip to content

Commit

Permalink
Add feature flag for animations
Browse files Browse the repository at this point in the history
  • Loading branch information
BradySimon committed Jan 30, 2025
1 parent ba9e957 commit 5898c61
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions examples/scrollable/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ publish = false
[dependencies]
iced.workspace = true
iced.features = ["debug"]

[features]
animations = ["iced/animations"]
1 change: 1 addition & 0 deletions widget/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ wgpu = ["iced_renderer/wgpu"]
markdown = ["dep:pulldown-cmark", "dep:url"]
highlighter = ["dep:iced_highlighter"]
advanced = []
animations = []

[dependencies]
iced_renderer.workspace = true
Expand Down
31 changes: 26 additions & 5 deletions widget/src/radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,20 @@ where
pub text_state: widget::text::State<Paragraph>,
}

impl<Paragraph> State<Paragraph>
where
Paragraph: text::Paragraph,
{
/// Whether there is an active animation.
fn is_animating(&self) -> bool {
if cfg!(feature = "animations") {
self.scale_in.is_animating(self.now)

Check failure on line 291 in widget/src/radio.rs

View workflow job for this annotation

GitHub Actions / wasm

mismatched types
} else {
false
}
}
}

impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer>
for Radio<'_, Message, Theme, Renderer>
where
Expand Down Expand Up @@ -386,7 +400,7 @@ where
let state = tree.state.downcast_mut::<State<Renderer::Paragraph>>();
state.now = now;

Check failure on line 401 in widget/src/radio.rs

View workflow job for this annotation

GitHub Actions / wasm

mismatched types
self.last_status = Some(current_status);
if state.scale_in.is_animating(now) {
if state.is_animating() {
shell.request_redraw();
}
} else if self
Expand Down Expand Up @@ -454,10 +468,17 @@ where
);

let state = tree.state.downcast_ref::<State<Renderer::Paragraph>>();
if self.is_selected || state.scale_in.is_animating(state.now) {
let dot_size =
state.scale_in.interpolate(0.0, dot_size, state.now);
let alpha = state.scale_in.interpolate(0.0, 1.0, state.now);
if self.is_selected || state.is_animating() {
let dot_size = if cfg!(feature = "animations") {
state.scale_in.interpolate(0.0, dot_size, state.now)

Check failure on line 473 in widget/src/radio.rs

View workflow job for this annotation

GitHub Actions / wasm

mismatched types
} else {
dot_size
};
let alpha = if cfg!(feature = "animations") {
state.scale_in.interpolate(0.0, 1.0, state.now)

Check failure on line 478 in widget/src/radio.rs

View workflow job for this annotation

GitHub Actions / wasm

mismatched types
} else {
1.0
};
renderer.fill_quad(
renderer::Quad {
bounds: Rectangle {
Expand Down

0 comments on commit 5898c61

Please sign in to comment.