FTXUI  3.0.0
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, InputOption (ptr only), MenuEntryOption (ptr only), MenuOption, RadioboxOption (ptr only)
12#include "ftxui/dom/elements.hpp" // for Element
13#include "ftxui/util/ref.hpp" // for 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
70template <class T> // T = {int, float, long}
71Component Slider(ConstStringRef label, T* value, T min, T max, T increment);
72
73Component ResizableSplitLeft(Component main, Component back, int* main_size);
74Component ResizableSplitRight(Component main, Component back, int* main_size);
75Component ResizableSplitTop(Component main, Component back, int* main_size);
76Component ResizableSplitBottom(Component main, Component back, int* main_size);
77
78Component Renderer(Component child, std::function<Element()>);
79Component Renderer(std::function<Element()>);
80Component Renderer(std::function<Element(bool /* focused */)>);
82
83Component CatchEvent(Component child, std::function<bool(Event)>);
84ComponentDecorator CatchEvent(std::function<bool(Event)> on_event);
85
86Component Maybe(Component, const bool* show);
87Component Maybe(Component, std::function<bool()>);
88ComponentDecorator Maybe(const bool* show);
89ComponentDecorator Maybe(std::function<bool()>);
90
92 Component child,
93 Ref<bool> show = false);
94} // namespace ftxui
95
96#endif /* end of include guard: FTXUI_COMPONENT_HPP */
97
98// Copyright 2021 Arthur Sonzogni. All rights reserved.
99// Use of this source code is governed by the MIT license that can be found in
100// 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:113
Component Radiobox(ConstStringListRef entries, int *selected_, Ref< RadioboxOption > option={})
A list of element, where only one can be selected.
Definition radiobox.cpp:214
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:66
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:18
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:262
Component Toggle(ConstStringListRef entries, int *selected)
An horizontal list of elements. The user can navigate through them.
Definition menu.cpp:507
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:537
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 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:496
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 ResizableSplitBottom(Component main, Component back, int *main_size)
An vertical split in between two components, configurable using the mouse.
Component Slider(ConstStringRef label, T *value, T min, T max, T increment)
An horizontal slider.
Definition slider.cpp:124
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()