Skip to content

Commit

Permalink
added toggling
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertasJ committed Oct 13, 2024
1 parent bfbdda1 commit 1086e04
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/hooks/src/use_animate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use dioxus_hooks::{use_memo, use_signal};
use dioxus_signals::{Memo, ReadOnlySignal, Readable, Signal, UnsyncStorage, Writable, Write};
use freya_engine::prelude::{Color, HSV};
use freya_node_state::Parse;
use torin::direction;

use crate::{use_platform, UsePlatform};
/// ```
Expand All @@ -28,7 +29,6 @@ impl Easable for Color {
fn ease(self, to: Self, time: u32, duration: u32, function: EasingFunction) -> Self::Output {
let hsv1 = self.to_hsv();
let hsv2 = to.to_hsv();

let h = function(time as f32, hsv1.h, hsv2.h - hsv1.h, duration as f32);
let s = function(time as f32, hsv1.s, hsv2.s - hsv1.s, duration as f32);
let v = function(time as f32, hsv1.v, hsv2.v - hsv1.v, duration as f32);
Expand Down Expand Up @@ -273,6 +273,7 @@ impl<O: 'static + Clone, Animated: AnimatedValue<Output = O> + Clone + PartialEq
anchor =
offset_time(last_direction, anchor, offset).expect("to not underflow");
offset = Instant::now();

last_direction = *direction.peek();
}

Expand All @@ -287,6 +288,14 @@ impl<O: 'static + Clone, Animated: AnimatedValue<Output = O> + Clone + PartialEq
}
}

pub fn toggle(&mut self) {
let direction = match *self.direction.peek() {
Direction::Forward => Direction::Backward,
Direction::Backward => Direction::Forward,
};
self.run(direction);
}

pub fn value(&self) -> ReadOnlySignal<O> {
ReadOnlySignal::new(self.value)
}
Expand Down

0 comments on commit 1086e04

Please sign in to comment.