pub mod compositor;
pub mod flush;
pub mod geometry;
pub mod grid;
pub mod hit;
pub mod layout;
pub mod line;
pub mod snapshot;
pub mod surface;
pub use compositor::Compositor;
pub use flush::flush_diff;
pub use grid::{Cell, CellUpdate, Grid, GridSlice, Style};
pub use hit::HitRegistry;
pub use layout::{
Align, Border, Constraint, Corner, Gutters, LayoutTree, LeafSizer, Natural, NaturalRef,
NoopSizer, PaintId, Rect, StaticNatural,
};
pub use line::{Line, Span};
pub use smelt_style::style::Color;
pub use smelt_style::theme::Theme;
pub use snapshot::SnapshotFrame;
pub use surface::Surface;
pub type PaintDispatch<'a> =
dyn FnMut(PaintId, Rect, &mut Grid, &std::sync::Arc<Theme>, (u16, u16)) + 'a;
pub fn paint_layout_tree(
grid: &mut Grid,
theme: &std::sync::Arc<Theme>,
node: &LayoutTree,
area: Rect,
term_size: (u16, u16),
paint: &mut PaintDispatch,
) {
paint_layout_tree_with(
grid,
theme,
node,
area,
term_size,
&layout::NoopSizer,
paint,
);
}
pub fn paint_layout_tree_with(
grid: &mut Grid,
theme: &std::sync::Arc<Theme>,
node: &LayoutTree,
area: Rect,
term_size: (u16, u16),
sizer: &dyn layout::LeafSizer,
paint: &mut PaintDispatch,
) {
match node {
LayoutTree::Leaf { id, chrome, .. } => {
layout::paint_chrome(grid, area, chrome, theme);
let inner = layout::inset_for_chrome(area, chrome);
paint(*id, inner, grid, theme, term_size);
}
LayoutTree::Vbox { items, chrome } | LayoutTree::Hbox { items, chrome } => {
layout::paint_chrome(grid, area, chrome, theme);
let vertical = matches!(node, LayoutTree::Vbox { .. });
let (_, rects) = layout::layout_box_children(items, chrome, area, vertical, sizer);
for ((_, child), &rect) in items.iter().zip(rects.iter()) {
paint_layout_tree_with(grid, theme, child, rect, term_size, sizer, paint);
}
}
}
}