use std::time::Duration;
use super::PaintCx;
use super::paint::ANIMATION_FRAME;
use crate::animation::AnimatedCell;
use crate::style::CellStyle;
impl PaintCx<'_> {
pub fn animation(&mut self, name: &str, style: CellStyle, since: Option<Duration>) -> AnimatedCell {
let env = self.env;
let Some(animation) = env.icons().animation(name) else {
return AnimatedCell { glyph: format!("⟦{name}⟧"), style, finished: true };
};
let since = since.filter(|_| !env.reduced_motion());
let frame = animation.sample(env.theme(), style.fg, self.now, since);
if since.is_some() {
if frame.smooth {
self.request_frame_in(ANIMATION_FRAME);
} else if let Some(next) = frame.next {
self.request_frame_in(next);
}
}
let glyph = animation.glyph(frame.index, env.icons().mode()).to_owned();
AnimatedCell { glyph, style: CellStyle { fg: frame.color.or(style.fg), ..style }, finished: frame.finished }
}
}