console_engine/
rect_style.rs

1use crossterm::style::Color;
2
3use crate::pixel::{self, Pixel};
4
5/// Borders for styled-border rectangle
6#[derive(Copy, Clone)]
7pub struct BorderStyle {
8    pub corner_top_left: Pixel,
9    pub corner_top_right: Pixel,
10    pub corner_bottom_left: Pixel,
11    pub corner_bottom_right: Pixel,
12    pub top_bottom: Pixel,
13    pub left_right: Pixel,
14}
15
16impl BorderStyle {
17    /// Simple border (uses only ascii characters +, -, |)
18    pub fn new_simple() -> Self {
19        Self {
20            corner_top_right: pixel::pxl('+'),
21            corner_top_left: pixel::pxl('+'),
22            corner_bottom_left: pixel::pxl('+'),
23            corner_bottom_right: pixel::pxl('+'),
24            top_bottom: pixel::pxl('-'),
25            left_right: pixel::pxl('|'),
26        }
27    }
28
29    /// Solid (Uses only the block character from ascii)
30    pub fn new_solid() -> Self {
31        Self {
32            corner_top_right: pixel::pxl('█'),
33            corner_top_left: pixel::pxl('█'),
34            corner_bottom_left: pixel::pxl('█'),
35            corner_bottom_right: pixel::pxl('█'),
36            top_bottom: pixel::pxl('█'),
37            left_right: pixel::pxl('█'),
38        }
39    }
40
41    /// Light border (uses Box Drawings Light set from unicode)
42    pub fn new_light() -> Self {
43        Self {
44            corner_top_right: pixel::pxl('┐'),
45            corner_top_left: pixel::pxl('┌'),
46            corner_bottom_left: pixel::pxl('└'),
47            corner_bottom_right: pixel::pxl('┘'),
48            top_bottom: pixel::pxl('─'),
49            left_right: pixel::pxl('│'),
50        }
51    }
52
53    /// Heavy border (uses Box Drawings Heavy set from unicode)
54    pub fn new_heavy() -> Self {
55        Self {
56            corner_top_right: pixel::pxl('┓'),
57            corner_top_left: pixel::pxl('┏'),
58            corner_bottom_left: pixel::pxl('┗'),
59            corner_bottom_right: pixel::pxl('┛'),
60            top_bottom: pixel::pxl('━'),
61            left_right: pixel::pxl('┃'),
62        }
63    }
64
65    /// Double border (uses Box Drawings Double set from unicode)
66    pub fn new_double() -> Self {
67        Self {
68            corner_top_right: pixel::pxl('╗'),
69            corner_top_left: pixel::pxl('╔'),
70            corner_bottom_left: pixel::pxl('╚'),
71            corner_bottom_right: pixel::pxl('╝'),
72            top_bottom: pixel::pxl('═'),
73            left_right: pixel::pxl('║'),
74        }
75    }
76
77    /// Creates user-defined border style with specified Pixel's structs
78    pub fn new(
79        corner_top_left: Pixel,
80        corner_top_right: Pixel,
81        corner_bottom_left: Pixel,
82        corner_bottom_right: Pixel,
83        top_bottom: Pixel,
84        left_right: Pixel,
85    ) -> Self {
86        Self {
87            corner_top_right,
88            corner_top_left,
89            corner_bottom_left,
90            corner_bottom_right,
91            top_bottom,
92            left_right,
93        }
94    }
95
96    /// Changes the border's colors
97    pub fn with_colors(mut self, fg: Color, bg: Color) -> Self {
98        self.corner_top_right.fg = fg;
99        self.corner_top_right.bg = bg;
100        self.corner_top_left.fg = fg;
101        self.corner_top_left.bg = bg;
102        self.corner_bottom_left.fg = fg;
103        self.corner_bottom_left.bg = bg;
104        self.corner_bottom_right.fg = fg;
105        self.corner_bottom_right.bg = bg;
106        self.top_bottom.fg = fg;
107        self.top_bottom.bg = bg;
108        self.left_right.fg = fg;
109        self.left_right.bg = bg;
110        self
111    }
112}