use crate::parser::css::CssRule;
use crate::parser::ttf::TtfFont;
use std::collections::HashMap;
use super::engine::CounterState;
pub(crate) struct LayoutEnv<'a> {
pub rules: &'a [CssRule],
pub fonts: &'a HashMap<String, TtfFont>,
pub counter_state: &'a mut CounterState,
}
#[derive(Debug, Clone, Copy)]
pub struct ContainingBlock {
pub x: f32,
pub width: f32,
pub height: f32,
pub depth: usize,
}
#[derive(Debug, Clone, Copy)]
#[allow(dead_code)]
pub struct Viewport {
pub width: f32,
pub height: f32,
}
#[derive(Debug, Clone, Copy)]
#[allow(dead_code)]
pub struct ParentBox {
pub content_width: f32,
pub content_height: Option<f32>,
pub font_size: f32,
}
#[derive(Debug, Clone, Copy)]
#[allow(dead_code)]
pub struct LayoutContext {
pub viewport: Viewport,
pub parent: ParentBox,
pub containing_block: Option<ContainingBlock>,
pub root_font_size: f32,
}
#[allow(dead_code)]
impl LayoutContext {
pub fn available_width(&self) -> f32 {
self.parent.content_width
}
pub fn available_height(&self) -> f32 {
self.parent.content_height.unwrap_or(self.viewport.height)
}
pub fn with_parent(
&self,
content_width: f32,
content_height: Option<f32>,
font_size: f32,
) -> Self {
LayoutContext {
parent: ParentBox {
content_width,
content_height,
font_size,
},
..*self
}
}
pub fn with_containing_block(&self, cb: Option<ContainingBlock>) -> Self {
LayoutContext {
containing_block: cb,
..*self
}
}
}