use ratatui::{
Frame,
layout::Rect,
style::{Color, Style},
widgets::Paragraph,
};
use crate::core::model::component_context::ComponentContext;
use crate::tui::component_impl::TuiComponent;
pub struct DividerComponent;
impl TuiComponent for DividerComponent {
fn name(&self) -> &'static str {
"Divider"
}
fn render(
&self,
ctx: &ComponentContext,
area: Rect,
frame: &mut Frame,
_render_child: &mut dyn FnMut(&str, Rect, &mut Frame),
) {
let comp_model = match ctx.components.get(&ctx.component_id) {
Some(m) => m,
None => return,
};
let inner = Rect {
x: area.x + 1,
y: area.y + 1,
width: area.width.saturating_sub(2),
height: area.height.saturating_sub(2),
};
if inner.width == 0 || inner.height == 0 {
return;
}
let axis: Option<String> = comp_model.get_property("axis");
let dim_style = Style::default().fg(Color::DarkGray);
match axis.as_deref() {
Some("vertical") => {
let line: String = "│".repeat(inner.height as usize);
let paragraph = Paragraph::new(line).style(dim_style);
frame.render_widget(paragraph, inner);
}
_ => {
let line: String = "─".repeat(inner.width as usize);
let paragraph = Paragraph::new(line).style(dim_style);
frame.render_widget(paragraph, inner);
}
}
}
}