tawasuyu/llimphi
Sovereign retained-mode GPU UI framework in Rust (wgpu+vello+taffy+parley), Elm loop, 40+ widgets.
1// Copyright 2024 the Velato Authors
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4mod render;
5
6use crate::Error;
7use crate::import;
8use crate::schema::Animation;
9use std::collections::HashMap;
10use std::ops::Range;
11
12#[cfg(feature = "vello")]
13mod vello;
14
15pub mod model;
16
17pub use render::{RenderSink, Renderer};
18
19/// Model of a Lottie file.
20#[derive(Clone, Default, Debug)]
21pub struct Composition {
22 /// Frames in which the animation is active.
23 pub frames: Range<f64>,
24 /// Frames per second.
25 pub frame_rate: f64,
26 /// Width of the animation.
27 pub width: usize,
28 /// Height of the animation.
29 pub height: usize,
30 /// Precomposed layers that may be instanced.
31 pub assets: HashMap<String, Vec<model::Layer>>,
32 /// Collection of layers.
33 pub layers: Vec<model::Layer>,
34}
35
36impl Composition {
37 /// Creates a new runtime composition from a buffer of Lottie file contents.
38 pub fn from_slice(source: impl AsRef<[u8]>) -> Result<Composition, Error> {
39 let source = Animation::from_slice(source.as_ref())?;
40 let composition = import::conv_animation(source);
41 Ok(composition)
42 }
43
44 /// Creates a new runtime composition from a json object of Lottie file contents.
45 pub fn from_json(v: serde_json::Value) -> Result<Composition, Error> {
46 let source = Animation::from_json(v)?;
47 let composition = import::conv_animation(source);
48 Ok(composition)
49 }
50}
51
52impl std::str::FromStr for Composition {
53 type Err = Error;
54
55 fn from_str(s: &str) -> Result<Self, Self::Err> {
56 let source = Animation::from_str(s)?;
57 let composition = import::conv_animation(source);
58 Ok(composition)
59 }
60}