16using Charset = std::array<std::string, 6>;
19static Charsets simple_border_charset = {
20 Charset{
"┌",
"┐",
"└",
"┘",
"─",
"│"},
21 Charset{
"┏",
"┓",
"┗",
"┛",
"━",
"┃"},
22 Charset{
"╔",
"╗",
"╚",
"╝",
"═",
"║"},
23 Charset{
"╭",
"╮",
"╰",
"╯",
"─",
"│"},
24 Charset{
" ",
" ",
" ",
" ",
" ",
" "},
28class Border :
public Node {
31 :
Node(std::move(children)),
32 charset_(simple_border_charset[style]) {}
36 void ComputeRequirement()
override {
51 void SetBox(Box box)
override {
55 title_box.x_min = box.x_min + 1;
56 title_box.x_max = box.x_max - 1;
57 title_box.y_min = box.y_min;
58 title_box.y_max = box.y_min;
68 void Render(Screen& screen)
override {
83 Pixel& p1 = screen.PixelAt(x,
box_.
y_min);
84 Pixel& p2 = screen.PixelAt(x,
box_.
y_max);
85 p1.character = charset_[4];
86 p2.character = charset_[4];
91 Pixel& p3 = screen.PixelAt(
box_.
x_min, y);
92 Pixel& p4 = screen.PixelAt(
box_.
x_max, y);
93 p3.character = charset_[5];
94 p4.character = charset_[5];
107class BorderPixel :
public Node {
109 BorderPixel(
Elements children, Pixel pixel)
110 :
Node(std::move(children)), pixel_(std::move(pixel)) {}
115 void ComputeRequirement()
override {
130 void SetBox(Box box)
override {
134 title_box.x_min = box.x_min + 1;
135 title_box.x_max = box.x_max - 1;
136 title_box.y_min = box.y_min;
137 title_box.y_max = box.y_min;
147 void Render(Screen& screen)
override {
201 return std::make_shared<Border>(unpack(std::move(child)),
ROUNDED);
208 return [pixel](
Element child) {
209 return std::make_shared<BorderPixel>(unpack(std::move(child)), pixel);
217 return [style](
Element child) {
218 return std::make_shared<Border>(unpack(std::move(child)), style);
253 return std::make_shared<Border>(unpack(std::move(child)),
LIGHT);
287 return std::make_shared<Border>(unpack(std::move(child)),
HEAVY);
321 return std::make_shared<Border>(unpack(std::move(child)),
DOUBLE);
355 return std::make_shared<Border>(unpack(std::move(child)),
ROUNDED);
389 return std::make_shared<Border>(unpack(std::move(child)),
EMPTY);
414 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
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
std::array< Charset, 6 > Charsets
Element borderHeavy(Element)
Draw a heavy border around the element.
Element borderLight(Element)
Draw a light border around the element.
Decorator borderWith(const Pixel &)
Same as border but with a constant Pixel around the element.
Decorator borderStyled(BorderStyle)
Same as border but with different styles.
std::array< std::string, 6 > Charset
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.