fp_tui 0.2.2

A very basic tui library
Documentation
use crate::PositioningAlgorithm;
use crate::common::Position;

/// #### Description
/// Positions the child relative to the position of the parent
///
pub struct RelativePositioning {
    /// #### Description
    /// The position of the parent relative to the viewport
    parent_position: Position
}

impl RelativePositioning {
    /// #### Description
    /// Creates a positioning algorithm that positions a child relative to its
    /// parent
    ///
    /// #### Returns
    /// [Box]<[RelativePositioning]> - A positioning algorithm that positions a child
    /// widget relative to its parent
    ///
    pub fn new() -> Box<Self> {
        return Box::new(Self {parent_position: Position::new(0, 0)});
    }
}

impl PositioningAlgorithm for RelativePositioning {
    fn calculate_position(&self, child_position: Position) -> Position {
        let x = self.parent_position.get_x() + child_position.get_x();
        let y = self.parent_position.get_y() + child_position.get_y();

        return Position::new(x, y);
    }

    fn set_parent_position(&mut self, position: Position) {
        self.parent_position = position
    }
}