use ratatui::{
Frame,
layout::Rect,
style::{Color, Style},
widgets::Paragraph,
};
use a2ui_base::model::component_context::ComponentContext;
use crate::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, &str),
_measure_child: &mut dyn FnMut(&str, &str, u16) -> Option<u16>,
) {
let comp_model = match ctx.components.get(&ctx.component_id) {
Some(m) => m,
None => return,
};
let inner = crate::layout_engine::padded_content(area);
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);
}
}
}
fn natural_height(
&self,
ctx: &ComponentContext,
_available_width: u16,
_measure_child: &mut dyn FnMut(&str, &str, u16) -> Option<u16>,
) -> Option<u16> {
let comp_model = ctx.components.get(&ctx.component_id)?;
let axis: Option<String> = comp_model.get_property("axis");
match axis.as_deref() {
Some("vertical") => None,
_ => Some(3),
}
}
}