FTXUI 7.0.3
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// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#ifndef FTXUI_COMPONENT_BASE_HPP
5#define FTXUI_COMPONENT_BASE_HPP
6
7#include <memory> // for unique_ptr
8#include <vector> // for vector
9
10#include "ftxui/component/captured_mouse.hpp" // for CaptureMouse
11#include "ftxui/dom/elements.hpp" // for Element
12#include "ftxui/util/export.hpp"
13
14namespace ftxui {
15
16class Delegate;
17class Focus;
18struct Event;
19
20namespace animation {
21class Params;
22} // namespace animation
23
24class ComponentBase;
25using Component = std::shared_ptr<ComponentBase>;
26using Components = std::vector<Component>;
27
28/// @brief ftxui::Elementとして自身のレンダリングを実装します。ftxui::Eventに応答してキーボードナビゲーションを実装します。
29/// @ingroup component
30class FTXUI_EXPORT(COMPONENT) ComponentBase {
31 public:
32 explicit ComponentBase(Components children);
33 virtual ~ComponentBase();
34 ComponentBase();
35
36 // コンポーネントはコピー/ムーブ不可です。
37 ComponentBase(const ComponentBase&) = delete;
38 ComponentBase(ComponentBase&&) = delete;
39 ComponentBase& operator=(const ComponentBase&) = delete;
40 ComponentBase& operator=(ComponentBase&&) = delete;
41
42 // コンポーネントの階層:
43 ComponentBase* Parent() const;
44 Component& ChildAt(size_t i);
45 size_t ChildCount() const;
46 int Index() const;
47 void Add(Component children);
48 void Detach();
49 void DetachAllChildren();
50
51 // コンポーネントを描画します。
52 Element Render();
53
54 // `Render`の動作を変更するためにこの関数をオーバーライドします。
55 virtual Element OnRender();
56
57 // イベントを処理します。
58 // デフォルトでは、子に対して遅延ORで削減します。
59 //
60 // イベントが処理されたかどうかを返します。
61 virtual bool OnEvent(Event);
62
63 // アニメーションステップを処理します。
64 virtual void OnAnimation(animation::Params& params);
65
66 // フォーカス管理 ----------------------------------------------------------
67 //
68 // このコンポーネントに子要素が含まれている場合、これはどれがアクティブであるかを示します。
69 // アクティブな子要素がない場合はnullptrです。
70 //
71 // ルートコンポーネントからのActiveChild()のチェーンにこのオブジェクトが含まれている場合、要素がフォーカスを持っていると言います。
72 virtual Component ActiveChild();
73
74 // コンポーネントがフォーカス可能な要素を含んでいる場合にtrueを返します。
75 // フォーカス不可能なコンポーネントは、キーボードを使用してナビゲートする際にスキップされます。
76 virtual bool Focusable() const;
77
78 // これが親のアクティブな子であるかどうか。
79 bool Active() const;
80 // すべての祖先がアクティブかどうか。
81 bool Focused() const;
82
83 // |child|を「アクティブ」にします。
84 virtual void SetActiveChild(ComponentBase* child);
85 void SetActiveChild(Component child);
86
87 // すべての祖先を構成して、このコンポーネントにフォーカスを与えます。
88 void TakeFocus();
89
90 // ABI予約:
91 virtual void Reserved1();
92 virtual void Reserved2();
93 virtual void Reserved3();
94 virtual void Reserved4();
95 virtual void Reserved5();
96 virtual void Reserved6();
97 virtual void Reserved7();
98 virtual void Reserved8();
99
100 protected:
101 CapturedMouse CaptureMouse(const Event& event);
102
103 Components& children();
104 const Components& children() const;
105
106 private:
107 struct Impl;
108 std::unique_ptr<Impl> impl_;
109};
110
111} // namespace ftxui
112
113#endif /* end of include guard: FTXUI_COMPONENT_BASE_HPP */
FTXUI ftxui::animation::名前空間
FTXUI ftxui::名前空間
Definition animation.hpp:11
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< Node > Element
Definition elements.hpp:25
std::vector< Component > Components
std::shared_ptr< ComponentBase > Component
Definition app.hpp:23