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 /* 包含防護結束: 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