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// Opérateur pipe pour décorer les composants.
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// Constructeur de curseur général :
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// Raccourci sans le constructeur `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 adaptateur. Possède ou référence un objet 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())
Dessine un bouton. Exécute une fonction lorsqu'il est cliqué.
Component ResizableSplitTop(Component main, Component back, int *main_size)
Une division verticale entre deux composants, configurable en utilisant la souris.
Component Horizontal(Components children, int *selector)
Une liste de composants, dessinés un par un horizontalement et navigués horizontalement en utilisant ...
Component Toggle(ConstStringListRef entries, int *selected)
Une liste horizontale d'éléments. L'utilisateur peut naviguer à travers eux.
Component Renderer(Component child, std::function< Element()>)
Retourne un nouveau Component, similaire à |child|, mais utilisant |render| comme événement Component...
Component Checkbox(ConstStringRef label, bool *checked, CheckboxOption options=CheckboxOption::Simple())
Dessine un élément cochable.
Component Vertical(Components children)
Une liste de composants, dessinés un par un verticalement et navigués verticalement en utilisant les ...
Component ResizableSplitRight(Component main, Component back, int *main_size)
Une division horizontale entre deux composants, configurable en utilisant la souris.
Component Input(StringRef content, InputOption options={})
Une boîte de saisie pour éditer du texte.
Component Dropdown(ConstStringListRef entries, int *selected)
Un menu déroulant.
Component Stacked(Components children)
Une liste de composants à empiler les uns sur les autres. Les événements sont propagés au premier com...
Component Radiobox(ConstStringListRef entries, int *selected_, RadioboxOption options={})
Une liste d'éléments, où un seul peut être sélectionné.
Component ResizableSplitBottom(Component main, Component back, int *main_size)
Une division verticale entre deux composants, configurable en utilisant la souris.
Component Menu(ConstStringListRef entries, int *selected_, MenuOption options=MenuOption::Vertical())
Une liste de texte. L'élément focalisé est sélectionné.
Component ResizableSplitLeft(Component main, Component back, int *main_size)
Une division horizontale entre deux composants, configurable en utilisant la souris.
Component Tab(Components children, int *selector)
Une liste de composants, où un seul est dessiné et interagit avec à la fois. Le |selector| donne l'in...
Component MenuEntry(ConstStringRef label, MenuEntryOption options={})
Une entrée de menu spécifique. Elles peuvent être placées dans un Container::Vertical pour former un ...
L'espace de noms FTXUI ftxui::Container::
L'espace de noms FTXUI 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)
Une séparation entre deux composants.
Component operator|(Component component, ComponentDecorator decorator)
Component Slider(SliderOption< T > options)
Un curseur dans n'importe quelle direction.
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