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;
117 bool focused_ =
false;
119 Wrapper(
Element child,
bool active,
bool focused)
120 :
Node({std::move(child)}), active_(active), focused_(focused) {}
122 void SetBox(
Box box)
override {
124 children_[0]->SetBox(box);
127 void ComputeRequirement()
override {
128 Node::ComputeRequirement();
129 requirement_.focused.component_active = active_;
130 requirement_.focused.component_focused = focused_;
134 return std::make_shared<Wrapper>(std::move(element),
Active(),
Focused());
145 return text(
"Not implemented component");
155 if (child->OnEvent(event)) {
167 child->OnAnimation(params);
175 if (child->Focusable()) {
187 if (child->Focusable()) {
196 return parent_ ==
nullptr || parent_->
ActiveChild().get() ==
this;
204 const auto* current =
this;
205 while (current && current->Active()) {
206 current = current->parent_;
225 parent->SetActiveChild(child);
235 return event.screen_->CaptureMouse();
237 return std::make_unique<CaptureMouseImpl>();
virtual bool Focusable() const
Return true when the component contains focusable elements. The non focusable Components will be skip...
bool Focused() const
Returns if the elements if focused by the user. True when the ComponentBase is focused by the user....
CapturedMouse CaptureMouse(const Event &event)
Take the CapturedMouse if available. There is only one component of them. It represents a component t...
void Add(Component children)
Add a child. @param child The child to be attached.
Element Render()
Draw the component. Build a ftxui::Element to be drawn on the ftxui::Screen representing this ftxui::...
void TakeFocus()
Configure all the ancestors to give focus to this component.
bool Active() const
Returns if the element if the currently active child of its parent.
virtual Component ActiveChild()
Return the currently Active child.
void DetachAllChildren()
Remove all children.
virtual void SetActiveChild(ComponentBase *child)
Make the |child| to be the "active" one.
int Index() const
Return index of the component in its parent. -1 if no parent.
size_t ChildCount() const
Returns the number of children.
ComponentBase * Parent() const
Return the parent ComponentBase, or nul if any.
virtual Element OnRender()
Draw the component. Build a ftxui::Element to be drawn on the ftxi::Screen representing this ftxui::C...
virtual bool OnEvent(Event)
Called in response to an event.
void Detach()
Detach this child from its parent.
Component & ChildAt(size_t i)
Access the child at index i.
virtual void OnAnimation(animation::Params ¶ms)
Called in response to an animation event.
It implement rendering itself as ftxui::Element. It implement keyboard navigation by responding to ft...
Represent an event. It can be key press event, a terminal resize, or more ...
Node is the base class for all elements in the DOM tree.
Element text(std::wstring_view text)
Display a piece of unicode text.
Box is a structure that represents a rectangular area in a 2D space.
The FTXUI ftxui:: namespace.
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< Node > Element
std::shared_ptr< ComponentBase > Component