Skip to content

Conversation

@LeonMatthes
Copy link
Contributor

Allow animate properties with a binding to re-query their PropertyAnimation whenever the binding to the property changes.

Closes #348

self.animation_data.borrow_mut().reset();
let mut animation_data = self.animation_data.borrow_mut();
animation_data.reset();
if let Some((details, start_time)) = (self.compute_animation_details)() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might not be good to call something that can query other properties from mark_dirty or we could end up in bad recursion.
Was it a problem to query it on the next frame in ShouldStart as before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I wanted to discuss this anyhow. This is a quick fix to be able to use current_tick() for an initial test and definitely not optimal. We'll probably want to modify the Animation::Transition type so that we can make the time Option.

Another downside to evaluating the PropertyAnimation inside evaluate is that from a user perspective it becomes very hard to predict when the animation data is computed.
It doesn't happen when the binding to the animated property changes, but rather when the animated property is first read, which could be unintuitive.
@NigelBreslaw agress that the values should remain constant after the animation starts ( #348 (comment) ), but this makes it somewhat hard to determine when exactly "the animation starts".

But maybe documenting this behavior of "the animation data is queried when the property is first read after modification", is probably good enough.

This avoids re-evaluating the PropertyAnimation during the mark_dirty
function and re-evaluates it on the first call to evaluate.
This has been replaced by set_animated_binding_for_transition
The `state` variable is referenced by both expressions, so using a
single CodeBlock is easier.
In the generated code, use tuple destructuring to convert the Instant to
an Option<Instant>.
@LeonMatthes LeonMatthes force-pushed the lm/348-animate-reactive branch from 969095e to 1bd8318 Compare January 14, 2026 16:33
@LeonMatthes LeonMatthes marked this pull request as ready for review January 19, 2026 09:27
Copy link
Member

@ogoffart ogoffart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thank you.

Please squash and merge

&animation_data, nullptr);
}

template<typename F, typename Trans>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nitpick: Maybe this can be renamed A for animation

(Out of scope for this PR, but concepts here would really help to read this code as to what this type is supposed to be)

@LeonMatthes LeonMatthes merged commit 09cc757 into slint-ui:master Jan 19, 2026
41 checks passed
R-Cramer4 pushed a commit to R-Cramer4/slint that referenced this pull request Jan 19, 2026
* Add test case for reactive Animate bindings

See issue slint-ui#348

* Add C++ test case for animate bindings reactivity

* Fix animted property bindings for C++ and Rust

* Fix animate bindings reactivity in interpreter

* Use optional start time instead of current_tick

This avoids re-evaluating the PropertyAnimation during the mark_dirty
function and re-evaluates it on the first call to evaluate.

* Remove set_animated_binding

This has been replaced by set_animated_binding_for_transition

* Rename set_animated_binding_for_transation to set_animated_binding

* Revert Animation::Transition to a single CodeBlock

The `state` variable is referenced by both expressions, so using a
single CodeBlock is easier.
In the generated code, use tuple destructuring to convert the Instant to
an Option<Instant>.

* Fix set_animated_binding unit tests
burhankhanzada pushed a commit to burhankhanzada/slint that referenced this pull request Jan 20, 2026
* Add test case for reactive Animate bindings

See issue slint-ui#348

* Add C++ test case for animate bindings reactivity

* Fix animted property bindings for C++ and Rust

* Fix animate bindings reactivity in interpreter

* Use optional start time instead of current_tick

This avoids re-evaluating the PropertyAnimation during the mark_dirty
function and re-evaluates it on the first call to evaluate.

* Remove set_animated_binding

This has been replaced by set_animated_binding_for_transition

* Rename set_animated_binding_for_transation to set_animated_binding

* Revert Animation::Transition to a single CodeBlock

The `state` variable is referenced by both expressions, so using a
single CodeBlock is easier.
In the generated code, use tuple destructuring to convert the Instant to
an Option<Instant>.

* Fix set_animated_binding unit tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Animate bindings are not reactive and can't reference property set or initialized after

2 participants