Files
FTXUI/src/ftxui/dom/node.cpp

48 lines
918 B
C++
Raw Normal View History

#include "ftxui/dom/node.hpp"
2018-09-18 08:48:40 +02:00
namespace ftxui {
using ftxui::Screen;
2018-09-18 08:48:40 +02:00
Node::Node() {}
Node::Node(std::vector<std::unique_ptr<Node>> children)
: children(std::move(children)) {}
Node::~Node() {}
void Node::ComputeRequirement() {
for(auto& child : children)
child->ComputeRequirement();
}
2018-09-18 08:48:40 +02:00
void Node::SetBox(Box box) {
box_ = box;
}
2018-09-18 08:48:40 +02:00
void Node::Render(Screen& screen) {
for(auto& child : children)
child->Render(screen);
}
void Render(Screen& screen, Node* node) {
// Step 1: Find what dimension this elements wants to be.
node->ComputeRequirement();
Box box;
2019-01-19 22:06:05 +01:00
box.x_min = 0;
box.y_min = 0;
box.x_max = screen.dimx() - 1;
box.y_max = screen.dimy() - 1;
2018-09-18 08:48:40 +02:00
// Step 2: Assign a dimension to the element.
node->SetBox(box);
2019-01-19 22:06:05 +01:00
screen.stencil = box;
2018-09-18 08:48:40 +02:00
// Step 3: Draw the element.
node->Render(screen);
2019-01-19 00:20:29 +01:00
// Step 4: Apply shaders
screen.ApplyShader();
2018-09-18 08:48:40 +02:00
}
2020-02-11 21:44:55 +01:00
} // namespace ftxui