use std::fmt::Debug;
use serde::Deserialize;
use crate::layout::{
Viewport,
node::Node,
style::{InheritedStyle, Style, tw::TailwindValues},
};
#[derive(Debug, Deserialize, Clone)]
pub struct ContainerNode<Nodes: Node<Nodes>> {
pub preset: Option<Style>,
pub style: Option<Style>,
pub children: Option<Box<[Nodes]>>,
pub tw: Option<TailwindValues>,
}
impl<Nodes: Node<Nodes>> Node<Nodes> for ContainerNode<Nodes> {
fn children_ref(&self) -> Option<&[Nodes]> {
self.children.as_deref()
}
fn create_inherited_style(
&mut self,
parent_style: &InheritedStyle,
viewport: Viewport,
) -> InheritedStyle {
let mut style = Style::default();
if let Some(preset) = self.preset.take() {
style.merge_from(preset);
}
if let Some(tw) = self.tw.as_ref() {
tw.apply(&mut style, viewport);
}
if let Some(inline_style) = self.style.take() {
style.merge_from(inline_style);
}
style.inherit(parent_style)
}
fn take_children(&mut self) -> Option<Box<[Nodes]>> {
self.children.take()
}
fn get_style(&self) -> Option<&Style> {
self.style.as_ref()
}
}