FTXUI
6.1.9
C++ functional terminal UI.
Toggle main menu visibility
Loading...
Searching...
No Matches
component_base.hpp
Go to the documentation of this file.
1
// Copyright 2020 Arthur Sonzogni. All rights reserved.
2
// Use of this source code is governed by the MIT license that can be found in
3
// the LICENSE file.
4
#ifndef FTXUI_COMPONENT_BASE_HPP
5
#define FTXUI_COMPONENT_BASE_HPP
6
7
#include <memory>
// for unique_ptr
8
#include <vector>
// for vector
9
10
#include "
ftxui/component/captured_mouse.hpp
"
// for CaptureMouse
11
#include "
ftxui/dom/elements.hpp
"
// for Element
12
13
namespace
ftxui
{
14
15
class
Delegate;
16
class
Focus;
17
struct
Event
;
18
19
namespace
animation
{
20
class
Params
;
21
}
// namespace animation
22
23
class
ComponentBase
;
24
using
Component
= std::shared_ptr<ComponentBase>;
25
using
Components
= std::vector<Component>;
26
27
/// @brief It implement rendering itself as ftxui::Element. It implement
28
/// keyboard navigation by responding to ftxui::Event.
29
/// @ingroup component
30
class
ComponentBase
{
31
public
:
32
explicit
ComponentBase
(
Components
children)
33
: children_(std::move(children)) {}
34
virtual
~ComponentBase
();
35
ComponentBase
() =
default
;
36
37
// A component is not copyable/movable.
38
ComponentBase
(
const
ComponentBase
&) =
delete
;
39
ComponentBase
(
ComponentBase
&&) =
delete
;
40
ComponentBase
&
operator=
(
const
ComponentBase
&) =
delete
;
41
ComponentBase
&
operator=
(
ComponentBase
&&) =
delete
;
42
43
// Component hierarchy:
44
ComponentBase
* Parent()
const
;
45
Component
& ChildAt(
size_t
i);
46
size_t
ChildCount()
const
;
47
int
Index()
const
;
48
void
Add(
Component
children);
49
void
Detach();
50
void
DetachAllChildren();
51
52
// Renders the component.
53
Element
Render
();
54
55
// Override this function modify how `Render` works.
56
virtual
Element
OnRender
();
57
58
// Handles an event.
59
// By default, reduce on children with a lazy OR.
60
//
61
// Returns whether the event was handled or not.
62
virtual
bool
OnEvent
(
Event
);
63
64
// Handle an animation step.
65
virtual
void
OnAnimation(
animation::Params
& params);
66
67
// Focus management ----------------------------------------------------------
68
//
69
// If this component contains children, this indicates which one is active,
70
// nullptr if none is active.
71
//
72
// We say an element has the focus if the chain of ActiveChild() from the
73
// root component contains this object.
74
virtual
Component
ActiveChild
();
75
76
// Return true when the component contains focusable elements.
77
// The non focusable Component will be skipped when navigating using the
78
// keyboard.
79
virtual
bool
Focusable()
const
;
80
81
// Whether this is the active child of its parent.
82
bool
Active()
const
;
83
// Whether all the ancestors are active.
84
bool
Focused()
const
;
85
86
// Make the |child| to be the "active" one.
87
virtual
void
SetActiveChild
(
ComponentBase
* child);
88
void
SetActiveChild
(
Component
child);
89
90
// Configure all the ancestors to give focus to this component.
91
void
TakeFocus();
92
93
protected
:
94
CapturedMouse
CaptureMouse(
const
Event
& event);
95
96
Components
children_;
97
98
private
:
99
ComponentBase
* parent_ =
nullptr
;
100
bool
in_render =
false
;
101
};
102
103
}
// namespace ftxui
104
105
#endif
/* end of include guard: FTXUI_COMPONENT_BASE_HPP */
captured_mouse.hpp
ftxui::ComponentBase
It implement rendering itself as ftxui::Element. It implement keyboard navigation by responding to ft...
Definition
component_base.hpp:30
ftxui::ComponentBase::ActiveChild
virtual Component ActiveChild()
Return the currently Active child.
Definition
component.cpp:183
ftxui::ComponentBase::SetActiveChild
virtual void SetActiveChild(ComponentBase *child)
Make the |child| to be the "active" one.
Definition
component.cpp:227
ftxui::ComponentBase::ComponentBase
ComponentBase(ComponentBase &&)=delete
ftxui::ComponentBase::operator=
ComponentBase & operator=(ComponentBase &&)=delete
ftxui::ComponentBase::OnRender
virtual Element OnRender()
Draw the component. Build a ftxui::Element to be drawn on the ftxi::Screen representing this ftxui::C...
Definition
component.cpp:147
ftxui::ComponentBase::OnEvent
virtual bool OnEvent(Event)
Called in response to an event.
Definition
component.cpp:161
ftxui::ComponentBase::ComponentBase
ComponentBase(const ComponentBase &)=delete
ftxui::ComponentBase::operator=
ComponentBase & operator=(const ComponentBase &)=delete
ftxui::ComponentBase::ComponentBase
ComponentBase()=default
ftxui::ComponentBase::ComponentBase
ComponentBase(Components children)
Definition
component_base.hpp:32
ftxui::animation::Params
Definition
animation.hpp:23
elements.hpp
ftxui::animation
Definition
animation.hpp:10
ftxui
Definition
animation.hpp:10
ftxui::CapturedMouse
std::unique_ptr< CapturedMouseInterface > CapturedMouse
Definition
captured_mouse.hpp:19
ftxui::Element
std::shared_ptr< Node > Element
Definition
elements.hpp:22
ftxui::Components
std::vector< Component > Components
Definition
component_base.hpp:25
ftxui::Render
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Definition
node.cpp:88
ftxui::Component
std::shared_ptr< ComponentBase > Component
Definition
component_base.hpp:24
ftxui::Event
Represent an event. It can be key press event, a terminal resize, or more ...
Definition
event.hpp:27