fp_tui 0.2.2

A very basic tui library
Documentation
use crate::{common::Dimensions, AbsolutePositioning, PositioningAlgorithm};
use super::{Widget, DisplayBuffer};

use std::rc::Rc;
use std::cell::RefCell;

/// #### Description
/// The root of the interface
///
pub struct Tui {
    /// #### Description
    /// The buffer that holds the characters to be drawn to the screen
    ///
    display_buffer: DisplayBuffer,

    /// #### Description
    /// The child widgets
    /// 
    children: Vec<Rc<RefCell<dyn Widget>>>
}

impl Tui {
    /// #### Description
    /// Creates a new tui with the specified dimensions
    /// 
    /// #### Arguments
    /// * `width`: [u32] - The width of the display
    /// * `height`: [u32] - The height of the display
    /// 
    /// #### Returns
    /// [Tui] - A tui object
    /// 
    pub fn new(width: u32, height: u32) -> Self {
        return Self {
            display_buffer: DisplayBuffer::new(Dimensions::new(width, height)),
            children: vec![]
        };
    }

    /// #### Description
    /// Draws the tui to the terminal
    /// 
    pub fn draw(&mut self) {
        let root_positioning_algorithm: Box<dyn PositioningAlgorithm> = 
            AbsolutePositioning::new();

        for widget in &mut self.children {
            widget.borrow_mut()
                .draw(&root_positioning_algorithm, &mut self.display_buffer);
        }
        self.display_buffer.draw();
        self.display_buffer.clear(' ');
    }

    /// #### Description
    /// Adds a widget to the tui
    /// 
    /// #### Arguments
    /// `widget`: [Rc]<[RefCell]<dyn [Widget]>> - The widget to be added
    /// 
    pub fn add_child(&mut self, widget: Rc<RefCell<dyn crate::Widget>>) {
        self.children.push(widget);
    }
}