use crate::timeline::context::{TimelineContext, VideoConfigContext};
use crate::types::VideoConfig;
use dioxus::prelude::*;
#[derive(Props, Clone, PartialEq)]
pub struct CompositionProps {
pub id: String,
pub width: u32,
pub height: u32,
pub fps: f64,
pub duration_in_frames: u32,
#[props(default = 0)]
pub frame: u32,
pub children: Element,
}
#[component]
pub fn Composition(props: CompositionProps) -> Element {
let config = VideoConfig {
id: props.id.clone(),
width: props.width,
height: props.height,
fps: props.fps,
duration_in_frames: props.duration_in_frames,
default_codec: None,
default_pixel_format: None,
};
let frame = props.frame.min(props.duration_in_frames.saturating_sub(1));
let mut timeline = use_context_provider(|| Signal::new(TimelineContext::new(frame)));
if timeline.peek().frame != frame {
timeline.set(TimelineContext::new(frame));
}
let mut video_config = use_context_provider(|| Signal::new(VideoConfigContext(config.clone())));
if video_config.peek().0 != config {
video_config.set(VideoConfigContext(config));
}
rsx! {
div {
style: "position: relative; width: {props.width}px; height: {props.height}px; overflow: hidden;",
{props.children}
}
}
}