use dom_cat::NodeId;
use crate::length::{Edges, Rect};
use crate::style::ComputedStyle;
#[derive(Debug, Clone, PartialEq)]
pub struct LayoutBox {
dom_node: NodeId,
style: ComputedStyle,
rect: Rect,
margin: Edges,
border: Edges,
padding: Edges,
children: Vec<LayoutBox>,
}
impl Eq for LayoutBox {}
impl LayoutBox {
#[must_use]
pub fn new(
dom_node: NodeId,
style: ComputedStyle,
rect: Rect,
margin: Edges,
border: Edges,
padding: Edges,
children: Vec<LayoutBox>,
) -> Self {
Self {
dom_node,
style,
rect,
margin,
border,
padding,
children,
}
}
#[must_use]
pub fn dom_node(&self) -> NodeId {
self.dom_node
}
#[must_use]
pub fn style(&self) -> &ComputedStyle {
&self.style
}
#[must_use]
pub fn rect(&self) -> Rect {
self.rect
}
#[must_use]
pub fn margin(&self) -> Edges {
self.margin
}
#[must_use]
pub fn border(&self) -> Edges {
self.border
}
#[must_use]
pub fn padding(&self) -> Edges {
self.padding
}
#[must_use]
pub fn children(&self) -> &[LayoutBox] {
&self.children
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Viewport {
width: u32,
height: u32,
}
impl Viewport {
#[must_use]
pub fn new(width: u32, height: u32) -> Self {
Self { width, height }
}
#[must_use]
pub fn width(&self) -> u32 {
self.width
}
#[must_use]
pub fn height(&self) -> u32 {
self.height
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct LayoutTree {
root: Option<LayoutBox>,
viewport: Viewport,
}
impl Eq for LayoutTree {}
impl LayoutTree {
#[must_use]
pub fn new(root: Option<LayoutBox>, viewport: Viewport) -> Self {
Self { root, viewport }
}
#[must_use]
pub fn root_box(&self) -> Option<&LayoutBox> {
self.root.as_ref()
}
#[must_use]
pub fn viewport(&self) -> Viewport {
self.viewport
}
}