tuigui 0.23.0

An easy-to-use, highly extensible, and speedy TUI library.
Documentation
use crate::preludes::widget_creation::*;

#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
/// Create layers of widgets so widgets can overlay each other
/// the last item in the vector will be the front-most item
pub struct Layers<W: Widget> {
    pub roots: Vec<W>,
    widget_data: WidgetData,
}

impl<W: Widget> Layers<W> {
    pub fn new(roots: Vec<W>) -> Self {
        Self {
            roots,
            widget_data: WidgetData::new(),
        }
    }
}

impl<W: Widget> Widget for Layers<W> {
    fn draw(&mut self, canvas: &mut Canvas, state_frame: Option<&EventStateFrame>) {
        if canvas.is_visible() == false {
            return;
        }

        let mut inners: Vec<Canvas> = self.roots.iter().map(|x| {
            let mut inner = canvas.new_copy_child();

            inner.transform.size = x.widget_info().size_info.correct_size(inner.transform.size);

            inner
        }).collect();

        for (i, widget) in self.roots.iter_mut().enumerate() {
            widget.draw(&mut inners[i], state_frame);
        }
    }

    fn widget_info(&self) -> WidgetInfo {
        WidgetInfo {
            size_info: WidgetSizeInfo::Dynamic {
                min: None,
                max: None,
            },
        }
    }

    fn widget_data(&mut self) -> &mut WidgetData {
        return &mut self.widget_data;
    }
}