2018-10-10 01:06:03 +08:00
|
|
|
#include "ftxui/dom/node.hpp"
|
2018-09-18 14:48:40 +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-18 14:48:40 +08:00
|
|
|
|
|
|
|
class Text : public Node {
|
|
|
|
public:
|
|
|
|
Text(std::wstring text) : Node(), text_(text) {}
|
|
|
|
~Text() {}
|
|
|
|
|
|
|
|
void ComputeRequirement() override {
|
|
|
|
requirement_.min.x = text_.size();
|
|
|
|
requirement_.min.y = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Render(Screen& screen) override {
|
2019-01-20 05:06:05 +08:00
|
|
|
int x = box_.x_min;
|
|
|
|
int y = box_.y_min;
|
|
|
|
if (y > box_.y_max)
|
2018-09-18 14:48:40 +08:00
|
|
|
return;
|
|
|
|
for (wchar_t c : text_) {
|
2019-01-20 05:06:05 +08:00
|
|
|
if (x > box_.x_max)
|
2018-09-18 14:48:40 +08:00
|
|
|
return;
|
|
|
|
screen.at(x++, y) = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::wstring text_;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<Node> text(std::wstring text) {
|
|
|
|
return std::make_unique<Text>(text);
|
|
|
|
}
|
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
}; // namespace ftxui
|