use crate::{
model::control::Control,
renderer::{
hwpunit_to_px,
render_tree::{RenderNode, RenderNodeType},
},
};
pub(super) fn close(
children: &[RenderNode],
current_end: f64,
trailing_spacing: f64,
controls: &[Control],
dpi: f64,
) -> f64 {
let occupied_end = children
.iter()
.filter(|node| {
matches!(
node.node_type,
RenderNodeType::TextLine(_) | RenderNodeType::Table(_)
)
})
.map(|node| {
let bottom_margin = match &node.node_type {
RenderNodeType::Table(table) => table
.control_index
.and_then(|index| controls.get(index))
.and_then(|control| match control {
Control::Table(source) if source.common.treat_as_char => {
Some(hwpunit_to_px(i32::from(source.outer_margin_bottom), dpi))
}
_ => None,
})
.unwrap_or(0.0),
_ => 0.0,
};
node.bbox.y + node.bbox.height + bottom_margin
})
.reduce(f64::max);
occupied_end.map_or(current_end + trailing_spacing, |end| {
current_end.max(end + trailing_spacing)
})
}