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) {
106 void RenderChar(Screen& screen) {
112 screen.PixelAt(x,
box_.
y_min) = charset_pixel[4];
113 screen.PixelAt(x,
box_.
y_max) = charset_pixel[4];
116 screen.PixelAt(
box_.
x_min, y) = charset_pixel[5];
117 screen.PixelAt(
box_.
x_max, y) = charset_pixel[5];
151 return std::make_shared<Border>(unpack(std::move(child)),
ROUNDED);
158 return [pixel](
Element child) {
159 return std::make_shared<Border>(unpack(std::move(child)), pixel);
167 return [style](
Element child) {
168 return std::make_shared<Border>(unpack(std::move(child)), style);
203 return std::make_shared<Border>(unpack(std::move(child)),
LIGHT);
237 return std::make_shared<Border>(unpack(std::move(child)),
HEAVY);
271 return std::make_shared<Border>(unpack(std::move(child)),
DOUBLE);
305 return std::make_shared<Border>(unpack(std::move(child)),
ROUNDED);
339 return std::make_shared<Border>(unpack(std::move(child)),
EMPTY);
364 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.