mirror of
https://github.com/danbulant/cushy
synced 2026-06-21 15:42:07 +00:00
LinearInterpolation now requires PartialEq
This also means that if an animation is animating over discrete values and the actual value has not changed, the Dynamic will no longer detect a change because it's now using update instead of set.
This commit is contained in:
parent
a818cc41fd
commit
58b98a9a16
5 changed files with 7 additions and 9 deletions
|
|
@ -13,12 +13,12 @@ fn main() -> gooey::Result {
|
|||
Resize::width(Lp::points(100), Label::new(label))
|
||||
.and(Button::new("+").on_click(counter.with_clone(|counter| {
|
||||
move |_| {
|
||||
counter.set(counter.get() + 1);
|
||||
*counter.lock() += 1;
|
||||
}
|
||||
})))
|
||||
.and(Button::new("-").on_click(counter.with_clone(|counter| {
|
||||
move |_| {
|
||||
counter.set(counter.get() - 1);
|
||||
*counter.lock() -= 1;
|
||||
}
|
||||
}))),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -210,11 +210,11 @@ where
|
|||
fn update(&self, percent: f32) {
|
||||
self.change
|
||||
.dynamic
|
||||
.set(self.start.lerp(&self.change.new_value, percent));
|
||||
.update(self.start.lerp(&self.change.new_value, percent));
|
||||
}
|
||||
|
||||
fn finish(&self) {
|
||||
self.change.dynamic.set(self.change.new_value.clone());
|
||||
self.change.dynamic.update(self.change.new_value.clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -606,7 +606,7 @@ impl Animate for Duration {
|
|||
}
|
||||
|
||||
/// Performs a linear interpolation between two values.
|
||||
pub trait LinearInterpolate {
|
||||
pub trait LinearInterpolate: PartialEq {
|
||||
/// Interpolate linearly between `self` and `target` using `percent`.
|
||||
#[must_use]
|
||||
fn lerp(&self, target: &Self, percent: f32) -> Self;
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ impl<T> Dynamic<T> {
|
|||
/// equal to the currently stored value.
|
||||
pub fn update(&self, new_value: T)
|
||||
where
|
||||
T: Eq,
|
||||
T: PartialEq,
|
||||
{
|
||||
self.0.map_mut(|value, changed| {
|
||||
if *value == new_value {
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ impl Button {
|
|||
.spawn();
|
||||
}
|
||||
(true, Some(dynamic)) => {
|
||||
dynamic.set(background_color);
|
||||
dynamic.update(background_color);
|
||||
self.background_color_animation.clear();
|
||||
}
|
||||
(_, None) => {
|
||||
|
|
|
|||
|
|
@ -736,8 +736,6 @@ where
|
|||
) {
|
||||
match event {
|
||||
WindowCommand::Redraw => {
|
||||
// TODO we should attempt to batch redraw events so that we're
|
||||
// not constantly sending them from animations.
|
||||
window.set_needs_redraw();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue