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
12 #include "ftxui/screen/screen.hpp"
13 
14 namespace ftxui {
15 
16 class Node;
17 class Screen;
18 
19 using Element = std::shared_ptr<Node>;
20 using Elements = std::vector<Element>;
21 
22 class Node {
23  public:
24  Node();
25  explicit 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 
61 void Render(Screen& screen, const Element& element);
62 void Render(Screen& screen, Node* node);
63 
64 } // namespace ftxui
65 
66 #endif // FTXUI_DOM_NODE_HPP
bool need_iteration
Definition: node.hpp:51
Node & operator=(const Node &)=delete
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
Node & operator=(const Node &&)=delete
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()
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(const Node &&)=delete
A rectangular grid of Pixel.
Definition: screen.hpp:25
std::shared_ptr< Node > Element
Definition: elements.hpp:22
std::vector< Element > Elements
Definition: elements.hpp:23
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Definition: node.cpp:47