18class ContainerBase :
public ComponentBase {
28 bool OnEvent(Event
event)
override {
29 if (
event.is_mouse()) {
30 return OnMouseEvent(
event);
37 if (ActiveChild() && ActiveChild()->OnEvent(
event)) {
41 return EventHandler(
event);
53 for (
size_t i = 0; i <
children_.size(); ++i) {
55 *selector_ =
static_cast<int>(i);
63 virtual bool EventHandler(Event ) {
return false; }
65 virtual bool OnMouseEvent(Event
event) {
70 int* selector_ =
nullptr;
72 void MoveSelector(
int dir) {
82 void MoveSelectorWrap(
int dir) {
97class VerticalContainer :
public ContainerBase {
99 using ContainerBase::ContainerBase;
113 bool EventHandler(Event
event)
override {
122 for (
int i = 0; i < box_.y_max - box_.y_min; ++i) {
127 for (
int i = 0; i < box_.y_max - box_.y_min; ++i) {
132 for (
size_t i = 0; i <
children_.size(); ++i) {
137 for (
size_t i = 0; i <
children_.size(); ++i) {
142 MoveSelectorWrap(+1);
145 MoveSelectorWrap(-1);
148 *selector_ = std::max(0, std::min(
int(
children_.size()) - 1, *selector_));
152 bool OnMouseEvent(Event
event)
override {
153 if (ContainerBase::OnMouseEvent(
event)) {
162 if (!box_.Contain(
event.mouse().x,
event.mouse().y)) {
172 *selector_ = std::max(0, std::min(
int(
children_.size()) - 1, *selector_));
180class HorizontalContainer :
public ContainerBase {
182 using ContainerBase::ContainerBase;
191 return text(
"Empty container");
196 bool EventHandler(Event
event)
override {
205 MoveSelectorWrap(+1);
208 MoveSelectorWrap(-1);
211 *selector_ = std::max(0, std::min(
int(
children_.size()) - 1, *selector_));
216class TabContainer :
public ContainerBase {
218 using ContainerBase::ContainerBase;
225 return text(
"Empty container");
228 bool Focusable()
const override {
235 bool OnMouseEvent(Event
event)
override {
236 return ActiveChild() && ActiveChild()->OnEvent(
event);
240class StackedContainer :
public ContainerBase {
258 if (
child->Focusable()) {
288 bool OnEvent(Event
event)
final {
382 return std::make_shared<HorizontalContainer>(std::move(
children),
selector);
432 return std::make_shared<StackedContainer>(std::move(
children));
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....
void Add(Component children)
Add a child. @param child The child to be attached.
void SetActiveChild(Component child)
Make the |child| to be the "active" one.
virtual bool OnEvent(Event)
Called in response to an event.
Component Horizontal(Components children)
A list of components, drawn one by one horizontally and navigated horizontally using left/right arrow...
Component Vertical(Components children)
A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or...
Component Stacked(Components children)
A list of components to be stacked on top of each other. Events are propagated to the first component...
Component Tab(Components children, int *selector)
A list of components, where only one is drawn and interacted with at a time. The |selector| gives the...
std::shared_ptr< Node > Element
std::shared_ptr< T > Make(Args &&... args)
std::shared_ptr< ComponentBase > Component
std::vector< Component > Components
Element hbox(Elements)
A container displaying elements horizontally one by one.
Element text(std::wstring text)
Display a piece of unicode text.
std::vector< Element > Elements
Element dbox(Elements)
Stack several element on top of each other.
Decorator reflect(Box &box)
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
Element vbox(Elements)
A container displaying elements vertically one by one.
static const Event TabReverse
static const Event PageUp
static const Event ArrowUp
static const Event ArrowDown
static const Event PageDown
static const Event ArrowLeft
static const Event ArrowRight