FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
node.hpp
浏览该文件的文档.
1// 版权所有 2020 Arthur Sonzogni. 保留所有权利。
2// 本源代码的使用受 MIT 许可证的约束,该许可证可在 LICENSE 文件中找到。
3#ifndef FTXUI_DOM_NODE_HPP
4#define FTXUI_DOM_NODE_HPP
5
6#include <memory> // for shared_ptr
7#include <vector> // for vector
8
9#include "ftxui/dom/requirement.hpp" // for Requirement
10#include "ftxui/dom/selection.hpp" // for Selection
11#include "ftxui/screen/box.hpp" // for Box
13
14namespace ftxui {
15
16class Node;
17class Screen;
18
19using Element = std::shared_ptr<Node>;
20using Elements = std::vector<Element>;
21
22/// @brief Node 是 DOM 树中所有元素的基类。
23///
24/// 它代表文档对象模型 (DOM) 中的单个节点,并提供布局和渲染的基本结构。
25/// 它包含用于计算布局要求、设置盒子尺寸、选择内容、渲染到屏幕以及检查布局状态的方法。
26/// 它通常包含子元素,这些子元素也是 Node 的实例。
27///
28/// 用户应从该类派生以创建自定义元素。
29///
30/// 内置元素的列表可在 `elements.hpp` 文件中找到。
31///
32/// @ingroup dom
33class Node {
34 public:
36 explicit Node(Elements children);
37 Node(const Node&) = delete;
38 Node(const Node&&) = delete;
39 Node& operator=(const Node&) = delete;
40 Node& operator=(const Node&&) = delete;
41
42 virtual ~Node();
43
44 // 步骤 1: 计算布局要求。告诉父级此元素希望的尺寸。
45 // 从子级传播到父级。
46 virtual void ComputeRequirement();
48
49 // 步骤 2: 为此元素分配最终尺寸。
50 // 从父级传播到子级。
51 virtual void SetBox(Box box);
52
53 // 步骤 3: (可选) 选择
54 // 从父级传播到子级。
55 virtual void Select(Selection& selection);
56
57 // 步骤 4: 绘制此元素。
58 virtual void Render(Screen& screen);
59
60 virtual std::string GetSelectedContent(Selection& selection);
61
62 // 对于某些元素,布局可能无法在单次迭代中解决。这允许它们请求额外的迭代。
63 // 此信号必须至少转发给子级一次。
64 struct Status {
65 int iteration = 0;
66 bool need_iteration = false;
67 };
68 virtual void Check(Status* status);
69
70 friend void Render(Screen& screen, Node* node, Selection& selection);
71
72 protected:
76};
77
78void Render(Screen& screen, const Element& element);
79void Render(Screen& screen, Node* node);
80void Render(Screen& screen, Node* node, Selection& selection);
81std::string GetNodeSelectedContent(Screen& screen,
82 Node* node,
83 Selection& selection);
84
85} // namespace ftxui
86
87#endif // FTXUI_DOM_NODE_HPP
virtual void Select(Selection &selection)
计算元素的选区。
Elements children_
virtual std::string GetSelectedContent(Selection &selection)
virtual void SetBox(Box box)
为绘图元素分配位置和尺寸。
Requirement requirement_
Requirement requirement()
virtual void ComputeRequirement()
计算元素所需的空间。
virtual void Check(Status *status)
virtual ~Node()
Node & operator=(const Node &)=delete
Node(const Node &)=delete
friend void Render(Screen &screen, Node *node, Selection &selection)
Node & operator=(const Node &&)=delete
Node(const Node &&)=delete
Node 是 DOM 树中所有元素的基类。
代表终端用户界面中的选择。
void Render(Screen &screen, const Element &element)
在 ftxui::Screen 上显示元素。
Requirement 是一个结构体,用于定义终端用户界面中 Node 的布局要求。
像素的矩形网格。
Box是一个表示2D空间中矩形区域的结构体。
定义 box.hpp:15
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
std::string GetNodeSelectedContent(Screen &screen, Node *node, Selection &selection)
std::shared_ptr< Node > Element
std::vector< Element > Elements