FTXUI  4.1.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
component_options.hpp
Go to the documentation of this file.
1#ifndef FTXUI_COMPONENT_COMPONENT_OPTIONS_HPP
2#define FTXUI_COMPONENT_COMPONENT_OPTIONS_HPP
3
4#include <chrono> // for milliseconds
5#include <ftxui/component/animation.hpp> // for Duration, QuadraticInOut, Function
6#include <ftxui/dom/direction.hpp> // for Direction, Direction::Left, Direction::Right, Direction::Down
7#include <ftxui/dom/elements.hpp> // for Element, separator
8#include <ftxui/util/ref.hpp> // for Ref, ConstRef
9#include <functional> // for function
10#include <optional> // for optional
11#include <string> // for string
12
13#include "ftxui/component/component_base.hpp" // for Component
14#include "ftxui/screen/color.hpp" // for Color, Color::GrayDark, Color::White
15
16namespace ftxui {
17
18/// @brief arguments for |ButtonOption::transform|, |CheckboxOption::transform|,
19/// |Radiobox::transform|, |MenuEntryOption::transform|,
20/// |MenuOption::transform|.
21struct EntryState {
22 std::string label; /// < The label to display.
23 bool state; /// < The state of the button/checkbox/radiobox
24 bool active; /// < Whether the entry is the active one.
25 bool focused; /// < Whether the entry is one focused by the user.
26};
27
50
51/// @brief Option about a potentially animated color.
52/// @ingroup component
66
71
72/// @brief Option for the MenuEntry component.
73/// @ingroup component
78
79/// @brief Option for the Menu component.
80/// @ingroup component
81struct MenuOption {
82 // Standard constructors:
83 static MenuOption Horizontal();
85 static MenuOption Vertical();
87 static MenuOption Toggle();
88
89 // Style:
93 std::function<Element()> elements_prefix;
94 std::function<Element()> elements_infix;
95 std::function<Element()> elements_postfix;
96
97 // Observers:
98 std::function<void()> on_change; ///> Called when the selected entry changes.
99 std::function<void()> on_enter; ///> Called when the user presses enter.
101};
102
103/// @brief Option for the AnimatedButton component.
104/// @ingroup component
106 // Standard constructors:
107 static ButtonOption Ascii();
108 static ButtonOption Simple();
109 static ButtonOption Border();
110 static ButtonOption Animated();
112 static ButtonOption Animated(Color background, Color foreground);
113 static ButtonOption Animated(Color background,
114 Color foreground,
115 Color background_active,
116 Color foreground_active);
117
118 // Style:
119 std::function<Element(const EntryState&)> transform;
121};
122
123/// @brief Option for the Checkbox component.
124/// @ingroup component
126 // Standard constructors:
127 static CheckboxOption Simple();
128
129 // Style:
130 std::function<Element(const EntryState&)> transform;
131
132 // Observer:
133 /// Called when the user change the state.
134 std::function<void()> on_change = [] {};
135};
136
137/// @brief Option for the Input component.
138/// @ingroup component
140 /// Called when the content changes.
141 std::function<void()> on_change = [] {};
142 /// Called when the user presses enter.
143 std::function<void()> on_enter = [] {};
144
145 /// Obscure the input content using '*'.
147
148 /// When set different from -1, this attributes is used to store the cursor
149 /// position.
151};
152
153/// @brief Option for the Radiobox component.
154/// @ingroup component
156 // Standard constructors:
157 static RadioboxOption Simple();
158
159 // Style:
160 std::function<Element(const EntryState&)> transform;
161
162 // Observers:
163 /// Called when the selected entry changes.
164 std::function<void()> on_change = [] {};
166};
167
177
178// @brief Option for the `Slider` component.
179// @ingroup component
180template <typename T>
190
191} // namespace ftxui
192
193#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_OPTIONS_HPP */
194
195// Copyright 2021 Arthur Sonzogni. All rights reserved.
196// Use of this source code is governed by the MIT license that can be found in
197// the LICENSE file.
A class representing terminal colors.
Definition color.hpp:18
An adapter. Own or reference an immutable object.
Definition ref.hpp:11
An adapter. Own or reference an mutable object.
Definition ref.hpp:27
float QuadraticInOut(float p)
Definition animation.cpp:46
std::function< float(float)> Function
Definition animation.hpp:36
std::chrono::duration< float > Duration
Definition animation.hpp:21
bool active
< The state of the button/checkbox/radiobox
std::function< Element()> separator_func
bool focused
< Whether the entry is the active one.
std::shared_ptr< Node > Element
Definition elements.hpp:20
std::function< void()> on_enter
Called when the user presses enter.
std::function< Element(const EntryState &state)> transform
Ref< bool > password
Obscure the input content using '*'.
bool state
< The label to display.
AnimatedColorsOption animated_colors
std::function< void()> on_change
Called when the content changes.
std::shared_ptr< ComponentBase > Component
Decorator color(Color)
Decorate using a foreground color.
Definition color.cpp:86
arguments for |ButtonOption::transform|, |CheckboxOption::transform|, |Radiobox::transform|,...
Option for the Input component.
Option for the MenuEntry component.
Option about a potentially animated color.
animation::easing::Function function
void Set(Color inactive, Color active, animation::Duration duration=std::chrono::milliseconds(250), animation::easing::Function function=animation::easing::QuadraticInOut)
Option for the AnimatedButton component.
static ButtonOption Animated()
Create a ButtonOption, using animated colors.
static ButtonOption Border()
Create a ButtonOption. The button is shown using a border, inverted when focused. This is the current...
static ButtonOption Simple()
Create a ButtonOption, inverted when focused.
static ButtonOption Ascii()
Create a ButtonOption, highlighted using [] characters.
AnimatedColorsOption animated_colors
std::function< Element(const EntryState &)> transform
Option for the Checkbox component.
static CheckboxOption Simple()
Option for standard Checkbox.
std::function< void()> on_change
Called when the user change the state.
std::function< Element(const EntryState &)> transform
Option for the Menu component.
std::function< Element()> elements_prefix
static MenuOption Toggle()
std::function< void()> on_enter
UnderlineOption underline
static MenuOption Horizontal()
static MenuOption VerticalAnimated()
static MenuOption Vertical()
std::function< Element()> elements_infix
std::function< Element()> elements_postfix
MenuEntryOption entries
std::function< void()> on_change
static MenuOption HorizontalAnimated()
Option for the Radiobox component.
std::function< void()> on_change
Called when the selected entry changes.
static RadioboxOption Simple()
Option for standard Radiobox.
std::function< Element(const EntryState &)> transform
animation::Duration follower_duration
animation::easing::Function leader_function
animation::Duration follower_delay
void SetAnimationFunction(animation::easing::Function f)
animation::Duration leader_duration
void SetAnimation(animation::Duration d, animation::easing::Function f)
void SetAnimationDuration(animation::Duration d)
animation::easing::Function follower_function
animation::Duration leader_delay