FTXUI 6.1.9 C++ functional terminal UI.

Loading...
Searching...
No Matches
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/dom/selection.hpp" // for Selection
12#include "ftxui/screen/box.hpp" // for Box
13#include "ftxui/screen/screen.hpp"
14
15 namespace ftxui {
16
17 class Node;
18 class Screen;
19
20 using Element = std::shared_ptr<Node>;
21 using Elements = std::vector<Element>;
22
23/// @brief Node is the base class for all elements in the DOM tree.
24///
25/// It represents a single node in the document object model (DOM) and provides
26/// the basic structure for layout and rendering.
27/// It contains methods for computing layout requirements, setting the box
28/// dimensions, selecting content, rendering to the screen, and checking the
29/// layout status.
30/// It typically contains child elements, which are also instances of Node.
31///
32/// Users are expected to derive from this class to create custom elements.
33///
34/// A list of builtin elements can be found in the `elements.hpp` file.
35///
36/// @ingroup dom
37 class Node {
38 public:
39 Node();
40 explicit Node(Elements children);
41 Node(const Node&) = delete;
42 Node(const Node&&) = delete;
43 Node& operator=(const Node&) = delete;
44 Node& operator=(const Node&&) = delete;
45
46 virtual ~Node();
47
48 // Step 1: Compute layout requirement. Tell parent what dimensions this
49 // element wants to be.
50 // Propagated from Children to Parents.
51 virtual void ComputeRequirement();
52 Requirement requirement() { return requirement_; }
53
54 // Step 2: Assign this element its final dimensions.
55 // Propagated from Parents to Children.
56 virtual void SetBox(Box box);
57
58 // Step 3: (optional) Selection
59 // Propagated from Parents to Children.
60 virtual void Select(Selection& selection);
61
62 // Step 4: Draw this element.
63 virtual void Render(Screen& screen);
64
65 virtual std::string GetSelectedContent(Selection& selection);
66
67 // Layout may not resolve within a single iteration for some elements. This
68 // allows them to request additionnal iterations. This signal must be
69 // forwarded to children at least once.
70 struct Status {
71 int iteration = 0;
72 bool need_iteration = false;
73 };
74 virtual void Check(Status* status);
75
76 friend void Render(Screen& screen, Node* node, Selection& selection);
77
78 protected:
79 Elements children_;
80 Requirement requirement_;
81 Box box_;
82};
83
84 void Render(Screen& screen, const Element& element);
85 void Render(Screen& screen, Node* node);
86 void Render(Screen& screen, Node* node, Selection& selection);
87std::string GetNodeSelectedContent(Screen& screen,
88 Node* node,
89 Selection& selection);
90
91} // namespace ftxui
92
93#endif // FTXUI_DOM_NODE_HPP
box.hpp
ftxui::Node::Select
virtual void Select(Selection &selection)
Compute the selection of an element.
Definition node.cpp:46
ftxui::Node::Node
Node()
ftxui::Node::children_
Elements children_
Definition node.hpp:79
ftxui::Node::GetSelectedContent
virtual std::string GetSelectedContent(Selection &selection)
Definition node.cpp:72
ftxui::Node::SetBox
virtual void SetBox(Box box)
Assign a position and a dimension to an element for drawing.
Definition node.cpp:41
ftxui::Node::requirement_
Requirement requirement_
Definition node.hpp:80
ftxui::Node::requirement
Requirement requirement()
Definition node.hpp:52
ftxui::Node::ComputeRequirement
virtual void ComputeRequirement()
Compute how much space an element needs.
Definition node.cpp:20
ftxui::Node::Check
virtual void Check(Status *status)
Definition node.cpp:65
ftxui::Node::~Node
virtual ~Node()
ftxui::Node::operator=
Node & operator=(const Node &)=delete
ftxui::Node::Node
Node(const Node &)=delete
ftxui::Node::box_
Box box_
Definition node.hpp:81
ftxui::Node::Render
friend void Render(Screen &screen, Node *node, Selection &selection)
Definition node.cpp:96
ftxui::Node::operator=
Node & operator=(const Node &&)=delete
ftxui::Node::Node
Node(const Node &&)=delete
ftxui::Node
Node is the base class for all elements in the DOM tree.
Definition node.hpp:37
ftxui::Selection
Represents a selection in a terminal user interface.
Definition selection.hpp:22
ftxui::Render
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Definition node.cpp:84
ftxui::Requirement
Requirement is a structure that defines the layout requirements for a Node in the terminal user inter...
Definition requirement.hpp:18
ftxui::Screen
A rectangular grid of Pixel.
Definition screen.hpp:27
ftxui::Box
Box is a structure that represents a rectangular area in a 2D space.
Definition box.hpp:16
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
ftxui::GetNodeSelectedContent
std::string GetNodeSelectedContent(Screen &screen, Node *node, Selection &selection)
Definition node.cpp:168
ftxui::Element
std::shared_ptr< Node > Element
Definition elements.hpp:22
ftxui::Elements
std::vector< Element > Elements
Definition elements.hpp:23
requirement.hpp
screen.hpp
selection.hpp
ftxui::Node::Status
Definition node.hpp:70
ftxui::Node::Status::need_iteration
bool need_iteration
Definition node.hpp:72
ftxui::Node::Status::iteration
int iteration
Definition node.hpp:71