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