16static std::string simple_border_charset[6][6] = {
17 {
"┌",
"┐",
"└",
"┘",
"─",
"│"},
18 {
"┏",
"┓",
"┗",
"┛",
"━",
"┃"},
19 {
"╔",
"╗",
"╚",
"╝",
"═",
"║"},
20 {
"╭",
"╮",
"╰",
"╯",
"─",
"│"},
28class Border :
public Node {
31 :
Node(std::move(children)),
32 charset(std::begin(simple_border_charset[style]),
33 std::end(simple_border_charset[style])) {}
34 Border(
Elements children, Pixel pixel)
35 :
Node(std::move(children)), charset_pixel(10, pixel) {}
37 std::vector<Pixel> charset_pixel;
38 std::vector<std::string> charset;
40 void ComputeRequirement()
override {
55 void SetBox(Box box)
override {
59 title_box.x_min = box.x_min + 1;
60 title_box.x_max = box.x_max - 1;
61 title_box.y_min = box.y_min;
62 title_box.y_max = box.y_min;
72 void Render(Screen& screen)
override {
86 void RenderPixel(Screen& screen) {
105 void RenderChar(Screen& screen) {
111 screen.PixelAt(x,
box_.
y_min) = charset_pixel[4];
112 screen.PixelAt(x,
box_.
y_max) = charset_pixel[4];
115 screen.PixelAt(
box_.
x_min, y) = charset_pixel[5];
116 screen.PixelAt(
box_.
x_max, y) = charset_pixel[5];
149 return std::make_shared<Border>(unpack(std::move(child)),
ROUNDED);
156 return [pixel](
Element child) {
157 return std::make_shared<Border>(unpack(std::move(child)), pixel);
165 return [style](
Element child) {
166 return std::make_shared<Border>(unpack(std::move(child)), style);
200 return std::make_shared<Border>(unpack(std::move(child)),
LIGHT);
233 return std::make_shared<Border>(unpack(std::move(child)),
HEAVY);
266 return std::make_shared<Border>(unpack(std::move(child)),
DOUBLE);
299 return std::make_shared<Border>(unpack(std::move(child)),
ROUNDED);
324 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.
A unicode character and its associated style.