16static std::string simple_border_charset[6][6] = {
17 {
"┌",
"┐",
"└",
"┘",
"─",
"│"},
18 {
"┏",
"┓",
"┗",
"┛",
"━",
"┃"},
19 {
"╔",
"╗",
"╚",
"╝",
"═",
"║"},
20 {
"╭",
"╮",
"╰",
"╯",
"─",
"│"},
21 {
" ",
" ",
" ",
" ",
" ",
" "},
29class Border :
public Node {
32 :
Node(std::move(children)),
33 charset(std::begin(simple_border_charset[style]),
34 std::end(simple_border_charset[style])) {}
35 Border(
Elements children, Pixel pixel)
36 :
Node(std::move(children)), charset_pixel(10, pixel) {}
38 std::vector<Pixel> charset_pixel;
39 std::vector<std::string> charset;
41 void ComputeRequirement()
override {
56 void SetBox(Box box)
override {
60 title_box.x_min = box.x_min + 1;
61 title_box.x_max = box.x_max - 1;
62 title_box.y_min = box.y_min;
63 title_box.y_max = box.y_min;
73 void Render(Screen& screen)
override {
87 void RenderPixel(Screen& screen) {
94 Pixel& p1 = screen.PixelAt(x,
box_.
y_min);
95 Pixel& p2 = screen.PixelAt(x,
box_.
y_max);
96 p1.character = charset[4];
97 p2.character = charset[4];
102 Pixel& p3 = screen.PixelAt(
box_.
x_min, y);
103 Pixel& p4 = screen.PixelAt(
box_.
x_max, y);
104 p3.character = charset[5];
105 p4.character = charset[5];
115 void RenderChar(Screen& screen) {
121 Pixel& p1 = screen.PixelAt(x,
box_.
y_min);
122 Pixel& p2 = screen.PixelAt(x,
box_.
y_max);
123 p1 = charset_pixel[5];
124 p2 = charset_pixel[5];
129 Pixel& p3 = screen.PixelAt(
box_.
x_min, y);
130 Pixel& p4 = screen.PixelAt(
box_.
x_max, y);
131 p3 = charset_pixel[5];
132 p4 = charset_pixel[5];
168 return std::make_shared<Border>(unpack(std::move(child)),
ROUNDED);
175 return [pixel](
Element child) {
176 return std::make_shared<Border>(unpack(std::move(child)), pixel);
184 return [style](
Element child) {
185 return std::make_shared<Border>(unpack(std::move(child)), style);
220 return std::make_shared<Border>(unpack(std::move(child)),
LIGHT);
254 return std::make_shared<Border>(unpack(std::move(child)),
HEAVY);
288 return std::make_shared<Border>(unpack(std::move(child)),
DOUBLE);
322 return std::make_shared<Border>(unpack(std::move(child)),
ROUNDED);
356 return std::make_shared<Border>(unpack(std::move(child)),
EMPTY);
381 return std::make_shared<Border>(unpack(std::move(content), std::move(title)),
virtual void SetBox(Box box)
Assign a position and a dimension to an element for drawing.
virtual void ComputeRequirement()
Compute how much space an elements needs.
Element borderDouble(Element)
Draw a double border around the element.
std::function< Element(Element)> Decorator
std::shared_ptr< Node > Element
Decorator borderWith(Pixel)
Same as border but with a constant Pixel around the element.
Element borderRounded(Element)
Draw a rounded border around the element.
Element window(Element title, Element content)
Draw window with a title and a border around the element.
std::vector< Element > Elements
Element borderHeavy(Element)
Draw a heavy border around the element.
Element borderLight(Element)
Draw a light border around the element.
Decorator borderStyled(BorderStyle)
Same as border but with different styles.
Element border(Element)
Draw a border around the element.
Element borderEmpty(Element)
Draw an empty border around the element.
A unicode character and its associated style.