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
14
15namespace ftxui {
16
17class Node;
18class Screen;
19
20using Element = std::shared_ptr<Node>;
21using Elements = std::vector<Element>;
22
23/// @brief 節點是DOM樹中所有元素的基底類別。
24///
25/// 它代表文件物件模型 (DOM) 中的單一節點,並提供佈局和渲染的基本結構。
26/// 它包含用於計算佈局需求、設定框尺寸、選取內容、渲染到螢幕以及檢查佈局狀態的方法。
27/// 它通常包含子元素,這些子元素也是節點的實例。
28///
29/// 鼓勵使用者從這個類別派生以建立自訂元素。
30///
31/// 內建元素的清單可以在 `elements.hpp` 檔案中找到。
32///
33/// @ingroup dom
34class Node {
35 public:
37 explicit Node(Elements children);
38 Node(const Node&) = delete;
39 Node(const Node&&) = delete;
40 Node& operator=(const Node&) = delete;
41 Node& operator=(const Node&&) = delete;
42
43 virtual ~Node();
44
45 // 步驟 1: 計算佈局需求。告知父元素此元素想要的尺寸。
46 // 從子元素傳播到父元素。
47 virtual void ComputeRequirement();
49
50 // 步驟 2: 為此元素指定其最終尺寸。
51 // 從父元素傳播到子元素。
52 virtual void SetBox(Box box);
53
54 // 步驟 3: (可選) 選取
55 // 從父元素傳播到子元素。
56 virtual void Select(Selection& selection);
57
58 // 步驟 4: 繪製此元素。
59 virtual void Render(Screen& screen);
60
61 virtual std::string GetSelectedContent(Selection& selection);
62
63 // 對於某些元素,佈局可能無法在單次迭代中解決。
64 // 這允許它們請求額外的迭代。此信號必須至少轉發給子元素一次。
65 struct Status {
66 int iteration = 0;
67 bool need_iteration = false;
68 };
69 virtual void Check(Status* status);
70
71 friend void Render(Screen& screen, Node* node, Selection& selection);
72
73 protected:
77};
78
79void Render(Screen& screen, const Element& element);
80void Render(Screen& screen, Node* node);
81void Render(Screen& screen, Node* node, Selection& selection);
82std::string GetNodeSelectedContent(Screen& screen,
83 Node* node,
84 Selection& selection);
85
86} // namespace ftxui
87
88#endif // FTXUI_DOM_NODE_HPP
virtual void Render(Screen &screen)
virtual void Select(Selection &selection)
計算元素的選取範圍。
Definition node.cpp:45
Elements children_
Definition node.hpp:74
virtual std::string GetSelectedContent(Selection &selection)
Definition node.cpp:70
virtual void SetBox(Box box)
為元素分配繪圖位置和尺寸。
Definition node.cpp:40
Requirement requirement_
Definition node.hpp:75
Requirement requirement()
Definition node.hpp:48
virtual void ComputeRequirement()
計算元素所需的空間大小。
Definition node.cpp:19
virtual void Check(Status *status)
Definition node.cpp:63
virtual ~Node()
Node & operator=(const Node &)=delete
Node(const Node &)=delete
Box box_
Definition node.hpp:76
friend void Render(Screen &screen, Node *node, Selection &selection)
Node & operator=(const Node &&)=delete
Node(const Node &&)=delete
節點是DOM樹中所有元素的基底類別。
Definition node.hpp:34
表示終端機使用者介面中的選取範圍。
Definition selection.hpp:21
Requirement 是一個結構,定義了終端使用者介面中節點的佈局要求。
像素的矩形網格。
Definition screen.hpp:26
Box 是一個表示二維空間中矩形區域的結構。
Definition box.hpp:14
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
std::string GetNodeSelectedContent(Screen &screen, Node *node, Selection &selection)
std::shared_ptr< Node > Element
Definition elements.hpp:22
std::vector< Element > Elements
Definition elements.hpp:23
void Render(Screen &screen, const Element &element)