2021-05-10 02:32:27 +08:00
|
|
|
#include <memory> // for make_shared
|
2021-05-02 02:40:35 +08:00
|
|
|
|
2021-05-10 02:32:27 +08:00
|
|
|
#include "ftxui/dom/elements.hpp" // for Element, separator
|
|
|
|
#include "ftxui/dom/node.hpp" // for Node
|
|
|
|
#include "ftxui/dom/requirement.hpp" // for Requirement
|
|
|
|
#include "ftxui/screen/box.hpp" // for Box
|
|
|
|
#include "ftxui/screen/screen.hpp" // for Pixel, Screen
|
2018-09-20 03:52:25 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
namespace ftxui {
|
2019-01-07 00:10:35 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
using ftxui::Screen;
|
2018-09-20 03:52:25 +08:00
|
|
|
|
|
|
|
class Separator : public Node {
|
|
|
|
public:
|
|
|
|
Separator() {}
|
|
|
|
~Separator() override {}
|
|
|
|
void ComputeRequirement() override {
|
2020-06-01 22:13:29 +08:00
|
|
|
requirement_.min_x = 1;
|
|
|
|
requirement_.min_y = 1;
|
2018-09-20 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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'─';
|
2019-01-05 09:03:49 +08:00
|
|
|
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:
|
2021-05-16 23:18:11 +08:00
|
|
|
SeparatorWithPixel(Pixel pixel) : pixel_(pixel) {}
|
2019-01-27 09:33:06 +08:00
|
|
|
~SeparatorWithPixel() override {}
|
2021-05-16 23:18:11 +08:00
|
|
|
void Render(Screen& screen) override { RenderWithPixel(screen, pixel_); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Pixel pixel_;
|
2019-01-27 09:33:06 +08:00
|
|
|
};
|
|
|
|
|
2020-05-21 02:36:47 +08:00
|
|
|
Element separator() {
|
|
|
|
return std::make_shared<Separator>();
|
2018-09-20 03:52:25 +08:00
|
|
|
}
|
|
|
|
|
2020-05-21 02:36:47 +08:00
|
|
|
Element separator(Pixel pixel) {
|
|
|
|
return std::make_shared<SeparatorWithPixel>(pixel);
|
2019-01-27 09:33:06 +08:00
|
|
|
}
|
|
|
|
|
2020-02-12 04:44:55 +08:00
|
|
|
} // namespace ftxui
|
2020-08-16 06:24:18 +08:00
|
|
|
|
|
|
|
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license that can be found in
|
|
|
|
// the LICENSE file.
|