use super::*;
use ratatui::widgets::{BorderType, Borders};
fn divider_touches(rect: Rect, d: &crate::layout::Divider) -> bool {
use crate::layout::Axis;
let right = rect.x + rect.width.saturating_sub(1);
let bottom = rect.y + rect.height.saturating_sub(1);
let near = |line: u16, a: u16, b: u16| {
(line as i32 - a as i32).abs() <= 1 || (line as i32 - b as i32).abs() <= 1
};
match d.axis {
Axis::Col => near(d.line, rect.x, right) && d.span.0 < bottom && d.span.1 > rect.y,
Axis::Row => near(d.line, rect.y, bottom) && d.span.0 < right && d.span.1 > rect.x,
}
}
pub(super) fn render_pane_borders(
f: &mut RenderTarget,
rects: &[(PaneId, Rect)],
focus: PaneId,
hover: Option<&crate::layout::Divider>,
t: &Theme,
) {
if rects.len() < 2 {
return;
}
for (id, rect) in rects {
if rect.width < 2 || rect.height < 2 {
continue;
}
let focused = *id == focus || hover.is_some_and(|d| divider_touches(*rect, d));
let color = if focused { t.border_focus } else { t.border };
let block = Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Plain)
.border_style(Style::new().fg(color));
f.render_widget(block, *rect);
}
}