FTXUI
6.1.9
C++ functional terminal UI.
Toggle main menu visibility
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
class
Node
{
24
public
:
25
Node
();
26
explicit
Node
(
Elements
children);
27
Node
(
const
Node
&) =
delete
;
28
Node
(
const
Node
&&) =
delete
;
29
Node
&
operator=
(
const
Node
&) =
delete
;
30
Node
&
operator=
(
const
Node
&&) =
delete
;
31
32
virtual
~Node
();
33
34
// Step 1: Compute layout requirement. Tell parent what dimensions this
35
// element wants to be.
36
// Propagated from Children to Parents.
37
virtual
void
ComputeRequirement
();
38
Requirement
requirement
() {
return
requirement_
; }
39
40
// Step 2: Assign this element its final dimensions.
41
// Propagated from Parents to Children.
42
virtual
void
SetBox
(
Box
box);
43
44
// Step 3: (optional) Selection
45
// Propagated from Parents to Children.
46
virtual
void
Select
(
Selection
& selection);
47
48
// Step 4: Draw this element.
49
virtual
void
Render
(
Screen
& screen);
50
51
virtual
std::string
GetSelectedContent
(
Selection
& selection);
52
53
// Layout may not resolve within a single iteration for some elements. This
54
// allows them to request additionnal iterations. This signal must be
55
// forwarded to children at least once.
56
struct
Status
{
57
int
iteration
= 0;
58
bool
need_iteration
=
false
;
59
};
60
virtual
void
Check
(
Status
* status);
61
62
friend
void
Render
(
Screen
& screen,
Node
* node,
Selection
& selection);
63
64
protected
:
65
Elements
children_
;
66
Requirement
requirement_
;
67
Box
box_
;
68
};
69
70
void
Render
(
Screen
& screen,
const
Element
& element);
71
void
Render
(
Screen
& screen,
Node
* node);
72
void
Render
(
Screen
& screen,
Node
* node,
Selection
& selection);
73
std::string
GetNodeSelectedContent
(
Screen
& screen,
74
Node
* node,
75
Selection
& selection);
76
77
}
// namespace ftxui
78
79
#endif
// FTXUI_DOM_NODE_HPP
box.hpp
ftxui::Node
Definition
node.hpp:23
ftxui::Node::Select
virtual void Select(Selection &selection)
Compute the selection of an element.
Definition
node.cpp:49
ftxui::Node::Node
Node()
ftxui::Node::Status::need_iteration
bool need_iteration
Definition
node.hpp:58
ftxui::Node::children_
Elements children_
Definition
node.hpp:65
ftxui::Node::GetSelectedContent
virtual std::string GetSelectedContent(Selection &selection)
Definition
node.cpp:76
ftxui::Node::SetBox
virtual void SetBox(Box box)
Assign a position and a dimension to an element for drawing.
Definition
node.cpp:43
ftxui::Node::requirement_
Requirement requirement_
Definition
node.hpp:66
ftxui::Node::requirement
Requirement requirement()
Definition
node.hpp:38
ftxui::Node::ComputeRequirement
virtual void ComputeRequirement()
Compute how much space an elements needs.
Definition
node.cpp:21
ftxui::Node::Check
virtual void Check(Status *status)
Definition
node.cpp:69
ftxui::Node::~Node
virtual ~Node()
ftxui::Node::operator=
Node & operator=(const Node &)=delete
ftxui::Node::Render
virtual void Render(Screen &screen)
Display an element on a ftxui::Screen.
Definition
node.cpp:63
ftxui::Node::Node
Node(const Node &)=delete
ftxui::Node::Status::iteration
int iteration
Definition
node.hpp:57
ftxui::Node::box_
Box box_
Definition
node.hpp:67
ftxui::Node::operator=
Node & operator=(const Node &&)=delete
ftxui::Node::Node
Node(const Node &&)=delete
ftxui::Node::Status
Definition
node.hpp:56
ftxui::Screen
A rectangular grid of Pixel.
Definition
screen.hpp:27
ftxui::Selection
Represent a selection in the terminal.
Definition
selection.hpp:17
ftxui
Definition
animation.hpp:10
ftxui::GetNodeSelectedContent
std::string GetNodeSelectedContent(Screen &screen, Node *node, Selection &selection)
Definition
node.cpp:172
ftxui::Element
std::shared_ptr< Node > Element
Definition
elements.hpp:22
ftxui::Elements
std::vector< Element > Elements
Definition
elements.hpp:23
ftxui::Render
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Definition
node.cpp:88
ftxui::Requirement
Definition
requirement.hpp:13
requirement.hpp
screen.hpp
selection.hpp
ftxui::Box
Definition
box.hpp:9