use super::super::render_tree::{RenderNode, RenderNodeType};
use super::super::style_resolver::ResolvedParaStyle;
use super::LayoutRect;
pub(super) fn rendered_table_right_edge(
column: &RenderNode,
section_index: usize,
para_index: usize,
control_index: usize,
) -> Option<f64> {
column.children.iter().rev().find_map(|node| {
let RenderNodeType::Table(table) = &node.node_type else {
return None;
};
(table.section_index == Some(section_index)
&& table.para_index == Some(para_index)
&& table.control_index == Some(control_index))
.then_some(node.bbox.x + node.bbox.width)
})
}
pub(super) fn paragraph_border_box(
style: Option<&ResolvedParaStyle>,
column: &LayoutRect,
allocation_top: f64,
line_top: f64,
line_bottom: f64,
flow_bottom: f64,
wrap_box: Option<(f64, f64)>,
) -> LayoutRect {
let ignore_margin = style.is_some_and(|style| style.border_ignore_margin);
let (x, width) = if let Some(wrap_box) = wrap_box {
wrap_box
} else {
let left = style.map_or(0.0, |style| {
(if ignore_margin {
style.margin_left
} else {
0.0
}) - style.border_spacing[0]
});
let right = style.map_or(0.0, |style| {
(if ignore_margin {
style.margin_right
} else {
0.0
}) - style.border_spacing[1]
});
(column.x + left, column.width - left - right)
};
let top = if ignore_margin {
line_top
} else {
allocation_top
};
let bottom = if ignore_margin {
line_bottom
} else {
flow_bottom.max(line_bottom)
};
LayoutRect {
x,
y: top,
width,
height: bottom - top,
}
}