rlvgl_core/plugins/
lottie.rs1use crate::widget::Color;
7use rlottie::{Animation, Size, Surface};
8
9#[derive(Debug, Clone)]
11pub enum Error {
12 InvalidJson,
14}
15
16pub fn render_lottie_frame(
24 json: &str,
25 frame: usize,
26 width: usize,
27 height: usize,
28) -> Option<alloc::vec::Vec<Color>> {
29 let mut anim = Animation::from_data(json, "mem", ".")?;
30 let mut surface = Surface::new(Size::new(width, height));
31 anim.render(frame, &mut surface);
32 Some(
33 surface
34 .data()
35 .iter()
36 .map(|px| Color(px.r, px.g, px.b, 255))
37 .collect(),
38 )
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 const SIMPLE_JSON: &str =
46 "{\"v\":\"5.7\",\"fr\":30,\"ip\":0,\"op\":0,\"w\":1,\"h\":1,\"layers\":[]}";
47
48 #[test]
49 fn render_minimal() {
50 let frame = render_lottie_frame(SIMPLE_JSON, 0, 1, 1).unwrap();
51 assert_eq!(frame.len(), 1);
52 }
53}