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 NodeはDOMツリー内のすべての要素の基底クラスです。
25///
26/// DOM(Document Object Model)内の単一のノードを表し、レイアウトとレンダリングのための
27/// 基本的な構造を提供します。
28/// レイアウト要件の計算、ボックスの寸法の設定、コンテンツの選択、画面へのレンダリング、
29/// およびレイアウトステータスの確認のためのメソッドが含まれています。
30/// 通常、子要素もNodeのインスタンスです。
31///
32/// ユーザーはカスタム要素を作成するためにこのクラスから派生することが期待されます。
33///
34/// 組み込み要素のリストは `elements.hpp` ファイルにあります。
35///
36/// @ingroup dom
37class FTXUI_EXPORT(DOM) Node {
38 public:
39 Node();
40 explicit Node(Elements children);
41 Node(const Node&) = delete;
42 Node(const Node&&) = delete;
43 Node& operator=(const Node&) = delete;
44 Node& operator=(const Node&&) = delete;
45
46 virtual ~Node();
47
48 // ステップ1: レイアウト要件を計算します。この要素がどのような
49 // 次元にしたいかを親に伝えます。
50 // 子から親へ伝播されます。
51 virtual void ComputeRequirement();
52 Requirement requirement() { return requirement_; }
53
54 // ステップ2: この要素に最終的な次元を割り当てます。
55 // 親から子へ伝播されます。
56 virtual void SetBox(Box box);
57
58 // ステップ3: (オプション) 選択
59 // 親から子へ伝播されます。
60 virtual void Select(Selection& selection);
61
62 // ステップ4: この要素を描画します。
63 virtual void Render(Screen& screen);
64
65 virtual std::string GetSelectedContent(Selection& selection);
66
67 // レイアウトは、一部の要素では1回のイテレーションで解決されない
68 // ことがあります。これにより、追加のイテレーションを要求できます。
69 // このシグナルは少なくとも1回は子に転送される必要があります。
70 struct Status {
71 int iteration = 0;
72 bool need_iteration = false;
73 };
74 virtual void Check(Status* status);
75
76 // ABI予約:
77 virtual void Reserved1();
78 virtual void Reserved2();
79 virtual void Reserved3();
80 virtual void Reserved4();
81 virtual void Reserved5();
82 virtual void Reserved6();
83 virtual void Reserved7();
84 virtual void Reserved8();
85
86 friend FTXUI_EXPORT(DOM) void Render(Screen& screen, Node* node, Selection& selection);
87
88 protected:
89 Elements children_;
90 Requirement requirement_;
91 Box box_;
92};
93
94FTXUI_EXPORT(DOM) void Render(Screen& screen, const Element& element);
95FTXUI_EXPORT(DOM) void Render(Screen& screen, Node* node);
96FTXUI_EXPORT(DOM)
97void Render(Screen& screen, Node* node, Selection& selection);
98FTXUI_EXPORT(DOM)
99std::string GetNodeSelectedContent(Screen& screen,
100 Node* node,
101 Selection& selection);
102
103} // namespace ftxui
104
105#endif // FTXUI_DOM_NODE_HPP
#define FTXUI_EXPORT(component)
Definition export.hpp:25
FTXUI ftxui::名前空間
Definition animation.hpp:11
std::shared_ptr< Node > Element
Definition elements.hpp:25
std::vector< Element > Elements
Definition elements.hpp:26