FTXUI  4.1.1
C++ functional terminal UI.
Loading...
Searching...
No Matches
component.hpp
Go to the documentation of this file.
1#ifndef FTXUI_COMPONENT_HPP
2#define FTXUI_COMPONENT_HPP
3
4#include <functional> // for function
5#include <memory> // for make_shared, shared_ptr
6#include <string> // for wstring
7#include <utility> // for forward
8#include <vector> // for vector
9
10#include "ftxui/component/component_base.hpp" // for Component, Components
11#include "ftxui/component/component_options.hpp" // for ButtonOption, CheckboxOption, MenuOption
12#include "ftxui/dom/elements.hpp" // for Element
13#include "ftxui/util/ref.hpp" // for ConstRef, Ref, ConstStringRef, ConstStringListRef, StringRef
14
15namespace ftxui {
16struct ButtonOption;
17struct CheckboxOption;
18struct Event;
19struct InputOption;
20struct MenuOption;
21struct RadioboxOption;
22struct MenuEntryOption;
23
24template <class T, class... Args>
25std::shared_ptr<T> Make(Args&&... args) {
26 return std::make_shared<T>(std::forward<Args>(args)...);
27}
28
29// Pipe operator to decorate components.
30using ComponentDecorator = std::function<Component(Component)>;
31using ElementDecorator = std::function<Element(Element)>;
33Component operator|(Component component, ElementDecorator decorator);
34Component& operator|=(Component& component, ComponentDecorator decorator);
35Component& operator|=(Component& component, ElementDecorator decorator);
36
37namespace Container {
39Component Vertical(Components children, int* selector);
41Component Horizontal(Components children, int* selector);
42Component Tab(Components children, int* selector);
43
44} // namespace Container
45
47 std::function<void()> on_click,
49
51 bool* checked,
53
55 ConstStringRef placeholder,
56 Ref<InputOption> option = {});
57
58Component Menu(ConstStringListRef entries,
59 int* selected_,
60 Ref<MenuOption> = MenuOption::Vertical());
61Component MenuEntry(ConstStringRef label, Ref<MenuEntryOption> = {});
62
63Component Dropdown(ConstStringListRef entries, int* selected);
64
65Component Radiobox(ConstStringListRef entries,
66 int* selected_,
67 Ref<RadioboxOption> option = {});
68Component Toggle(ConstStringListRef entries, int* selected);
69
70// General slider constructor:
71template <typename T>
72Component Slider(SliderOption<T> options = {});
73
74// Shorthand without the `SliderOption` constructor:
75Component Slider(ConstStringRef label,
76 Ref<int> value,
77 ConstRef<int> min = 0,
78 ConstRef<int> max = 100,
79 ConstRef<int> increment = 5);
80Component Slider(ConstStringRef label,
81 Ref<float> value,
82 ConstRef<float> min = 0.f,
83 ConstRef<float> max = 100.f,
84 ConstRef<float> increment = 5.f);
85Component Slider(ConstStringRef label,
86 Ref<long> value,
87 ConstRef<long> min = 0l,
88 ConstRef<long> max = 100l,
89 ConstRef<long> increment = 5l);
90
91Component ResizableSplitLeft(Component main, Component back, int* main_size);
92Component ResizableSplitRight(Component main, Component back, int* main_size);
93Component ResizableSplitTop(Component main, Component back, int* main_size);
94Component ResizableSplitBottom(Component main, Component back, int* main_size);
95
96Component Renderer(Component child, std::function<Element()>);
97Component Renderer(std::function<Element()>);
98Component Renderer(std::function<Element(bool /* focused */)>);
100
101Component CatchEvent(Component child, std::function<bool(Event)>);
102ComponentDecorator CatchEvent(std::function<bool(Event)> on_event);
103
104Component Maybe(Component, const bool* show);
105Component Maybe(Component, std::function<bool()>);
106ComponentDecorator Maybe(const bool* show);
107ComponentDecorator Maybe(std::function<bool()>);
108
109Component Modal(Component main, Component modal, const bool* show_modal);
110ComponentDecorator Modal(Component modal, const bool* show_modal);
111
113 Component child,
114 Ref<bool> show = false);
115
116Component Hoverable(Component component, bool* hover);
118 std::function<void()> on_enter,
119 std::function<void()> on_leave);
120Component Hoverable(Component component, //
121 std::function<void(bool)> on_change);
122ComponentDecorator Hoverable(bool* hover);
123ComponentDecorator Hoverable(std::function<void()> on_enter,
124 std::function<void()> on_leave);
125ComponentDecorator Hoverable(std::function<void(bool)> on_change);
126
127} // namespace ftxui
128
129#endif /* end of include guard: FTXUI_COMPONENT_HPP */
130
131// Copyright 2021 Arthur Sonzogni. All rights reserved.
132// Use of this source code is governed by the MIT license that can be found in
133// the LICENSE file.
An adapter. Own or reference a constant string. For convenience, this class convert multiple immutabl...
Definition ref.hpp:60
An adapter. Own or reference an mutable object.
Definition ref.hpp:27
An adapter. Own or reference a constant string. For convenience, this class convert multiple mutable ...
Definition ref.hpp:44
Component Horizontal(Components children)
A list of components, drawn one by one horizontally and navigated horizontally using left/right arrow...
Component Vertical(Components children)
A list of components, drawn one by one vertically and navigated vertically using up/down arrow key or...
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 Checkbox(ConstStringRef label, bool *checked, Ref< CheckboxOption > option=CheckboxOption::Simple())
Draw checkable element.
Definition checkbox.cpp:112
Component Radiobox(ConstStringListRef entries, int *selected_, Ref< RadioboxOption > option={})
A list of element, where only one can be selected.
Definition radiobox.cpp:211
Component Maybe(Component, const bool *show)
Decorate a component |child|. It is shown only when |show| is true. @params child the compoennt to de...
Definition maybe.cpp:67
Component ResizableSplitTop(Component main, Component back, int *main_size)
An vertical split in between two components, configurable using the mouse.
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:25
std::shared_ptr< Node > Element
Definition elements.hpp:19
std::function< Element(Element)> ElementDecorator
Definition component.hpp:31
Component Input(StringRef content, ConstStringRef placeholder, Ref< InputOption > option={})
An input box for editing text.
Definition input.cpp:337
Component Toggle(ConstStringListRef entries, int *selected)
An horizontal list of elements. The user can navigate through them.
Definition menu.cpp:522
std::vector< Component > Components
Component MenuEntry(ConstStringRef label, Ref< MenuEntryOption >={})
A specific menu entry. They can be put into a Container::Vertical to form a menu.
Definition menu.cpp:552
Component Modal(Component main, Component modal, const bool *show_modal)
Definition modal.cpp:15
Component Renderer(Component child, std::function< Element()>)
Return a new Component, similar to |child|, but using |render| as the Component::Render() event.
Definition renderer.cpp:60
Component Hoverable(Component component, bool *hover)
Wrap a component. Gives the ability to know if it is hovered by the mouse.
Definition hoverable.cpp:41
Component operator|(Component component, ComponentDecorator decorator)
Definition util.cpp:9
Component Button(ConstStringRef label, std::function< void()> on_click, Ref< ButtonOption >=ButtonOption::Simple())
Draw a button. Execute a function when clicked.
Definition button.cpp:59
Component Menu(ConstStringListRef entries, int *selected_, Ref< MenuOption >=MenuOption::Vertical())
A list of text. The focused element is selected.
Definition menu.cpp:511
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)
Definition dropdown.cpp:14
Component Slider(SliderOption< T > options={})
A slider in any direction.
Definition slider.cpp:326
Component ResizableSplitBottom(Component main, Component back, int *main_size)
An vertical split in between two components, configurable using the mouse.
Component & operator|=(Component &component, ComponentDecorator decorator)
Definition util.cpp:19
Component ResizableSplitLeft(Component main, Component back, int *main_size)
An horizontal split in between two components, configurable using the mouse.
std::function< Component(Component)> ComponentDecorator
Definition component.hpp:30
std::shared_ptr< ComponentBase > Component
Component Collapsible(ConstStringRef label, Component child, Ref< bool > show=false)
Component CatchEvent(Component child, std::function< bool(Event)>)
static ButtonOption Simple()
Create a ButtonOption, inverted when focused.
static CheckboxOption Simple()
Option for standard Checkbox.
Represent an event. It can be key press event, a terminal resize, or more ...
Definition event.hpp:26
static MenuOption Vertical()