FTXUI  0.11.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
node.cpp
Go to the documentation of this file.
1#include <utility>
2
3#include "ftxui/dom/node.hpp"
5
6namespace ftxui {
7
9Node::Node(Elements children) : children_(std::move(children)) {}
11
12/// @brief Compute how much space an elements needs.
13/// @ingroup dom
15 for (auto& child : children_)
16 child->ComputeRequirement();
17}
18
19/// @brief Assign a position and a dimension to an element for drawing.
20/// @ingroup dom
21void Node::SetBox(Box box) {
22 box_ = box;
23}
24
25/// @brief Display an element on a ftxui::Screen.
26/// @ingroup dom
27void Node::Render(Screen& screen) {
28 for (auto& child : children_)
29 child->Render(screen);
30}
31
32/// @brief Display an element on a ftxui::Screen.
33/// @ingroup dom
34void Render(Screen& screen, const Element& element) {
35 Render(screen, element.get());
36}
37
38/// @brief Display an element on a ftxui::Screen.
39/// @ingroup dom
40void Render(Screen& screen, Node* node) {
41 // Step 1: Find what dimension this elements wants to be.
42 node->ComputeRequirement();
43
44 Box box;
45 box.x_min = 0;
46 box.y_min = 0;
47 box.x_max = screen.dimx() - 1;
48 box.y_max = screen.dimy() - 1;
49
50 // Step 2: Assign a dimension to the element.
51 node->SetBox(box);
52 screen.stencil = box;
53
54 // Step 3: Draw the element.
55 node->Render(screen);
56
57 // Step 4: Apply shaders
58 screen.ApplyShader();
59}
60
61} // namespace ftxui
62
63// Copyright 2020 Arthur Sonzogni. All rights reserved.
64// Use of this source code is governed by the MIT license that can be found in
65// the LICENSE file.
Elements children_
Definition node.hpp:39
virtual void SetBox(Box box)
Assign a position and a dimension to an element for drawing.
Definition node.cpp:21
virtual void ComputeRequirement()
Compute how much space an elements needs.
Definition node.cpp:14
virtual ~Node()
Definition node.cpp:10
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
Definition node.cpp:27
Box box_
Definition node.hpp:41
A rectangular grid of Pixel.
Definition screen.hpp:49
void ApplyShader()
Definition screen.cpp:455
std::shared_ptr< Node > Element
Definition elements.hpp:15
std::vector< Element > Elements
Definition elements.hpp:16
void Render(Screen &screen, const Element &node)
Display an element on a ftxui::Screen.
Definition node.cpp:34
int x_max
Definition box.hpp:8
int y_min
Definition box.hpp:9
int y_max
Definition box.hpp:10
int x_min
Definition box.hpp:7