feat: Multiple border style. (#202)

This commit is contained in:
Arthur Sonzogni
2021-09-12 00:36:59 +02:00
committed by GitHub
parent 4d50dadb41
commit b5c3b17b3f
8 changed files with 506 additions and 40 deletions

View File

@@ -11,8 +11,17 @@ namespace ftxui {
using ftxui::Screen;
const std::string charset[][2] = {
{"", ""},
{"", ""},
{"", ""},
{"", ""},
};
class Separator : public Node {
public:
Separator(BorderStyle style) : style_(style) {}
void ComputeRequirement() override {
requirement_.min_x = 1;
requirement_.min_y = 1;
@@ -22,11 +31,7 @@ class Separator : public Node {
bool is_column = (box_.x_max == box_.x_min);
bool is_line = (box_.y_min == box_.y_max);
std::string c = "+";
if (is_line && !is_column)
c = "";
else
c = "";
const std::string c = charset[style_][is_line && !is_column];
for (int y = box_.y_min; y <= box_.y_max; ++y) {
for (int x = box_.x_min; x <= box_.x_max; ++x) {
@@ -34,11 +39,13 @@ class Separator : public Node {
}
}
}
BorderStyle style_;
};
class SeparatorWithPixel : public Separator {
public:
SeparatorWithPixel(Pixel pixel) : pixel_(pixel) {}
SeparatorWithPixel(Pixel pixel) : Separator(LIGHT), pixel_(pixel) {}
void Render(Screen& screen) override {
for (int y = box_.y_min; y <= box_.y_max; ++y) {
for (int x = box_.x_min; x <= box_.x_max; ++x) {
@@ -52,11 +59,21 @@ class SeparatorWithPixel : public Separator {
};
Element separator() {
return std::make_shared<Separator>();
return std::make_shared<Separator>(LIGHT);
}
Element separator(Pixel pixel) {
return std::make_shared<SeparatorWithPixel>(pixel);
Element separatorStyled(BorderStyle style) {
return std::make_shared<Separator>(style);
}
Element separatorLight() {
return std::make_shared<Separator>(LIGHT);
}
Element separatorHeavy() {
return std::make_shared<Separator>(HEAVY);
}
Element separatorDouble() {
return std::make_shared<Separator>(DOUBLE);
}
} // namespace ftxui