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
11#include "ftxui/component/component_base.hpp" // for Component, Components
12#include "ftxui/component/component_options.hpp" // for ButtonOption, CheckboxOption, MenuOption
13#include "ftxui/dom/elements.hpp" // for Element
14#include "ftxui/util/ref.hpp" // for ConstRef, Ref, ConstStringRef, ConstStringListRef, StringRef
15
16 namespace ftxui {
17 struct ButtonOption;
18 struct CheckboxOption;
19 struct Event;
20 struct InputOption;
21 struct MenuOption;
22 struct RadioboxOption;
23 struct MenuEntryOption;
24
25 template <class T, class... Args>
26std::shared_ptr<T> Make(Args&&... args) {
27 return std::make_shared<T>(std::forward<Args>(args)...);
28}
29
30// Pipe operator to decorate components.
31 using ComponentDecorator = std::function<Component(Component)>;
32 using ElementDecorator = std::function<Element(Element)>;
33 Component operator|(Component component, ComponentDecorator decorator);
34 Component operator|(Component component, ElementDecorator decorator);
35 Component& operator|=(Component& component, ComponentDecorator decorator);
36 Component& operator|=(Component& component, ElementDecorator decorator);
37
38 namespace Container {
39 Component Vertical(Components children);
40 Component Vertical(Components children, int* selector);
41 Component Horizontal(Components children);
42 Component Horizontal(Components children, int* selector);
43 Component Tab(Components children, int* selector);
44 Component Stacked(Components children);
45} // namespace Container
46
47 Component Button(ButtonOption options);
48 Component Button(ConstStringRef label,
49 std::function<void()> on_click,
50 ButtonOption options = ButtonOption::Simple());
51
52 Component Checkbox(CheckboxOption options);
53 Component Checkbox(ConstStringRef label,
54 bool* checked,
55 CheckboxOption options = CheckboxOption::Simple());
56
57 Component Input(InputOption options = {});
58 Component Input(StringRef content, InputOption options = {});
59 Component Input(StringRef content,
60 StringRef placeholder,
61 InputOption options = {});
62
63 Component Menu(MenuOption options);
64 Component Menu(ConstStringListRef entries,
65 int* selected_,
66 MenuOption options = MenuOption::Vertical());
67 Component MenuEntry(MenuEntryOption options);
68 Component MenuEntry(ConstStringRef label, MenuEntryOption options = {});
69
70 Component Radiobox(RadioboxOption options);
71 Component Radiobox(ConstStringListRef entries,
72 int* selected_,
73 RadioboxOption options = {});
74
75 Component Dropdown(ConstStringListRef entries, int* selected);
76 Component Dropdown(DropdownOption options);
77
78 Component Toggle(ConstStringListRef entries, int* selected);
79
80// General slider constructor:
81 template <typename T>
82 Component Slider(SliderOption<T> options);
83
84// Shorthand without the `SliderOption` constructor:
85 Component Slider(ConstStringRef label,
86 Ref<int> value,
87 ConstRef<int> min = 0,
88 ConstRef<int> max = 100,
89 ConstRef<int> increment = 5);
90 Component Slider(ConstStringRef label,
91 Ref<float> value,
92 ConstRef<float> min = 0.f,
93 ConstRef<float> max = 100.f,
94 ConstRef<float> increment = 5.f);
95 Component Slider(ConstStringRef label,
96 Ref<long> value,
97 ConstRef<long> min = 0L,
98 ConstRef<long> max = 100L,
99 ConstRef<long> increment = 5L);
100
101 Component ResizableSplit(ResizableSplitOption options);
102 Component ResizableSplitLeft(Component main, Component back, int* main_size);
103 Component ResizableSplitRight(Component main, Component back, int* main_size);
104 Component ResizableSplitTop(Component main, Component back, int* main_size);
105 Component ResizableSplitBottom(Component main, Component back, int* main_size);
106
107 Component Renderer(Component child, std::function<Element()>);
108 Component Renderer(std::function<Element()>);
109 Component Renderer(std::function<Element(bool /* focused */)>);
110 ComponentDecorator Renderer(ElementDecorator);
111
112 Component CatchEvent(Component child, std::function<bool(Event)>);
113 ComponentDecorator CatchEvent(std::function<bool(Event)> on_event);
114
115 Component Maybe(Component, const bool* show);
116 Component Maybe(Component, std::function<bool()>);
117 ComponentDecorator Maybe(const bool* show);
118 ComponentDecorator Maybe(std::function<bool()>);
119
120 Component Modal(Component main, Component modal, const bool* show_modal);
121 ComponentDecorator Modal(Component modal, const bool* show_modal);
122
123 Component Collapsible(ConstStringRef label,
124 Component child,
125 Ref<bool> show = false);
126
127 Component Hoverable(Component component, bool* hover);
128 Component Hoverable(Component component,
129 std::function<void()> on_enter,
130 std::function<void()> on_leave);
131 Component Hoverable(Component component, //
132 std::function<void(bool)> on_change);
133 ComponentDecorator Hoverable(bool* hover);
134 ComponentDecorator Hoverable(std::function<void()> on_enter,
135 std::function<void()> on_leave);
136 ComponentDecorator Hoverable(std::function<void(bool)> on_change);
137
138 Component Window(WindowOptions option);
139
140} // namespace ftxui
141
142#endif /* end of include guard: FTXUI_COMPONENT_HPP */
ftxui::ConstStringRef
An adapter. Own or reference a constant string. For convenience, this class convert multiple immutabl...
Definition ref.hpp:94
ftxui::Ref
An adapter. Own or reference an mutable object.
Definition ref.hpp:46
component_base.hpp
component_options.hpp
elements.hpp
main
int main()
Definition examples/component/button.cpp:33
ftxui::CheckboxOption::Simple
static CheckboxOption Simple()
Option for standard Checkbox.
Definition component_options.cpp:244
ftxui::ButtonOption::Simple
static ButtonOption Simple()
Create a ButtonOption, inverted when focused.
Definition component_options.cpp:165
ftxui::MenuOption::Vertical
static MenuOption Vertical()
Standard options for a vertical menu. This can be useful to implement a list of selectable items.
Definition component_options.cpp:102
ftxui::Container::Horizontal
Component Horizontal(Components children)
A list of components, drawn one by one horizontally and navigated horizontally using left/right arrow...
Definition container.cpp:360
ftxui::Maybe
Component Maybe(Component, const bool *show)
Decorate a component |child|. It is shown only when |show| is true.
Definition src/ftxui/component/maybe.cpp:74
ftxui::ResizableSplitTop
Component ResizableSplitTop(Component main, Component back, int *main_size)
An vertical split in between two components, configurable using the mouse.
Definition src/ftxui/component/resizable_split.cpp:283
ftxui::Menu
Component Menu(MenuOption options)
A list of text. The focused element is selected.
Definition src/ftxui/component/menu.cpp:512
ftxui::MenuEntry
Component MenuEntry(MenuEntryOption options)
A specific menu entry. They can be put into a Container::Vertical to form a menu.
Definition src/ftxui/component/menu.cpp:614
ftxui::Toggle
Component Toggle(ConstStringListRef entries, int *selected)
An horizontal list of elements. The user can navigate through them.
Definition src/ftxui/component/menu.cpp:554
ftxui::Radiobox
Component Radiobox(RadioboxOption options)
A list of element, where only one can be selected.
Definition src/ftxui/component/radiobox.cpp:204
ftxui::Button
Component Button(ButtonOption options)
Draw a button. Execute a function when clicked.
Definition src/ftxui/component/button.cpp:175
ftxui::Modal
Component Modal(Component main, Component modal, const bool *show_modal)
Definition modal.cpp:18
ftxui::Renderer
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Definition src/ftxui/component/renderer.cpp:61
ftxui::Hoverable
Component Hoverable(Component component, bool *hover)
Wrap a component. Gives the ability to know if it is hovered by the mouse.
Definition hoverable.cpp:43
ftxui::Window
Component Window(WindowOptions option)
A draggeable / resizeable window. To use multiple of them, they must be stacked using Container::Stac...
Definition src/ftxui/component/window.cpp:312
ftxui::Container::Vertical
Component Vertical(Components children)
A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or...
Definition container.cpp:317
ftxui::Input
Component Input(InputOption options={})
An input box for editing text.
Definition src/ftxui/component/input.cpp:571
ftxui::ResizableSplitRight
Component ResizableSplitRight(Component main, Component back, int *main_size)
An horizontal split in between two components, configurable using the mouse.
Definition src/ftxui/component/resizable_split.cpp:249
ftxui::Dropdown
Component Dropdown(ConstStringListRef entries, int *selected)
A dropdown menu.
Definition src/ftxui/component/dropdown.cpp:22
ftxui::Container::Stacked
Component Stacked(Components children)
A list of components to be stacked on top of each other. Events are propagated to the first component...
Definition container.cpp:432
ftxui::ResizableSplitBottom
Component ResizableSplitBottom(Component main, Component back, int *main_size)
An vertical split in between two components, configurable using the mouse.
Definition src/ftxui/component/resizable_split.cpp:317
ftxui::Checkbox
Component Checkbox(CheckboxOption options)
Draw checkable element.
Definition src/ftxui/component/checkbox.cpp:108
ftxui::ResizableSplitLeft
Component ResizableSplitLeft(Component main, Component back, int *main_size)
An horizontal split in between two components, configurable using the mouse.
Definition src/ftxui/component/resizable_split.cpp:215
ftxui::Container::Tab
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...
Definition container.cpp:405
ftxui::ButtonOption
Option for the AnimatedButton component.
Definition component_options.hpp:113
ftxui::CheckboxOption
Option for the Checkbox component.
Definition component_options.hpp:136
ftxui::Event
Represent an event. It can be key press event, a terminal resize, or more ...
Definition event.hpp:29
ftxui::InputOption
Option for the Input component.
Definition component_options.hpp:163
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
ftxui::Make
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26
ftxui::Element
std::shared_ptr< Node > Element
Definition elements.hpp:22
ftxui::ElementDecorator
std::function< Element(Element)> ElementDecorator
Definition component.hpp:32
ftxui::Components
std::vector< Component > Components
Definition component_base.hpp:25
ftxui::ResizableSplit
Component ResizableSplit(ResizableSplitOption options)
A split in between two components.
Definition src/ftxui/component/resizable_split.cpp:186
ftxui::operator|
Component operator|(Component component, ComponentDecorator decorator)
Definition component/util.cpp:12
ftxui::Collapsible
Component Collapsible(ConstStringRef label, Component child, Ref< bool > show=false)
A collapsible component. It displays a checkbox with an arrow. Once activated, the child is displayed...
Definition src/ftxui/component/collapsible.cpp:33
ftxui::Slider
Component Slider(SliderOption< T > options)
A slider in any direction.
Definition src/ftxui/component/slider.cpp:346
ftxui::operator|=
Component & operator|=(Component &component, ComponentDecorator decorator)
Definition component/util.cpp:22
ftxui::ComponentDecorator
std::function< Component(Component)> ComponentDecorator
Definition component.hpp:31
ftxui::Component
std::shared_ptr< ComponentBase > Component
Definition component_base.hpp:24
ftxui::CatchEvent
Component CatchEvent(Component child, std::function< bool(Event)>)
ref.hpp
ftxui::WindowOptions
Definition component_options.hpp:251