FTXUI 7.0.3
C++ functional terminal UI.
Loading...
Searching...
No Matches
component.hpp
Go to the documentation of this file.
1// Copyright 2021 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_HPP
5#define FTXUI_COMPONENT_HPP
6
7#include <functional> // for function
8#include <memory> // for make_shared, shared_ptr
9#include <utility> // for forward
10
12#include "ftxui/component/component_base.hpp" // for Component, Components
13#include "ftxui/component/component_options.hpp" // for ButtonOption, CheckboxOption, MenuOption
14#include "ftxui/dom/elements.hpp" // for Element
15#include "ftxui/util/export.hpp"
16#include "ftxui/util/ref.hpp" // for ConstRef, Ref, ConstStringRef, ConstStringListRef, StringRef
17
18namespace ftxui {
19struct ButtonOption;
20struct CheckboxOption;
21struct Event;
22struct InputOption;
23struct MenuOption;
24struct RadioboxOption;
25struct MenuEntryOption;
26
27template <class T, class... Args>
28std::shared_ptr<T> Make(Args&&... args) {
29 return std::make_shared<T>(std::forward<Args>(args)...);
30}
31
32// Operador de tubería para decorar componentes.
33using ComponentDecorator = std::function<Component(Component)>;
34using ElementDecorator = std::function<Element(Element)>;
35FTXUI_EXPORT(COMPONENT)
37FTXUI_EXPORT(COMPONENT)
38Component operator|(Component component, ElementDecorator decorator);
39FTXUI_EXPORT(COMPONENT)
40Component& operator|=(Component& component, ComponentDecorator decorator);
41FTXUI_EXPORT(COMPONENT)
42Component& operator|=(Component& component, ElementDecorator decorator);
43
44namespace Container {
47FTXUI_EXPORT(COMPONENT) Component Horizontal(Components children);
48FTXUI_EXPORT(COMPONENT)
50FTXUI_EXPORT(COMPONENT) Component Tab(Components children, int* selector);
51FTXUI_EXPORT(COMPONENT) Component Stacked(Components children);
52} // namespace Container
53
54FTXUI_EXPORT(COMPONENT) Component Button(ButtonOption options);
55FTXUI_EXPORT(COMPONENT)
56Component Button(ConstStringRef label,
57 std::function<void()> on_click,
58 ButtonOption options = ButtonOption::Simple());
59
60FTXUI_EXPORT(COMPONENT) Component Checkbox(CheckboxOption options);
61FTXUI_EXPORT(COMPONENT)
62Component Checkbox(ConstStringRef label,
63 bool* checked,
64 CheckboxOption options = CheckboxOption::Simple());
65
66FTXUI_EXPORT(COMPONENT) Component Input(InputOption options = {});
67FTXUI_EXPORT(COMPONENT)
68Component Input(StringRef content, InputOption options = {});
69FTXUI_EXPORT(COMPONENT)
70Component Input(StringRef content,
71 StringRef placeholder,
72 InputOption options = {});
73
74FTXUI_EXPORT(COMPONENT) Component Menu(MenuOption options);
75FTXUI_EXPORT(COMPONENT)
76Component Menu(ConstStringListRef entries,
77 int* selected_,
78 MenuOption options = MenuOption::Vertical());
79FTXUI_EXPORT(COMPONENT) Component MenuEntry(MenuEntryOption options);
80FTXUI_EXPORT(COMPONENT)
81Component MenuEntry(ConstStringRef label, MenuEntryOption options = {});
82
83FTXUI_EXPORT(COMPONENT) Component Radiobox(RadioboxOption options);
84FTXUI_EXPORT(COMPONENT)
85Component Radiobox(ConstStringListRef entries,
86 int* selected_,
87 RadioboxOption options = {});
88
89FTXUI_EXPORT(COMPONENT)
90Component Dropdown(ConstStringListRef entries, int* selected);
91FTXUI_EXPORT(COMPONENT) Component Dropdown(DropdownOption options);
92
93FTXUI_EXPORT(COMPONENT)
94Component Toggle(ConstStringListRef entries, int* selected);
95
96// Constructor de deslizador general:
97template <typename T>
98Component Slider(SliderOption<T> options);
99
100extern template FTXUI_EXPORT(COMPONENT) Component Slider(SliderOption<int8_t>);
101extern template FTXUI_EXPORT(COMPONENT) Component Slider(SliderOption<int16_t>);
102extern template FTXUI_EXPORT(COMPONENT) Component Slider(SliderOption<int32_t>);
103extern template FTXUI_EXPORT(COMPONENT) Component Slider(SliderOption<int64_t>);
104
105extern template FTXUI_EXPORT(COMPONENT) Component Slider(SliderOption<uint8_t>);
106extern template FTXUI_EXPORT(COMPONENT) Component
107 Slider(SliderOption<uint16_t>);
108extern template FTXUI_EXPORT(COMPONENT) Component
109 Slider(SliderOption<uint32_t>);
110extern template FTXUI_EXPORT(COMPONENT) Component
111 Slider(SliderOption<uint64_t>);
112
113extern template FTXUI_EXPORT(COMPONENT) Component Slider(SliderOption<float>);
114extern template FTXUI_EXPORT(COMPONENT) Component Slider(SliderOption<double>);
115
116// Abreviatura sin el constructor `SliderOption`:
117FTXUI_EXPORT(COMPONENT)
118Component Slider(ConstStringRef label,
119 Ref<int> value,
120 ConstRef<int> min = 0,
121 ConstRef<int> max = 100,
122 ConstRef<int> increment = 5);
123FTXUI_EXPORT(COMPONENT)
124Component Slider(ConstStringRef label,
125 Ref<float> value,
126 ConstRef<float> min = 0.f,
127 ConstRef<float> max = 100.f,
128 ConstRef<float> increment = 5.f);
129FTXUI_EXPORT(COMPONENT)
130Component Slider(ConstStringRef label,
131 Ref<long> value,
132 ConstRef<long> min = 0L,
133 ConstRef<long> max = 100L,
134 ConstRef<long> increment = 5L);
135
136FTXUI_EXPORT(COMPONENT)
137Component ResizableSplit(ResizableSplitOption options);
138FTXUI_EXPORT(COMPONENT)
140FTXUI_EXPORT(COMPONENT)
142FTXUI_EXPORT(COMPONENT)
143Component ResizableSplitTop(Component main, Component back, int* main_size);
144FTXUI_EXPORT(COMPONENT)
146
147FTXUI_EXPORT(COMPONENT)
148Component Renderer(Component child, std::function<Element()>);
149FTXUI_EXPORT(COMPONENT) Component Renderer(std::function<Element()>);
150FTXUI_EXPORT(COMPONENT)
151Component Renderer(std::function<Element(bool /* focused */)>);
153
154FTXUI_EXPORT(COMPONENT)
155Component CatchEvent(Component child, std::function<bool(Event)>);
156FTXUI_EXPORT(COMPONENT)
157ComponentDecorator CatchEvent(std::function<bool(Event)> on_event);
158
159FTXUI_EXPORT(COMPONENT) Component Maybe(Component, const bool* show);
160FTXUI_EXPORT(COMPONENT) Component Maybe(Component, std::function<bool()>);
161FTXUI_EXPORT(COMPONENT) ComponentDecorator Maybe(const bool* show);
162FTXUI_EXPORT(COMPONENT) ComponentDecorator Maybe(std::function<bool()>);
163
164FTXUI_EXPORT(COMPONENT)
165Component Modal(Component main, Component modal, const bool* show_modal);
166FTXUI_EXPORT(COMPONENT)
167ComponentDecorator Modal(Component modal, const bool* show_modal);
168
169FTXUI_EXPORT(COMPONENT)
170Component Collapsible(ConstStringRef label,
171 Component child,
172 Ref<bool> show = false);
173
174FTXUI_EXPORT(COMPONENT)
175Component Hoverable(Component component, bool* hover);
176FTXUI_EXPORT(COMPONENT)
177Component Hoverable(Component component,
178 std::function<void()> on_enter,
179 std::function<void()> on_leave);
180FTXUI_EXPORT(COMPONENT)
181Component Hoverable(Component component, //
182 std::function<void(bool)> on_change);
183FTXUI_EXPORT(COMPONENT) ComponentDecorator Hoverable(bool* hover);
184FTXUI_EXPORT(COMPONENT)
185ComponentDecorator Hoverable(std::function<void()> on_enter,
186 std::function<void()> on_leave);
187FTXUI_EXPORT(COMPONENT)
188ComponentDecorator Hoverable(std::function<void(bool)> on_change);
189
190FTXUI_EXPORT(COMPONENT) Component Window(WindowOptions option);
191
192} // namespace ftxui
193
194#endif /* end of include guard: FTXUI_COMPONENT_HPP */
Un adaptador. Posee o referencia un objeto mutable.
Definition ref.hpp:56
#define FTXUI_EXPORT(component)
Definition export.hpp:24
Component Button(ConstStringRef label, std::function< void()> on_click, ButtonOption options=ButtonOption::Simple())
Dibuja un botón. Ejecuta una función cuando se hace clic.
Component ResizableSplitTop(Component main, Component back, int *main_size)
Una división vertical entre dos componentes, configurable usando el ratón.
Component Horizontal(Components children, int *selector)
Una lista de componentes, dibujados uno a uno horizontalmente y navegados horizontalmente usando las ...
Component Toggle(ConstStringListRef entries, int *selected)
Una lista horizontal de elementos. El usuario puede navegar a través de ellos.
Component Renderer(Component child, std::function< Element()>)
Devuelve un nuevo Component, similar a |child|, pero usando |render| como el evento Component::Render...
Component Checkbox(ConstStringRef label, bool *checked, CheckboxOption options=CheckboxOption::Simple())
Dibuja un elemento marcable.
Component Vertical(Components children)
Una lista de componentes, dibujados uno a uno verticalmente y navegados verticalmente usando las tecl...
Component ResizableSplitRight(Component main, Component back, int *main_size)
Una división horizontal entre dos componentes, configurable usando el ratón.
Component Input(StringRef content, InputOption options={})
Una caja de entrada para editar texto.
Component Dropdown(ConstStringListRef entries, int *selected)
Un menú desplegable.
Component Stacked(Components children)
Una lista de componentes que se apilan uno encima del otro. Los eventos se propagan al primer compone...
Component Radiobox(ConstStringListRef entries, int *selected_, RadioboxOption options={})
Una lista de elementos, donde solo uno puede ser seleccionado.
Component ResizableSplitBottom(Component main, Component back, int *main_size)
Una división vertical entre dos componentes, configurable usando el ratón.
Component Menu(ConstStringListRef entries, int *selected_, MenuOption options=MenuOption::Vertical())
Una lista de texto. El elemento enfocado está seleccionado.
Component ResizableSplitLeft(Component main, Component back, int *main_size)
Una división horizontal entre dos componentes, configurable usando el ratón.
Component Tab(Components children, int *selector)
Una lista de componentes, donde solo uno se dibuja e interactúa a la vez. El |selector| da el índice ...
Component MenuEntry(ConstStringRef label, MenuEntryOption options={})
Una entrada de menú específica. Se pueden colocar en un Container::Vertical para formar un menú.
El espacio de nombres ftxui::Container:: de FTXUI.
El espacio de nombres ftxui:: de FTXUI.
Definition animation.hpp:11
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:28
std::shared_ptr< Node > Element
Definition elements.hpp:25
std::function< Element(Element)> ElementDecorator
Definition component.hpp:34
std::vector< Component > Components
Component ResizableSplit(ResizableSplitOption options)
Una división entre dos componentes.
Component operator|(Component component, ComponentDecorator decorator)
Component Slider(SliderOption< T > options)
Un control deslizante en cualquier dirección.
int value
Definition elements.hpp:195
Component & operator|=(Component &component, ComponentDecorator decorator)
const bool * show
std::function< Component(Component)> ComponentDecorator
Definition component.hpp:33
std::shared_ptr< ComponentBase > Component
Definition app.hpp:23