FTXUI/src/ftxui/dom/separator.cpp

57 lines
1.2 KiB
C++
Raw Normal View History

#include "ftxui/dom/node.hpp"
2018-09-20 03:52:25 +08:00
namespace ftxui {
using ftxui::Screen;
2018-09-20 03:52:25 +08:00
class Separator : public Node {
public:
Separator() {}
~Separator() override {}
void ComputeRequirement() override {
requirement_.min.x = 1;
requirement_.min.y = 1;
}
void Render(Screen& screen) override {
2019-01-20 05:06:05 +08:00
bool is_column = (box_.x_max == box_.x_min);
bool is_line = (box_.y_min == box_.y_max);
2018-09-20 03:52:25 +08:00
wchar_t c = U'+';
if (is_line && !is_column)
c = U'';
else
2018-09-20 03:52:25 +08:00
c = U'';
2019-01-27 09:33:06 +08:00
Pixel p;
p.character = c;
RenderWithPixel(screen, p);
}
void RenderWithPixel(Screen& screen, Pixel pixel) {
2019-01-20 05:06:05 +08:00
for (int y = box_.y_min; y <= box_.y_max; ++y) {
for (int x = box_.x_min; x <= box_.x_max; ++x) {
2019-01-27 09:33:06 +08:00
screen.PixelAt(x, y) = pixel;
2018-09-20 03:52:25 +08:00
}
}
}
};
2019-01-27 09:33:06 +08:00
class SeparatorWithPixel : public Separator {
public:
SeparatorWithPixel(Pixel p) : p(p) {}
~SeparatorWithPixel() override {}
void Render(Screen& screen) override { RenderWithPixel(screen, p); }
Pixel p;
};
2018-09-20 03:52:25 +08:00
std::unique_ptr<Node> separator() {
return std::make_unique<Separator>();
}
2019-01-27 09:33:06 +08:00
std::unique_ptr<Node> separator(Pixel pixel) {
return std::make_unique<SeparatorWithPixel>(pixel);
}
}; // namespace ftxui