FTXUI  0.9.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
separator.cpp
Go to the documentation of this file.
1#include <memory> // for make_shared
2#include <string> // for string
3
4#include "ftxui/dom/elements.hpp" // for Element, separator
5#include "ftxui/dom/node.hpp" // for Node
6#include "ftxui/dom/requirement.hpp" // for Requirement
7#include "ftxui/screen/box.hpp" // for Box
8#include "ftxui/screen/screen.hpp" // for Pixel, Screen
9
10namespace ftxui {
11
12using ftxui::Screen;
13
14const std::string charset[][2] = {
15 {"│", "─"},
16 {"┃", "━"},
17 {"║", "═"},
18 {"│", "─"},
19};
20
21class Separator : public Node {
22 public:
23 Separator(BorderStyle style) : style_(style) {}
24
25 void ComputeRequirement() override {
28 }
29
30 void Render(Screen& screen) override {
31 bool is_column = (box_.x_max == box_.x_min);
32 bool is_line = (box_.y_min == box_.y_max);
33
34 const std::string c = charset[style_][is_line && !is_column];
35
36 for (int y = box_.y_min; y <= box_.y_max; ++y) {
37 for (int x = box_.x_min; x <= box_.x_max; ++x) {
38 screen.PixelAt(x, y).character = c;
39 }
40 }
41 }
42
43 BorderStyle style_;
44};
45
46class SeparatorWithPixel : public Separator {
47 public:
48 SeparatorWithPixel(Pixel pixel) : Separator(LIGHT), pixel_(pixel) {}
49 void Render(Screen& screen) override {
50 for (int y = box_.y_min; y <= box_.y_max; ++y) {
51 for (int x = box_.x_min; x <= box_.x_max; ++x) {
52 screen.PixelAt(x, y) = pixel_;
53 }
54 }
55 }
56
57 private:
58 Pixel pixel_;
59};
60
62 return std::make_shared<Separator>(LIGHT);
63}
64
66 return std::make_shared<Separator>(style);
67}
68
70 return std::make_shared<Separator>(LIGHT);
71}
73 return std::make_shared<Separator>(HEAVY);
74}
76 return std::make_shared<Separator>(DOUBLE);
77}
78
79} // namespace ftxui
80
81// Copyright 2020 Arthur Sonzogni. All rights reserved.
82// Use of this source code is governed by the MIT license that can be found in
83// the LICENSE file.
Requirement requirement_
Definition node.hpp:40
Box box_
Definition node.hpp:41
A rectangular grid of Pixel.
Definition screen.hpp:49
std::shared_ptr< Node > Element
Definition elements.hpp:15
Element separatorLight()
Definition separator.cpp:69
Element separator(void)
Definition separator.cpp:61
Element separatorDouble()
Definition separator.cpp:75
Element separatorHeavy()
Definition separator.cpp:72
Element separatorStyled(BorderStyle)
Definition separator.cpp:65
BorderStyle
Definition elements.hpp:20
@ DOUBLE
Definition elements.hpp:20
@ HEAVY
Definition elements.hpp:20
@ LIGHT
Definition elements.hpp:20
int x_max
Definition box.hpp:8
int y_min
Definition box.hpp:9
int y_max
Definition box.hpp:10
int x_min
Definition box.hpp:7