28class CaptureMouseImpl :
public CapturedMouseInterface {};
55 if (parent_ ==
nullptr) {
60 if (child.get() ==
this) {
72 child->parent_ =
this;
80 if (parent_ ==
nullptr) {
83 auto it = std::find_if(std::begin(parent_->
children_),
86 return this == that.get();
114 class Wrapper :
public Node {
116 bool active_ =
false;
118 Wrapper(
Element child,
bool active)
119 :
Node({std::move(child)}), active_(active) {}
121 void SetBox(
Box box)
override {
123 children_[0]->SetBox(box);
126 void ComputeRequirement()
override {
127 Node::ComputeRequirement();
128 requirement_.focused.component_active = active_;
132 return std::make_shared<Wrapper>(std::move(element),
Active());
143 return text(
"Not implemented component");
153 if (child->OnEvent(event)) {
165 child->OnAnimation(params);
173 if (child->Focusable()) {
184 if (child->Focusable()) {
193 return parent_ ==
nullptr || parent_->
ActiveChild().get() ==
this;
199 const auto* current =
this;
200 while (current && current->Active()) {
201 current = current->parent_;
220 parent->SetActiveChild(child);
230 return event.screen_->CaptureMouse();
232 return std::make_unique<CaptureMouseImpl>();
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
返回该元素是否是其父级的当前活动子项。
ScreenInteractive * screen_
virtual Component ActiveChild()
返回当前活动的子项。
void DetachAllChildren()
移除所有子项。
virtual void SetActiveChild(ComponentBase *child)
使 |child| 成为“活动”子项。
int Index() const
返回组件在其父级中的索引。如果没有父级,则返回 -1。
size_t ChildCount() const
返回子项的数量。
ComponentBase * Parent() const
返回父 ComponentBase,如果没有则返回 null。
virtual Element OnRender()
绘制组件。 构建一个 ftxui::Element,用于在表示此 ftxui::ComponentBase 的 ftxui::Screen 上绘制。 此函数旨在被覆盖。
virtual bool OnEvent(Event)
响应事件时调用。
Component & ChildAt(size_t i)
访问索引 i 处的子项。
virtual void OnAnimation(animation::Params ¶ms)
响应动画事件时调用。
它将自身实现为 ftxui::Element。它通过响应 ftxui::Event 来实现键盘导航。
代表一个事件。它可以是按键事件、终端大小调整等等...
Element text(std::wstring text)
显示一段Unicode文本。
FTXUI ftxui::animation:: 命名空间
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< Node > Element
std::shared_ptr< ComponentBase > Component