boxy_cli/
constructs.rs

1use std::fmt::Display;
2
3/// Type of border for the TextBox
4///
5/// Total of 8 types: Classic, Single, DoubleHorizontal, DoubleVertical, Double, Bold, Rounded and BoldCorners
6// TextBox Type Enums
7#[derive(Debug)]
8pub enum BoxType{
9    Classic,
10    Single,
11    DoubleHorizontal,
12    DoubleVertical,
13    Double,
14    Bold,
15    Rounded,
16    BoldCorners
17}
18
19// Added Display Fucntion to resolve type errors in the macro
20impl Display for BoxType{
21    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22        let str = match &self {
23            BoxType::Classic => "classic".to_string(),
24            BoxType::Single => "single".to_string(),
25            BoxType::DoubleHorizontal => "double_horizontal".to_string(),
26            BoxType::DoubleVertical => "double_vertical".to_string(),
27            BoxType::Double => "double".to_string(),
28            BoxType::Bold => "bold".to_string(),
29            BoxType::Rounded => "rounded".to_string(),
30            BoxType::BoldCorners => "bold_corners".to_string(),
31        };
32        write!(f, "{}", str)
33    }
34}
35
36// Alignment Enums
37/// Type of alignment for the text inside the TextBox
38///
39/// Total of 3 types: Left, Center and Right
40#[derive(Debug)]
41pub enum BoxAlign {
42    Left,
43    Center,
44    Right,
45}
46
47// Added Display Fucntion to resolve type errors in the macro
48impl Display for BoxAlign {
49    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
50        let str = match self {
51            BoxAlign::Left => "left".to_string(),
52            BoxAlign::Center => "center".to_string(),
53            BoxAlign::Right => "right".to_string(),
54        };
55        write!(f, "{}", str)
56    }
57}
58
59
60/// Padding Struct for the TextBox
61#[derive(Debug)]
62pub struct BoxPad {
63    pub top: usize,
64    pub down: usize,
65    pub left: usize,
66    pub right: usize,
67}
68
69impl Default for BoxPad {
70    fn default() -> Self {
71        Self::new()
72    }
73}
74
75impl BoxPad {
76    pub fn new() -> Self {
77        BoxPad{
78            top: 0,
79            down: 0,
80            left: 0,
81            right: 0
82        }
83    }
84    /// Creates a new BoxPad Struct with the given padding values in order: top, left, down, right (tldr)
85    pub fn from_tldr(top: usize, left: usize, down: usize, right: usize) -> Self {
86        BoxPad{
87            top,
88            down,
89            left,
90            right
91        }
92    }
93
94    /// Creates a new BoxPad Struct with uniform padding values on all sides
95    pub fn uniform(pad: usize) -> Self{
96        BoxPad{
97            top: pad,
98            down: pad,
99            left: pad,
100            right: pad
101        }
102    }
103    /// Creates a new BoxPad Struct with the given padding values in order: vertical, horizontal
104    pub fn vh(vertical: usize, horizontal: usize) -> Self{
105        BoxPad{
106            top: vertical,
107            down: vertical,
108            left: horizontal,
109            right: horizontal
110        }
111    }
112    /// returns the total padidng on either side. used for text wrapping and display time calculations
113    pub fn lr(&self) -> usize{
114        self.right + self.left
115    }
116}