FTXUI 6.1.9
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// Pipe operator to decorate components.
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// General slider constructor:
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// Shorthand without the `SliderOption` constructor:
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 */
An adapter. Own or reference an mutable object.
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())
Draw a button. Execute a function when clicked.
Component ResizableSplitTop(Component main, Component back, int *main_size)
An vertical split in between two components, configurable using the mouse.
Component Horizontal(Components children, int *selector)
A list of components, drawn one by one horizontally and navigated horizontally using left/right arrow...
Component Toggle(ConstStringListRef entries, int *selected)
An horizontal list of elements. The user can navigate through them.
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Component Checkbox(ConstStringRef label, bool *checked, CheckboxOption options=CheckboxOption::Simple())
Draw checkable element.
Component Vertical(Components children)
A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or...
Component ResizableSplitRight(Component main, Component back, int *main_size)
An horizontal split in between two components, configurable using the mouse.
Component Input(StringRef content, InputOption options={})
An input box for editing text.
Component Dropdown(ConstStringListRef entries, int *selected)
A dropdown menu.
Component Stacked(Components children)
A list of components to be stacked on top of each other. Events are propagated to the first component...
Component Radiobox(ConstStringListRef entries, int *selected_, RadioboxOption options={})
A list of element, where only one can be selected.
Component ResizableSplitBottom(Component main, Component back, int *main_size)
An vertical split in between two components, configurable using the mouse.
Component Menu(ConstStringListRef entries, int *selected_, MenuOption options=MenuOption::Vertical())
A list of text. The focused element is selected.
Component ResizableSplitLeft(Component main, Component back, int *main_size)
An horizontal split in between two components, configurable using the mouse.
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...
Component MenuEntry(ConstStringRef label, MenuEntryOption options={})
A specific menu entry. They can be put into a Container::Vertical to form a menu.
The FTXUI ftxui::Container:: namespace.
The FTXUI ftxui:: namespace.
Definition animation.hpp:11
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:28
std::shared_ptr< Node > Element
Definition elements.hpp:24
std::function< Element(Element)> ElementDecorator
Definition component.hpp:34
std::vector< Component > Components
Component ResizableSplit(ResizableSplitOption options)
A split in between two components.
Component operator|(Component component, ComponentDecorator decorator)
Component Slider(SliderOption< T > options)
A slider in any direction.
int value
Definition elements.hpp:178
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