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