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
|
|
|
|
|
|
|
Node::Node() {}
|
|
|
|
Node::Node(std::vector<std::unique_ptr<Node>> children)
|
|
|
|
: children(std::move(children)) {}
|
|
|
|
Node::~Node() {}
|
|
|
|
|
2018-10-10 01:06:03 +08:00
|
|
|
void Node::ComputeRequirement() {
|
2020-03-23 05:32:44 +08:00
|
|
|
for (auto& child : children)
|
2018-10-10 01:06:03 +08:00
|
|
|
child->ComputeRequirement();
|
|
|
|
}
|
|
|
|
|
2018-09-18 14:48:40 +08:00
|
|
|
void Node::SetBox(Box box) {
|
|
|
|
box_ = box;
|
|
|
|
}
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2018-09-18 14:48:40 +08:00
|
|
|
void Node::Render(Screen& screen) {
|
2020-03-23 05:32:44 +08:00
|
|
|
for (auto& child : children)
|
2018-09-18 14:48:40 +08:00
|
|
|
child->Render(screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Render(Screen& screen, Node* node) {
|
|
|
|
// Step 1: Find what dimension this elements wants to be.
|
|
|
|
node->ComputeRequirement();
|
2020-03-23 05:32:44 +08:00
|
|
|
|
2018-09-18 14:48:40 +08:00
|
|
|
Box box;
|
2019-01-20 05:06:05 +08:00
|
|
|
box.x_min = 0;
|
|
|
|
box.y_min = 0;
|
|
|
|
box.x_max = screen.dimx() - 1;
|
|
|
|
box.y_max = screen.dimy() - 1;
|
2020-03-23 05:32:44 +08:00
|
|
|
|
2018-09-18 14:48:40 +08:00
|
|
|
// Step 2: Assign a dimension to the element.
|
|
|
|
node->SetBox(box);
|
2019-01-20 05:06:05 +08:00
|
|
|
screen.stencil = box;
|
2018-09-18 14:48:40 +08:00
|
|
|
|
|
|
|
// Step 3: Draw the element.
|
|
|
|
node->Render(screen);
|
2019-01-19 07:20:29 +08:00
|
|
|
|
|
|
|
// Step 4: Apply shaders
|
|
|
|
screen.ApplyShader();
|
2018-09-18 14:48:40 +08:00
|
|
|
}
|
|
|
|
|
2020-02-12 04:44:55 +08:00
|
|
|
} // namespace ftxui
|