FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
component_base.hpp
浏览该文件的文档.
1// Copyright 2020 Arthur Sonzogni. 保留所有权利。
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 // Component hierarchy:
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。当一个元素及其所有祖先都是其父级的 ActiveChild() 并且它是 Focusable() 时,该元素被聚焦。
CapturedMouse CaptureMouse(const Event &event)
如果可用,则捕获 CapturedMouse。只有一个组件可以捕获它。 它表示一个优先于其他组件的组件。
void Add(Component children)
添加一个子项。 @param child 要附加的子项。
Element Render()
绘制组件。 构建一个 ftxui::Element,用于在表示此 ftxui::ComponentBase 的 ftxui::Screen 上绘制。 请覆盖 OnRender() 以修改渲染。
void TakeFocus()
配置所有祖先以将焦点赋予此组件。
bool Active() const
返回该元素是否是其父级的当前活动子项。
virtual Component ActiveChild()
返回当前活动的子项。
void DetachAllChildren()
移除所有子项。
virtual void SetActiveChild(ComponentBase *child)
使 |child| 成为“活动”子项。
int Index() const
返回组件在其父级中的索引。如果没有父级,则返回 -1。
size_t ChildCount() const
返回子项的数量。
ComponentBase(ComponentBase &&)=delete
ComponentBase & operator=(ComponentBase &&)=delete
ComponentBase * Parent() const
返回父 ComponentBase,如果没有则返回 null。
virtual Element OnRender()
绘制组件。 构建一个 ftxui::Element,用于在表示此 ftxui::ComponentBase 的 ftxui::Screen 上绘制。 此函数旨在被覆盖。
virtual bool OnEvent(Event)
响应事件时调用。
void Detach()
将此子项从其父级分离。
ComponentBase(const ComponentBase &)=delete
ComponentBase & operator=(const ComponentBase &)=delete
Component & ChildAt(size_t i)
访问索引 i 处的子项。
ComponentBase(Components children)
virtual void OnAnimation(animation::Params &params)
响应动画事件时调用。
它将自身实现为 ftxui::Element。它通过响应 ftxui::Event 来实现键盘导航。
代表一个事件。它可以是按键事件、终端大小调整等等...
FTXUI ftxui::animation:: 命名空间
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< Node > Element
std::vector< Component > Components
std::shared_ptr< ComponentBase > Component