From f3ae4266e9727940ba0d0e8469362923590916f4 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 9 Feb 2025 06:38:48 +0100 Subject: Implement `From` instead of `u16` for `Length` and `Pixels` --- core/src/length.rs | 6 +++--- core/src/pixels.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'core') diff --git a/core/src/length.rs b/core/src/length.rs index 5f24169f..363833c4 100644 --- a/core/src/length.rs +++ b/core/src/length.rs @@ -77,8 +77,8 @@ impl From for Length { } } -impl From for Length { - fn from(units: u16) -> Self { - Length::Fixed(f32::from(units)) +impl From for Length { + fn from(units: u32) -> Self { + Length::Fixed(units as f32) } } diff --git a/core/src/pixels.rs b/core/src/pixels.rs index 7d6267cf..c87e2b31 100644 --- a/core/src/pixels.rs +++ b/core/src/pixels.rs @@ -20,9 +20,9 @@ impl From for Pixels { } } -impl From for Pixels { - fn from(amount: u16) -> Self { - Self(f32::from(amount)) +impl From for Pixels { + fn from(amount: u32) -> Self { + Self(amount as f32) } } -- cgit From ec4d007a4cafa005a61aa24a47960e5d639b5587 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 9 Feb 2025 08:02:05 +0100 Subject: Simplify `gallery` example a bit --- core/src/animation.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'core') diff --git a/core/src/animation.rs b/core/src/animation.rs index 258fd084..14cbb5c3 100644 --- a/core/src/animation.rs +++ b/core/src/animation.rs @@ -13,6 +13,7 @@ where T: Clone + Copy + PartialEq + Float, { raw: lilt::Animated, + duration: Duration, // TODO: Expose duration getter in `lilt` } impl Animation @@ -23,6 +24,7 @@ where pub fn new(state: T) -> Self { Self { raw: lilt::Animated::new(state), + duration: Duration::from_millis(100), } } @@ -58,6 +60,7 @@ where /// Sets the duration of the [`Animation`] to the given value. pub fn duration(mut self, duration: Duration) -> Self { self.raw = self.raw.duration(duration.as_secs_f32() * 1_000.0); + self.duration = duration; self } @@ -133,4 +136,13 @@ impl Animation { { self.raw.animate_bool(start, end, at) } + + /// Returns the remaining [`Duration`] of the [`Animation`]. + pub fn remaining(&self, at: Instant) -> Duration { + Duration::from_secs_f32(self.interpolate( + self.duration.as_secs_f32(), + 0.0, + at, + )) + } } -- cgit