Rusty-tui 0.1.0

A simple TUI library for making CLI applications with ease.
Documentation
/// A structure representing a border with specific dimensions and position.
pub struct Border {
    /// The character or string used for the border.
    pub border: String,
    /// The height of the area defined by the border.
    pub h: u16,
    /// The width of the area defined by the border.
    pub w: u16,
    /// The x-coordinate position of the border's top-left corner.
    pub x: u16,
    /// The y-coordinate position of the border's top-left corner.
    pub y: u16,
}

impl Border {
    /// Creates a new instance of `Border`.
    ///
    /// # Parameters
    ///
    /// - `h`: The height of the border area.
    /// - `w`: The width of the border area.
    /// - `x`: The x-coordinate of the border's position.
    /// - `y`: The y-coordinate of the border's position.
    /// - `border`: A string representing the border character(s).
    ///
    /// # Returns
    ///
    /// Returns a new `Border` instance.
    pub fn new(h: u16, w: u16, x: u16, y: u16, border: String) -> Border {
        Border {
            border, // Using shorthand syntax for field initialization
            h,
            w,
            x,
            y,
        }
    }

    /// Draws the border on the console.
    ///
    /// This method will print the border to the console starting at the specified
    /// (x, y) position. The border consists of repeated characters specified
    /// in the `border` field, and it is drawn for the height and width defined
    /// in the struct.
    ///
    /// # Example
    ///
    /// ```
    /// let border = Border::new(5, 10, 2, 1, "*".to_string());
    /// border.draw();
    /// ```
    ///
    /// This will create a border 10 characters wide and 5 characters high, starting
    /// from the x-coordinate 2 and y-coordinate 1.
    pub fn draw(&self) {
        // Calculate the top-left corner based on the position
        for row in 0..self.h {
            // Move cursor to (self.x, self.y + row)
            println!("{:width$}", "", width = self.x as usize);
            
            // Draw the border line
            let border_line = self.border.repeat(self.w as usize);
            println!("{}", border_line);
        }
    }
}