glyph_ui 0.1.0

TUI library utilizing the Elm architecture
Documentation
//! An empty view with size `(1, 1)`

use euclid::Size2D;

use crate::{event::Event, unit::Cell, Printer, View as ViewTrait};

/// The view itself
pub struct View;

/// Instantiates this [`View`]
///
/// Just writing `empty::View` also works, but this is nice for consistency.
///
/// [`View`]: View
pub fn new() -> View {
    View
}

impl<T, M> ViewTrait<T, M> for View
where
    M: 'static,
{
    fn draw(&self, _printer: &Printer, _focused: bool) {
        // Do nothing
    }

    fn width(&self) -> Size2D<u16, Cell> {
        (1, 1).into()
    }

    fn height(&self) -> Size2D<u16, Cell> {
        (1, 1).into()
    }

    fn layout(&self, _constraint: Size2D<u16, Cell>) -> Size2D<u16, Cell> {
        // One cell
        (1, 1).into()
    }

    fn event(
        &mut self,
        _event: &Event<T>,
        _focused: bool,
    ) -> Box<dyn Iterator<Item = M>> {
        Box::new(std::iter::empty())
    }

    fn interactive(&self) -> bool {
        false
    }
}