FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
component_base.hpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// このソースコードの使用は、LICENSEファイルにあるMITライセンスによって管理されています。
3#ifndef FTXUI_COMPONENT_BASE_HPP
4#define FTXUI_COMPONENT_BASE_HPP
5
6#include <memory> // for unique_ptr
7#include <vector> // for vector
8
9#include "ftxui/component/captured_mouse.hpp" // for CaptureMouse
10#include "ftxui/dom/elements.hpp" // for Element
11
12namespace ftxui {
13
14class Delegate;
15class Focus;
16struct Event;
17
18namespace animation {
19class Params;
20} // namespace animation
21
22class ComponentBase;
23using Component = std::shared_ptr<ComponentBase>;
24using Components = std::vector<Component>;
25
26/// @brief ftxui::Elementとして自身のレンダリングを実装します。ftxui::Eventに応答してキーボードナビゲーションを実装します。
27/// @ingroup component
29 public:
30 explicit ComponentBase(Components children)
31 : children_(std::move(children)) {}
32 virtual ~ComponentBase();
33 ComponentBase() = default;
34
35 // コンポーネントはコピー/ムーブできません。
36 ComponentBase(const ComponentBase&) = delete;
40
41 // コンポーネント階層:
42 ComponentBase* Parent() const;
43 Component& ChildAt(size_t i);
44 size_t ChildCount() const;
45 int Index() const;
46 void Add(Component children);
47 void Detach();
48 void DetachAllChildren();
49
50 // コンポーネントをレンダリングします。
52
53 // `Render`の動作を変更するためにこの関数をオーバーライドします。
54 virtual Element OnRender();
55
56 // イベントを処理します。
57 // デフォルトでは、遅延ORで子要素を減らします。
58 //
59 // イベントが処理されたかどうかを返します。
60 virtual bool OnEvent(Event);
61
62 // アニメーションステップを処理します。
63 virtual void OnAnimation(animation::Params& params);
64
65 // フォーカス管理 ----------------------------------------------------------
66 //
67 // このコンポーネントに子要素が含まれている場合、これはどれがアクティブであるかを示します。
68 // アクティブな子要素がない場合はnullptrです。
69 //
70 // ルートコンポーネントからのActiveChild()のチェーンにこのオブジェクトが含まれている場合、要素がフォーカスを持っていると言います。
71 virtual Component ActiveChild();
72
73 // コンポーネントがフォーカス可能な要素を含んでいる場合にtrueを返します。
74 // フォーカス不可能なコンポーネントは、キーボードを使用してナビゲートする際にスキップされます。
75 virtual bool Focusable() const;
76
77 // これがその親のアクティブな子であるかどうか。
78 bool Active() const;
79 // すべての祖先がアクティブであるかどうか。
80 bool Focused() const;
81
82 // |child|を「アクティブ」にします。
83 virtual void SetActiveChild(ComponentBase* child);
84 void SetActiveChild(Component child);
85
86 // すべての祖先を設定して、このコンポーネントにフォーカスを与えます。
87 void TakeFocus();
88
89 protected:
90 CapturedMouse CaptureMouse(const Event& event);
91
93
94 private:
95 ComponentBase* parent_ = nullptr;
96 bool in_render = false;
97};
98
99} // namespace ftxui
100
101#endif /* end of include guard: FTXUI_COMPONENT_BASE_HPP */
virtual bool Focusable() const
コンポーネントがフォーカス可能な要素を含んでいる場合にtrueを返します。 フォーカス不可能なコンポーネントは、キーボードでナビゲートする際にスキップされます。
bool Focused() const
要素がユーザーによってフォーカスされているかどうかを返します。 ComponentBaseがユーザーによってフォーカスされている場合にtrueを返します。要素は、そのすべての子孫が親のActiveChi...
CapturedMouse CaptureMouse(const Event &event)
利用可能であればCapturedMouseを取得します。コンポーネントは1つしかありません。これは他のコンポーネントよりも優先されるコンポーネントを表します。
void Add(Component children)
子を追加します。 @param child 添付する子。
Definition component.cpp:69
Element Render()
コンポーネントを描画します。 このftxui::ComponentBaseを表すftxui::Screen上に描画されるftxui::Elementを構築します。レンダリングを変更するにはOnRende...
void TakeFocus()
このコンポーネントにフォーカスを与えるように、すべての祖先を設定します。
bool Active() const
要素が現在親のアクティブな子であるかどうかを返します。
virtual Component ActiveChild()
現在アクティブな子を返します。
void DetachAllChildren()
すべての子を削除します。
Definition component.cpp:93
int Index() const
親におけるコンポーネントのインデックスを返します。親がない場合は-1を返します。
Definition component.cpp:53
size_t ChildCount() const
子の数を返します。
Definition component.cpp:48
ComponentBase(ComponentBase &&)=delete
ComponentBase & operator=(ComponentBase &&)=delete
ComponentBase * Parent() const
親のComponentBaseを返します。存在しない場合はnullを返します。
Definition component.cpp:37
virtual void SetActiveChild(ComponentBase *child)
virtual Element OnRender()
コンポーネントを描画します。 このftxui::ComponentBaseを表すftxui::Screen上に描画されるftxui::Elementを構築します。この関数はオーバーライドされることを意図...
virtual bool OnEvent(Event)
イベントに応じて呼び出されます。
void Detach()
この子を親からデタッチします。
Definition component.cpp:78
ComponentBase(const ComponentBase &)=delete
ComponentBase & operator=(const ComponentBase &)=delete
Component & ChildAt(size_t i)
インデックスiの子にアクセスします。
Definition component.cpp:42
ComponentBase(Components children)
virtual ~ComponentBase()
Definition component.cpp:30
virtual void OnAnimation(animation::Params &params)
アニメーションイベントに応じて呼び出されます。
ftxui::Elementとして自身のレンダリングを実装します。ftxui::Eventに応答してキーボードナビゲーションを実装します。
イベントを表します。キープレスイベント、ターミナルのリサイズなど、さまざまなイベントがあります。
Definition event.hpp:28
FTXUI ftxui::animation::名前空間
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< Node > Element
Definition elements.hpp:21
std::vector< Component > Components
std::shared_ptr< ComponentBase > Component