From e18425e0ca76cdfdcf95c0ae0fbda7fce63b6670 Mon Sep 17 00:00:00 2001 From: Victoria Fischer Date: Tue, 24 Mar 2026 12:37:53 +0100 Subject: [PATCH] tasks: ui: use const animators --- src/tasks/ui.rs | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/tasks/ui.rs b/src/tasks/ui.rs index 8c94698..3d5a7e7 100644 --- a/src/tasks/ui.rs +++ b/src/tasks/ui.rs @@ -7,6 +7,19 @@ use log::*; use crate::{animation::{AnimatedSurface, Animation}, ego::engine::MotionState, events::{Personality, Prediction, Scene, SensorSource, SensorState}, graphics::{display::{SegmentSpace, Uniforms}, shaders::*}}; +const NOTIFY_FADE_IN: Animation = Animation::new().duration(Duration::from_millis(30)) .from(Fract8::MIN).to(Fract8::MAX); +const NOTIFY_PULSE_OUT: Animation = Animation::new().duration(Duration::from_millis(100)).from(Fract8::MAX).to(Fract8::from_raw(60)); +const NOTIFY_PULSE_IN: Animation = Animation::new().duration(Duration::from_millis(100)).from(Fract8::MIN).to(Fract8::MAX); +const NOTIFY_FADE_OUT: Animation = Animation::new().duration(Duration::from_secs(2)) .from(Fract8::MAX).to(Fract8::MIN); + +const FG_FADE_OUT: Animation = Animation::new().duration(Duration::from_millis(300)).to(Fract8::MIN); +const BG_FADE_IN: Animation = Animation::new().duration(Duration::from_millis(300)).to(Fract8::from_raw(128)); + +const TAIL: Animation = Animation::new().duration(Duration::from_millis(300)).to(Fract8::from_raw(96)); +const PANELS: Animation = Animation::new().duration(Duration::from_millis(300)).to(Fract8::from_raw(128)); +const BG: Animation = Animation::new().duration(Duration::from_millis(300)).to(Fract8::from_raw(32)); +const MOTION: Animation = Animation::new().duration(Duration::from_secs(1)) .to(Fract8::MIN); + pub struct Ui { // Background layer provides an always-running background for everything to draw on background: AnimatedSurface, @@ -53,25 +66,21 @@ impl) { - let fade_in = Animation::default().from(Fract8::MIN).to(Fract8::MAX).duration(Duration::from_millis(30)); - let pulse_out = Animation::default().from(Fract8::MAX).to(Fract8::from_raw(60)).duration(Duration::from_millis(100)); - let pulse_in = Animation::default().from(Fract8::MIN).to(Fract8::MAX).duration(Duration::from_millis(100)); - let fade_out = Animation::default().from(Fract8::MAX).to(Fract8::MIN).duration(Duration::from_secs(2)); info!("Flashing notification {color}"); self.notification.set_visible(true); self.notification.set_shader(Background::from_color(color)); - fade_in.apply([&mut self.notification]).await; + NOTIFY_FADE_IN.apply([&mut self.notification]).await; // Pulse quickly 5 times for _ in 0..5 { - pulse_out.apply([&mut self.notification]).await; - pulse_in.apply([&mut self.notification]).await; + NOTIFY_PULSE_OUT.apply([&mut self.notification]).await; + NOTIFY_PULSE_IN.apply([&mut self.notification]).await; } - fade_out.apply([&mut self.notification]).await; + NOTIFY_FADE_OUT.apply([&mut self.notification]).await; self.notification.set_visible(false); } @@ -93,26 +102,20 @@ impl { - let tail = Animation::default().duration(Duration::from_millis(300)).to(Fract8::from_raw(96)); - let panels = Animation::default().duration(Duration::from_millis(300)).to(Fract8::from_raw(128)); - let bg = Animation::default().duration(Duration::from_millis(300)).to(Fract8::from_raw(32)); - let motion = Animation::default().duration(Duration::from_secs(1)).to(Fract8::MIN); embassy_futures::join::join4( - tail.apply([&mut self.tail]), - panels.apply([&mut self.panels]), - bg.apply([&mut self.background]), - motion.apply([&mut self.motion]) + TAIL.apply([&mut self.tail]), + PANELS.apply([&mut self.panels]), + BG.apply([&mut self.background]), + MOTION.apply([&mut self.motion]) ).await; self.background.set_shader(Background::default()); }, Scene::Idle => { self.background.set_shader(Thinking::default()); - let fg_fade = Animation::default().duration(Duration::from_millis(300)).to(Fract8::MIN); - let bg_fade = Animation::default().duration(Duration::from_millis(300)).to(Fract8::from_raw(128)); - + embassy_futures::join::join( - fg_fade.apply([&mut self.tail, &mut self.panels, &mut self.motion]), - bg_fade.apply([&mut self.background]) + FG_FADE_OUT.apply([&mut self.tail, &mut self.panels, &mut self.motion]), + BG_FADE_IN.apply([&mut self.background]) ).await; }, Scene::Accelerating => {