use std::fmt::Debug;
pub use alignment::Aligned;
pub use blank::Blank;
pub use bordering::Bordered;
pub use bounding::Bounded;
pub(crate) use canvas::Canvas;
pub use padding::Padded;
pub use splitting::Split;
pub use crate::components::draw_horizontal::DrawHorizontal;
pub use crate::components::draw_vertical::DrawVertical;
use crate::Dimensions;
use crate::Lines;
pub mod alignment;
mod blank;
pub mod bordering;
mod bounding;
mod canvas;
mod draw_horizontal;
mod draw_vertical;
pub(crate) mod echo;
pub mod padding;
pub mod splitting;
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum DrawMode {
Normal,
Final,
}
pub trait Component {
fn draw_unchecked(&self, dimensions: Dimensions, mode: DrawMode) -> anyhow::Result<Lines>;
fn draw(&self, dimensions: Dimensions, mode: DrawMode) -> anyhow::Result<Lines> {
let mut res = self.draw_unchecked(dimensions, mode)?;
res.shrink_lines_to_dimensions(dimensions);
Ok(res)
}
}
impl Component for Box<dyn Component> {
fn draw_unchecked(&self, dimensions: Dimensions, mode: DrawMode) -> anyhow::Result<Lines> {
(**self).draw_unchecked(dimensions, mode)
}
}
impl Component for Box<dyn Component + Send> {
fn draw_unchecked(&self, dimensions: Dimensions, mode: DrawMode) -> anyhow::Result<Lines> {
(**self).draw_unchecked(dimensions, mode)
}
}
impl<C: Component> Component for Box<C> {
fn draw_unchecked(&self, dimensions: Dimensions, mode: DrawMode) -> anyhow::Result<Lines> {
(**self).draw_unchecked(dimensions, mode)
}
}
impl<'a> Component for &'a dyn Component {
fn draw_unchecked(&self, dimensions: Dimensions, mode: DrawMode) -> anyhow::Result<Lines> {
(**self).draw_unchecked(dimensions, mode)
}
}
impl<'a> Component for &'a (dyn Component + Send) {
fn draw_unchecked(&self, dimensions: Dimensions, mode: DrawMode) -> anyhow::Result<Lines> {
(**self).draw_unchecked(dimensions, mode)
}
}
impl<'a, C: Component> Component for &'a C {
fn draw_unchecked(&self, dimensions: Dimensions, mode: DrawMode) -> anyhow::Result<Lines> {
(**self).draw_unchecked(dimensions, mode)
}
}