FTXUI  3.0.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/elements.hpp> // for Element
7#include <ftxui/util/ref.hpp> // for Ref
8#include <functional> // for function
9#include <optional> // for optional
10#include <string> // for string
11
12#include "ftxui/screen/color.hpp" // for Color, Color::GrayDark, Color::White
13
14namespace ftxui {
15
16/// @brief arguments for |ButtonOption::transform|, |CheckboxOption::transform|,
17/// |Radiobox::transform|, |MenuEntryOption::transform|,
18/// |MenuOption::transform|.
19struct EntryState {
20 std::string label; /// < The label to display.
21 bool state; /// < The state of the button/checkbox/radiobox
22 bool active; /// < Whether the entry is the active one.
23 bool focused; /// < Whether the entry is one focused by the user.
24};
25
48
49/// @brief Option about a potentially animated color.
50/// @ingroup component
64
69
70/// @brief Option for the MenuEntry component.
71/// @ingroup component
76
77/// @brief Option for the Menu component.
78/// @ingroup component
79struct MenuOption {
80 // Standard constructors:
81 static MenuOption Horizontal();
83 static MenuOption Vertical();
85 static MenuOption Toggle();
86
87 // Style:
90 enum Direction { Up, Down, Left, Right };
92 std::function<Element()> elements_prefix;
93 std::function<Element()> elements_infix;
94 std::function<Element()> elements_postfix;
95
96 // Observers:
97 std::function<void()> on_change; ///> Called when the seelcted entry changes.
98 std::function<void()> on_enter; ///> Called when the user presses enter.
100};
101
102/// @brief Option for the AnimatedButton component.
103/// @ingroup component
105 // Standard constructors:
106 static ButtonOption Ascii();
107 static ButtonOption Simple();
109 static ButtonOption Animated();
111 static ButtonOption Animated(Color background, Color foreground);
112 static ButtonOption Animated(Color background,
113 Color foreground,
114 Color background_active,
115 Color foreground_active);
116
117 // Style:
118 std::function<Element(const EntryState&)> transform;
120};
121
122/// @brief Option for the Checkbox component.
123/// @ingroup component
125 // Standard constructors:
126 static CheckboxOption Simple();
127
128 // Style:
129 std::function<Element(const EntryState&)> transform;
130
131 // Observer:
132 /// Called when the user change the state.
133 std::function<void()> on_change = [] {};
134};
135
136/// @brief Option for the Input component.
137/// @ingroup component
139 /// Called when the content changes.
140 std::function<void()> on_change = [] {};
141 /// Called when the user presses enter.
142 std::function<void()> on_enter = [] {};
143
144 /// Obscure the input content using '*'.
146
147 /// When set different from -1, this attributes is used to store the cursor
148 /// position.
150};
151
152/// @brief Option for the Radiobox component.
153/// @ingroup component
155 // Standard constructors:
156 static RadioboxOption Simple();
157
158 // Style:
159 std::function<Element(const EntryState&)> transform;
160
161 // Observers:
162 /// Called when the selected entry changes.
163 std::function<void()> on_change = [] {};
165};
166
167} // namespace ftxui
168
169#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_OPTIONS_HPP */
170
171// Copyright 2021 Arthur Sonzogni. All rights reserved.
172// Use of this source code is governed by the MIT license that can be found in
173// the LICENSE file.
A class representing terminal colors.
Definition color.hpp:17
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< double > Duration
Definition animation.hpp:21
bool active
< The state of the button/checkbox/radiobox
bool focused
< Whether the entry is the active one.
std::shared_ptr< Node > Element
Definition elements.hpp:18
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.
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()
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