use crate::{
primitives::{Interpolate, geometry::Rectangle},
render::{AnimatedJoin, ContentShape, IntrinsicShape, Render},
render_target::RenderTarget,
};
use super::AnimationDomain;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Container<T> {
pub frame: Rectangle,
pub child: T,
}
impl<T> Container<T> {
pub const fn new(frame: Rectangle, child: T) -> Self {
Self { frame, child }
}
}
impl<T: AnimatedJoin> AnimatedJoin for Container<T> {
fn join_from(&mut self, source: &Self, domain: &AnimationDomain) {
self.frame =
Rectangle::interpolate(source.frame.clone(), self.frame.clone(), domain.factor);
self.child.join_from(&source.child, domain);
}
}
impl<T: Render<Color>, Color> Render<Color> for Container<T> {
fn render(&self, render_target: &mut impl RenderTarget<ColorFormat = Color>, style: &Color) {
self.child.render(render_target, style);
}
fn render_animated(
render_target: &mut impl RenderTarget<ColorFormat = Color>,
source: &Self,
target: &Self,
style: &Color,
domain: &AnimationDomain,
) {
T::render_animated(render_target, &source.child, &target.child, style, domain);
}
}
impl<T: IntrinsicShape> IntrinsicShape for Container<T> {
fn content_shape(&self) -> ContentShape {
self.child.content_shape()
}
}