use crate::{
graphics::block_style,
layout::{
BoxConstraint, Cursor, InlineRun, LayoutBox, LayoutContext,
inner_formatting_context::flow::{LayoutBlockOptions, layout_block},
},
tdom::node::{NodeArena, NodeId, NodeType},
};
fn heading_prefix(node_type: &NodeType) -> Option<&'static str> {
match node_type {
NodeType::H1 => Some("# "),
NodeType::H2 => Some("## "),
NodeType::H3 => Some("### "),
NodeType::H4 => Some("#### "),
NodeType::H5 => Some("##### "),
NodeType::H6 => Some("###### "),
_ => None,
}
}
pub fn layout_hn(
arena: &NodeArena,
node_id: NodeId,
containing: BoxConstraint,
cursor: &mut Cursor,
context: LayoutContext,
pre_allocated_rect: Option<crate::layout::Rect>,
) -> Option<LayoutBox> {
let node = &arena[node_id];
let prefix_text = heading_prefix(&node.node_type)?;
let block_fg = node.css_attr.get_color();
let block_bg = node.css_attr.get_bg_color();
let block_font_style = block_style(&node.css_attr);
let prefix_run =
InlineRun::synthesized_marker(prefix_text, block_font_style, block_fg, block_bg);
Some(layout_block(
arena,
node,
node_id,
containing,
cursor,
LayoutBlockOptions {
prefix: Some(prefix_run),
..Default::default()
},
context,
pre_allocated_rect,
))
}
pub fn layout_title(
arena: &NodeArena,
node_id: NodeId,
_containing: BoxConstraint,
_cursor: &mut Cursor,
_context: LayoutContext,
_pre_allocated_rect: Option<crate::layout::Rect>,
) -> Option<LayoutBox> {
let node = &arena[node_id];
if node.node_type != NodeType::Title {
return None;
}
None
}
pub fn layout_meta(
arena: &NodeArena,
node_id: NodeId,
_containing: BoxConstraint,
_cursor: &mut Cursor,
_context: LayoutContext,
_pre_allocated_rect: Option<crate::layout::Rect>,
) -> Option<LayoutBox> {
let node = &arena[node_id];
if node.node_type != NodeType::Meta {
return None;
}
None
}