Skip to main content

rustmotion_components/
container.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use skia_safe::Canvas;
4
5use rustmotion_core::css::CssStyle;
6use rustmotion_core::engine::layout_pass::BoxLayout;
7use rustmotion_core::schema::TimelineStep;
8use rustmotion_core::traits::{PaintCtx, Painter, TimingConfig};
9
10use crate::ChildComponent;
11
12/// The single layout container — the HTML `<div>` equivalent. Lays out
13/// `children` via flex (default) or grid, decorated purely by `style`
14/// (`background`, `border-radius`, `box-shadow`, ... — all opt-in, none
15/// applied by default) and gets `display: flex` automatically when `style`
16/// doesn't set one, like every other layout container.
17///
18/// Six spellings of `"type"` all deserialize into this same struct and
19/// render identically: `"div"` (canonical), plus `"container"`, `"card"`,
20/// `"flex"`, `"grid"`, and `"positioned"` kept as aliases for backward
21/// compatibility. None of them carries different behavior — a `"card"`
22/// with no `background` set is exactly as undecorated as a `"div"`, and a
23/// `"positioned"` is exactly as capable of flex/grid flow as any other
24/// spelling; `position: {x, y}` on a child works the same way inside all
25/// six, since it's a property of the child, not of the container.
26#[derive(Debug, Serialize, Deserialize, JsonSchema)]
27pub struct ContainerComponent {
28    #[serde(default)]
29    pub children: Vec<ChildComponent>,
30    #[serde(flatten)]
31    pub timing: TimingConfig,
32    #[serde(default)]
33    pub style: CssStyle,
34    #[serde(default)]
35    pub timeline: Vec<TimelineStep>,
36    #[serde(default)]
37    pub stagger: Option<f32>,
38    #[serde(default)]
39    pub time_scale: Option<f64>,
40    #[serde(default)]
41    pub time_offset: Option<f64>,
42}
43
44rustmotion_core::impl_traits!(ContainerComponent {
45    Animatable => animation,
46    Timed => timing,
47    Styled => style,
48});
49
50impl Painter for ContainerComponent {
51    fn paint_content(
52        &self,
53        _canvas: &Canvas,
54        _layout: &BoxLayout,
55        _props: &rustmotion_core::engine::animator::AnimatedProperties,
56        _ctx: &PaintCtx,
57    ) {
58    }
59}