27class CaptureMouseImpl :
public CapturedMouseInterface {};
54 if (parent_ ==
nullptr) {
59 if (child.get() ==
this) {
71 child->parent_ =
this;
79 if (parent_ ==
nullptr) {
82 auto it = std::find_if(std::begin(parent_->
children_),
85 return this == that.get();
112 class Wrapper :
public Node {
114 bool active_ =
false;
116 Wrapper(
Element child,
bool active)
117 :
Node({std::move(child)}), active_(active) {}
119 void SetBox(
Box box)
override {
121 children_[0]->SetBox(box);
124 void ComputeRequirement()
override {
125 Node::ComputeRequirement();
126 requirement_.focused.component_active = active_;
130 return std::make_shared<Wrapper>(std::move(element),
Active());
140 return text(
"Not implemented component");
149 if (child->OnEvent(event)) {
161 child->OnAnimation(params);
169 if (child->Focusable()) {
180 if (child->Focusable()) {
189 return parent_ ==
nullptr || parent_->
ActiveChild().get() ==
this;
195 const auto* current =
this;
196 while (current && current->Active()) {
197 current = current->parent_;
216 parent->SetActiveChild(child);
225 return event.screen_->CaptureMouse();
227 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,如果沒有則返回空。
virtual Element OnRender()
繪製組件。 建構一個 ftxui::Element,用於在表示此 ftxui::ComponentBase 的 ftxi::Screen 上繪製。此函數旨在被覆寫。
virtual bool OnEvent(Event)
回應事件時呼叫。
void Detach()
將此子項從其父項中分離。
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:: 命名空間
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< Node > Element
std::shared_ptr< ComponentBase > Component