FTXUI  0.11.1
C++ functional terminal UI.
Go to the documentation of this file.
4 #include <memory> // for unique_ptr
5 #include <vector> // for vector
7 #include "ftxui/component/captured_mouse.hpp" // for CaptureMouse
8 #include "ftxui/dom/elements.hpp" // for Element
10 namespace ftxui {
12 class Delegate;
13 class Focus;
14 struct Event;
16 class ComponentBase;
17 using Component = std::shared_ptr<ComponentBase>;
18 using Components = std::vector<Component>;
20 /// @brief It implement rendering itself as ftxui::Element. It implement
21 /// keyboard navigation by responding to ftxui::Event.
22 /// @ingroup component
24  public:
25  // virtual Destructor.
26  virtual ~ComponentBase();
28  // Component hierarchy:
29  ComponentBase* Parent() const;
30  Component& ChildAt(size_t i);
31  size_t ChildCount() const;
32  void Add(Component children);
33  void Detach();
34  void DetachAllChildren();
36  // Renders the component.
37  virtual Element Render();
39  // Handles an event.
40  // By default, reduce on children with a lazy OR.
41  //
42  // Returns whether the event was handled or not.
43  virtual bool OnEvent(Event);
45  // Focus management ----------------------------------------------------------
46  //
47  // If this component contains children, this indicates which one is active,
48  // nullptr if none is active.
49  //
50  // We say an element has the focus if the chain of ActiveChild() from the
51  // root component contains this object.
52  virtual Component ActiveChild();
54  // Return true when the component contains focusable elements.
55  // The non focusable Component will be skipped when navigating using the
56  // keyboard.
57  virtual bool Focusable() const;
59  // Whether this is the active child of its parent.
60  bool Active() const;
61  // Whether all the ancestors are active.
62  bool Focused() const;
64  // Make the |child| to be the "active" one.
65  virtual void SetActiveChild(ComponentBase* child);
66  void SetActiveChild(Component child);
68  // Configure all the ancestors to give focus to this component.
69  void TakeFocus();
71  protected:
72  CapturedMouse CaptureMouse(const Event& event);
76  private:
77  ComponentBase* parent_ = nullptr;
78 };
80 } // namespace ftxui
82 #endif /* end of include guard: FTXUI_COMPONENT_BASE_HPP */
84 // Copyright 2020 Arthur Sonzogni. All rights reserved.
85 // Use of this source code is governed by the MIT license that can be found in
86 // the LICENSE file.
It implement rendering itself as ftxui::Element. It implement keyboard navigation by responding to ft...
virtual bool Focusable() const
Return true when the component contains focusable elements. The non focusable Components will be skip...
Definition: component.cpp:114
bool Focused() const
Returns if the elements if focused by the user. True when the ComponentBase is focused by the user....
Definition: component.cpp:132
CapturedMouse CaptureMouse(const Event &event)
Take the CapturedMouse if available. There is only one component of them. It represents a component t...
Definition: component.cpp:166
void Add(Component children)
Add a child. @param child The child to be attached.
Definition: component.cpp:49
virtual Element Render()
Draw the component. Build a ftxui::Element to be drawn on the ftxi::Screen representing this ftxui::C...
Definition: component.cpp:82
void TakeFocus()
Configure all the ancestors to give focus to this component.
Definition: component.cpp:154
bool Active() const
Returns if the element if the currently active child of its parent.
Definition: component.cpp:124
virtual Component ActiveChild()
Return the currently Active child.
Definition: component.cpp:106
void DetachAllChildren()
Remove all children.
Definition: component.cpp:73
virtual void SetActiveChild(ComponentBase *child)
Make the |child| to be the "active" one.
Definition: component.cpp:143
size_t ChildCount() const
Returns the number of children.
Definition: component.cpp:42
ComponentBase * Parent() const
Return the parent ComponentBase, or nul if any.
Definition: component.cpp:29
virtual bool OnEvent(Event)
Called in response to an event.
Definition: component.cpp:95
void Detach()
Detach this child from its parent.
Definition: component.cpp:59
Component & ChildAt(size_t i)
Access the child at index i.
Definition: component.cpp:35
virtual ~ComponentBase()
Definition: component.cpp:21
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< Node > Element
Definition: elements.hpp:16
std::shared_ptr< ComponentBase > Component
std::vector< Component > Components
Represent an event. It can be key press event, a terminal resize, or more ...
Definition: event.hpp:25