# FTXUI: node.hpp Source File

Loading...
Searching...
No Matches
node.hpp
Go to the documentation of this file.
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#ifndef FTXUI_DOM_NODE_HPP
#define FTXUI_DOM_NODE_HPP
#include <memory> // for shared_ptr
#include <vector> // for vector
#include "ftxui/dom/requirement.hpp" // for Requirement
#include "ftxui/dom/selection.hpp" // for Selection
#include "ftxui/screen/box.hpp" // for Box
#include "ftxui/screen/screen.hpp"
namespace ftxui {
class Node;
class Screen;
using Element = std::shared_ptr<Node>;
using Elements = std::vector<Element>;
/// @brief Node is the base class for all elements in the DOM tree.
///
/// It represents a single node in the document object model (DOM) and provides
/// the basic structure for layout and rendering.
/// It contains methods for computing layout requirements, setting the box
/// dimensions, selecting content, rendering to the screen, and checking the
/// layout status.
/// It typically contains child elements, which are also instances of Node.
///
/// Users are expected to derive from this class to create custom elements.
///
/// A list of builtin elements can be found in the `elements.hpp` file.
///
/// @ingroup dom
class Node {
public:
Node();
explicit Node(Elements children);
Node(const Node&) = delete;
Node(const Node&&) = delete;
Node& operator=(const Node&) = delete;
Node& operator=(const Node&&) = delete;
virtual ~Node();
// Step 1: Compute layout requirement. Tell parent what dimensions this
// element wants to be.
// Propagated from Children to Parents.
virtual void ComputeRequirement();
Requirement requirement() { return requirement_; }
// Step 2: Assign this element its final dimensions.
// Propagated from Parents to Children.
virtual void SetBox(Box box);
// Step 3: (optional) Selection
// Propagated from Parents to Children.
virtual void Select(Selection& selection);
// Step 4: Draw this element.
virtual void Render(Screen& screen);
virtual std::string GetSelectedContent(Selection& selection);
// Layout may not resolve within a single iteration for some elements. This
// allows them to request additionnal iterations. This signal must be
// forwarded to children at least once.
struct Status {
int iteration = 0;
bool need_iteration = false;
};
virtual void Check(Status* status);
friend void Render(Screen& screen, Node* node, Selection& selection);
protected:
Elements children_;
Requirement requirement_;
Box box_;
};
void Render(Screen& screen, const Element& element);
void Render(Screen& screen, Node* node);
void Render(Screen& screen, Node* node, Selection& selection);
std::string GetNodeSelectedContent(Screen& screen,
Node* node,
Selection& selection);
} // namespace ftxui
#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:26
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