a2ui 0.1.1

A TUI component library built on top of ratatui
Documentation
//! Column component — vertical layout container.

use ratatui::{Frame, layout::{Direction, Rect}};

use crate::core::model::component_context::ComponentContext;
use crate::core::protocol::common_types::{Align, ChildList, Justify};
use crate::tui::component_impl::TuiComponent;
use crate::tui::components::row::{render_static_children, render_template_children};

/// Column component implementation.
///
/// Lays out children vertically using weighted splitting.
/// Invisible container — no margin or padding.
/// Default justify: Start, default align: Stretch.
pub struct ColumnComponent;

impl TuiComponent for ColumnComponent {
    fn name(&self) -> &'static str {
        "Column"
    }

    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 children = match comp_model.children() {
            Some(c) => c,
            None => return,
        };

        let justify = comp_model.get_property::<Justify>("justify").unwrap_or(Justify::Start);
        let align = comp_model.get_property::<Align>("align").unwrap_or(Align::Stretch);

        match children {
            ChildList::Static(ids) => {
                render_static_children(
                    ctx, area, frame, render_child,
                    &ids, justify, align, Direction::Vertical,
                );
            }
            ChildList::Template { component_id, path } => {
                render_template_children(
                    ctx, area, frame, render_child,
                    &component_id, &path, justify, align, Direction::Vertical,
                );
            }
        }
    }
}