FTXUI 7.0.3
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#include "ftxui/util/export.hpp"
15
16namespace ftxui {
17
18class Node;
19class Screen;
20
21using Element = std::shared_ptr<Node>;
22using Elements = std::vector<Element>;
23
24/// @brief 節點是DOM樹中所有元素的基底類別。
25///
26/// 它代表文件物件模型 (DOM) 中的單一節點,並提供佈局和渲染的基本結構。
27/// 它包含用於計算佈局需求、設定框尺寸、選取內容、渲染到螢幕以及檢查佈局狀態的方法。
28/// 它通常包含子元素,這些子元素也是節點的實例。
29///
30/// 鼓勵使用者從這個類別派生以建立自訂元素。
31///
32/// 內建元素的清單可以在 `elements.hpp` 檔案中找到。
33///
34/// @ingroup dom
35class FTXUI_EXPORT(DOM) Node {
36 public:
37 Node();
38 explicit Node(Elements children);
39 Node(const Node&) = delete;
40 Node(const Node&&) = delete;
41 Node& operator=(const Node&) = delete;
42 Node& operator=(const Node&&) = delete;
43
44 virtual ~Node();
45
46 // 步驟 1:計算布局需求。告知父元件此
47 // 元素想要的尺寸。
48 // 從子元件傳遞到父元件。
49 virtual void ComputeRequirement();
50 Requirement requirement() { return requirement_; }
51
52 // 步驟 2:指派此元素最終的尺寸。
53 // 從父元件傳遞到子元件。
54 virtual void SetBox(Box box);
55
56 // 步驟 3:(選用)選取
57 // 從父元件傳遞到子元件。
58 virtual void Select(Selection& selection);
59
60 // 步驟 4:繪製此元素。
61 virtual void Render(Screen& screen);
62
63 virtual std::string GetSelectedContent(Selection& selection);
64
65 // 對某些元素而言,布局可能無法在單一次迭代中完成。這
66 // 讓它們可以要求額外的迭代。此訊號必須
67 // 至少向子元件轉發一次。
68 struct Status {
69 int iteration = 0;
70 bool need_iteration = false;
71 };
72 virtual void Check(Status* status);
73
74 // ABI 保留欄位:
75 virtual void Reserved1();
76 virtual void Reserved2();
77 virtual void Reserved3();
78 virtual void Reserved4();
79 virtual void Reserved5();
80 virtual void Reserved6();
81 virtual void Reserved7();
82 virtual void Reserved8();
83
84 friend FTXUI_EXPORT(DOM) void Render(Screen& screen, Node* node, Selection& selection);
85
86 protected:
87 Elements children_;
88 Requirement requirement_;
89 Box box_;
90};
91
92FTXUI_EXPORT(DOM) void Render(Screen& screen, const Element& element);
93FTXUI_EXPORT(DOM) void Render(Screen& screen, Node* node);
94FTXUI_EXPORT(DOM)
95void Render(Screen& screen, Node* node, Selection& selection);
96FTXUI_EXPORT(DOM)
97std::string GetNodeSelectedContent(Screen& screen,
98 Node* node,
99 Selection& selection);
100
101} // namespace ftxui
102
103#endif // FTXUI_DOM_NODE_HPP
#define FTXUI_EXPORT(component)
Definition export.hpp:23
FTXUI ftxui:: 命名空間
Definition animation.hpp:11
std::shared_ptr< Node > Element
Definition elements.hpp:25
std::vector< Element > Elements
Definition elements.hpp:26