FTXUI  5.0.0
C++ functional terminal UI.
node.hpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#ifndef FTXUI_DOM_NODE_HPP
5#define FTXUI_DOM_NODE_HPP
6
7#include <memory> // for shared_ptr
8#include <vector> // for vector
9
10#include "ftxui/dom/requirement.hpp" // for Requirement
11#include "ftxui/screen/box.hpp" // for Box
13
14namespace ftxui {
15
16class Node;
17class Screen;
18
19using Element = std::shared_ptr<Node>;
20using Elements = std::vector<Element>;
21
22class Node {
23 public:
25 Node(Elements children);
26 Node(const Node&) = delete;
27 Node(const Node&&) = delete;
28 Node& operator=(const Node&) = delete;
29 Node& operator=(const Node&&) = delete;
30
31 virtual ~Node();
32
33 // Step 1: Compute layout requirement. Tell parent what dimensions this
34 // element wants to be.
35 // Propagated from Children to Parents.
36 virtual void ComputeRequirement();
38
39 // Step 2: Assign this element its final dimensions.
40 // Propagated from Parents to Children.
41 virtual void SetBox(Box box);
42
43 // Step 3: Draw this element.
44 virtual void Render(Screen& screen);
45
46 // Layout may not resolve within a single iteration for some elements. This
47 // allows them to request additionnal iterations. This signal must be
48 // forwarded to children at least once.
49 struct Status {
50 int iteration = 0;
51 bool need_iteration = false;
52 };
53 virtual void Check(Status* status);
54
55 protected:
59};
60
61void Render(Screen& screen, const Element& element);
62void Render(Screen& screen, Node* node);
63
64} // namespace ftxui
65
66#endif // FTXUI_DOM_NODE_HPP
bool need_iteration
Definition: node.hpp:51
Elements children_
Definition: node.hpp:56
virtual void SetBox(Box box)
Assign a position and a dimension to an element for drawing.
Definition: node.cpp:26
Requirement requirement_
Definition: node.hpp:57
Requirement requirement()
Definition: node.hpp:37
virtual void ComputeRequirement()
Compute how much space an elements needs.
Definition: node.cpp:18
virtual void Check(Status *status)
Definition: node.cpp:38
virtual ~Node()
Node & operator=(const Node &)=delete
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
Definition: node.cpp:32
Node(const Node &)=delete
Box box_
Definition: node.hpp:58
Node & operator=(const Node &&)=delete
Node(const Node &&)=delete
A rectangular grid of Pixel.
Definition: screen.hpp:63
std::shared_ptr< Node > Element
Definition: elements.hpp:23
std::vector< Element > Elements
Definition: elements.hpp:24
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Definition: node.cpp:47