summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/animation.rs12
-rw-r--r--core/src/length.rs6
-rw-r--r--core/src/pixels.rs6
-rw-r--r--core/src/widget/operation/focusable.rs27
4 files changed, 45 insertions, 6 deletions
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<T, Instant>,
+ duration: Duration, // TODO: Expose duration getter in `lilt`
}
impl<T> Animation<T>
@@ -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<bool> {
{
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,
+ ))
+ }
}
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<f32> for Length {
}
}
-impl From<u16> for Length {
- fn from(units: u16) -> Self {
- Length::Fixed(f32::from(units))
+impl From<u32> 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<f32> for Pixels {
}
}
-impl From<u16> for Pixels {
- fn from(amount: u16) -> Self {
- Self(f32::from(amount))
+impl From<u32> for Pixels {
+ fn from(amount: u32) -> Self {
+ Self(amount as f32)
}
}
diff --git a/core/src/widget/operation/focusable.rs b/core/src/widget/operation/focusable.rs
index 8f66e575..a1327bc1 100644
--- a/core/src/widget/operation/focusable.rs
+++ b/core/src/widget/operation/focusable.rs
@@ -61,6 +61,33 @@ pub fn focus<T>(target: Id) -> impl Operation<T> {
Focus { target }
}
+/// Produces an [`Operation`] that unfocuses the focused widget.
+pub fn unfocus<T>() -> impl Operation<T> {
+ struct Unfocus;
+
+ impl<T> Operation<T> for Unfocus {
+ fn focusable(
+ &mut self,
+ _id: Option<&Id>,
+ _bounds: Rectangle,
+ state: &mut dyn Focusable,
+ ) {
+ state.unfocus();
+ }
+
+ fn container(
+ &mut self,
+ _id: Option<&Id>,
+ _bounds: Rectangle,
+ operate_on_children: &mut dyn FnMut(&mut dyn Operation<T>),
+ ) {
+ operate_on_children(self);
+ }
+ }
+
+ Unfocus
+}
+
/// Produces an [`Operation`] that generates a [`Count`] and chains it with the
/// provided function to build a new [`Operation`].
pub fn count() -> impl Operation<Count> {