use core::time::Duration;
use crate::{
environment::LayoutEnvironment,
layout::{Layout, ResolvedLayout},
primitives::Point,
render_target::RenderTarget,
};
mod animate;
mod capsule;
mod circle;
pub mod collections;
mod empty;
#[cfg(feature = "embedded-graphics")]
mod image;
mod offset;
mod one_of;
mod rect;
mod rounded_rect;
mod shade_subtree;
mod text;
pub use animate::Animate;
pub use capsule::Capsule;
pub use circle::Circle;
#[cfg(feature = "embedded-graphics")]
pub use image::Image;
pub use offset::Offset;
pub use one_of::{OneOf2, OneOf3, OneOf4};
pub use rect::Rect;
pub use rounded_rect::RoundedRect;
pub use shade_subtree::ShadeSubtree;
pub use text::Text;
pub trait Renderable: Layout {
type Renderables;
fn render_tree(
&self,
layout: &ResolvedLayout<Self::Sublayout>,
origin: Point,
env: &impl LayoutEnvironment,
) -> Self::Renderables;
}
pub trait AnimatedJoin {
fn join(source: Self, target: Self, domain: &AnimationDomain) -> Self;
}
pub trait Render<Color>: AnimatedJoin + Sized {
fn render(
&self,
render_target: &mut impl RenderTarget<ColorFormat = Color>,
style: &Color,
offset: Point,
);
fn render_animated(
render_target: &mut impl RenderTarget<ColorFormat = Color>,
source: &Self,
target: &Self,
style: &Color,
offset: Point,
domain: &AnimationDomain,
);
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AnimationDomain {
pub factor: u8,
pub app_time: Duration,
}
impl AnimationDomain {
#[must_use]
pub const fn new(factor: u8, app_time: Duration) -> Self {
Self { factor, app_time }
}
#[must_use]
pub const fn top_level(app_time: Duration) -> Self {
Self {
factor: 255,
app_time,
}
}
#[must_use]
pub const fn is_complete(&self) -> bool {
self.factor == 255
}
}