FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
component_options.hpp
浏览该文件的文档.
1// 版权所有 2021 Arthur Sonzogni。保留所有权利。
2// 本源代码的使用受 MIT 许可协议的约束,该协议可在 LICENSE 文件中找到。
3#ifndef FTXUI_COMPONENT_COMPONENT_OPTIONS_HPP
4#define FTXUI_COMPONENT_COMPONENT_OPTIONS_HPP
5
6#include <chrono> // for milliseconds
7#include <ftxui/component/animation.hpp> // for Duration, QuadraticInOut, Function
8#include <ftxui/dom/direction.hpp> // for Direction, Direction::Left, Direction::Right, Direction::Down
9#include <ftxui/dom/elements.hpp> // for Element, separator
10#include <ftxui/util/ref.hpp> // for Ref, ConstRef, StringRef
12#include <functional> // for function
13#include <limits> // for numeric_limits
14#include <string> // for string
15
16#include "ftxui/component/component_base.hpp" // for Component
17#include "ftxui/screen/color.hpp" // for Color, Color::GrayDark, Color::White
18
19namespace ftxui {
20
21/// @brief 来自 |ButtonOption|、|CheckboxOption|、
22/// |RadioboxOption|、|MenuEntryOption|、|MenuOption| 的转换参数。
23struct EntryState {
24 std::string label; ///< 要显示的标签。
25 bool state; ///< 按钮/复选框/单选框的状态
26 bool active; ///< 条目是否为活动状态。
27 bool focused; ///< 条目是否被用户聚焦。
28 int index; ///< 适用时为条目的索引,否则为 -1。
29};
30
31/// @brief 下划线效果的选项。
32/// @ingroup component
55
56/// @brief 可能是动画颜色的选项。
57/// @ingroup component
59 void Set(
62 animation::Duration duration = std::chrono::milliseconds(250),
63 animation::easing::Function function = animation::easing::QuadraticInOut);
64
65 bool enabled = false;
68 animation::Duration duration = std::chrono::milliseconds(250);
70};
71
76
77/// @brief MenuEntry 组件的选项。
78/// @ingroup component
84
85/// @brief Menu 组件的选项。
86/// @ingroup component
87struct MenuOption {
88 // 标准构造函数:
89 static MenuOption Horizontal();
91 static MenuOption Vertical();
93 static MenuOption Toggle();
94
95 ConstStringListRef entries; ///> 条目列表。
96 Ref<int> selected = 0; ///> 选中条目的索引。
97
98 // 样式:
102 std::function<Element()> elements_prefix;
103 std::function<Element()> elements_infix;
104 std::function<Element()> elements_postfix;
105
106 // 观察者:
107 std::function<void()> on_change; ///> 当选中条目改变时调用。
108 std::function<void()> on_enter; ///> 当用户按下回车键时调用。
110};
111
112/// @brief AnimatedButton 组件的选项。
113/// @ingroup component
115 // Standard constructors:
116 static ButtonOption Ascii();
117 static ButtonOption Simple();
118 static ButtonOption Border();
119 static ButtonOption Animated();
120 static ButtonOption Animated(Color color);
121 static ButtonOption Animated(Color background, Color foreground);
122 static ButtonOption Animated(Color background,
123 Color foreground,
124 Color background_active,
125 Color foreground_active);
126
128 std::function<void()> on_click = [] {};
129
130 // Style:
131 std::function<Element(const EntryState&)> transform;
133};
134
135/// @brief Checkbox 组件的选项。
136/// @ingroup component
138 // 标准构造函数:
139 static CheckboxOption Simple();
140
141 ConstStringRef label = "Checkbox";
142
144
145 // 样式:
146 std::function<Element(const EntryState&)> transform;
147
148 // 观察者:
149 /// 当用户改变状态时调用。
150 std::function<void()> on_change = [] {};
151};
152
153/// @brief 用于定义 Input 组件的样式。
156 bool hovered; ///< 输入框是否被鼠标悬停。
157 bool focused; ///< 输入框是否被用户聚焦。
158 bool is_placeholder; ///< 输入框是否为空并显示占位符。
159};
160
161/// @brief Input 组件的选项。
162/// @ingroup component
164 // 一组预定义样式:
165
166 /// @brief 创建默认输入样式:
167 static InputOption Default();
168 /// @brief 带有大边距的白底黑字样式:
169 static InputOption Spacious();
170
171 /// 输入框的内容。
173
174 /// 当输入框为空时显示的内容。
176
177 // 样式:
178 std::function<Element(InputState)> transform;
179 Ref<bool> password = false; ///< 使用 '*' 遮盖输入内容。
180 Ref<bool> multiline = true; ///< 输入框是否可以多行。
181 Ref<bool> insert = true; ///< 插入或覆盖字符模式。
182
183 /// 当内容改变时调用。
184 std::function<void()> on_change = [] {};
185 /// 当用户按下回车键时调用。
186 std::function<void()> on_enter = [] {};
187
188 // 光标的字符位置:
190};
191
192/// @brief Radiobox 组件的选项。
193/// @ingroup component
195 // 标准构造函数:
196 static RadioboxOption Simple();
197
198 // 内容:
201
202 // 样式:
203 std::function<Element(const EntryState&)> transform;
204
205 // 观察者:
206 /// 当选中条目改变时调用。
207 std::function<void()> on_change = [] {};
209};
210
217 : 10;
218 std::function<Element()> separator_func = [] { return ::ftxui::separator(); };
219
220 // Constraints on main_size:
222 Ref<int> max = std::numeric_limits<int>::max();
223};
224
225// @brief `Slider` 组件的选项。
226// @ingroup component
227template <typename T>
238
239/// @brief 传递给 `Window` 组件渲染函数的 State。
240/// @ingroup component
242 Element inner; ///< 包装在此窗口内的元素。
243 const std::string& title; ///< 窗口的标题。
244 bool active = false; ///< 窗口是否为活动状态。
245 bool drag = false; ///< 窗口是否正在被拖动。
246 bool resize = false; ///< 窗口是否正在被调整大小。
247 bool hover_left = false; ///< 可调整大小的左侧是否被悬停。
248 bool hover_right = false; ///< 可调整大小的右侧是否被悬停。
249 bool hover_top = false; ///< 可调整大小的顶部是否被悬停。
250 bool hover_down = false; ///< 可调整大小的底部是否被悬停。
251};
252
253// @brief `Window` 组件的选项。
254// @ingroup component
256 Component inner; ///< 此窗口包装的组件。
257 ConstStringRef title = ""; ///< 此窗口显示的标题。
258
259 Ref<int> left = 0; ///< 窗口的左侧位置。
260 Ref<int> top = 0; ///< 窗口的顶部位置。
261 Ref<int> width = 20; ///< 窗口的宽度。
262 Ref<int> height = 10; ///< 窗口的高度。
263
264 Ref<bool> resize_left = true; ///< 左侧是否可以调整大小?
265 Ref<bool> resize_right = true; ///< 右侧是否可以调整大小?
266 Ref<bool> resize_top = true; ///< 顶部是否可以调整大小?
267 Ref<bool> resize_down = true; ///< 底部是否可以调整大小?
268
269 /// 用于自定义窗口外观的可选函数:
270 std::function<Element(const WindowRenderState&)> render;
271};
272
273/// @brief Dropdown 组件的选项。
274/// @ingroup component
275/// 下拉菜单是打开/关闭单选框的复选框。
277 /// 下拉菜单是打开还是关闭:
279 // 复选框的选项:
281 // 单选框的选项:
283 // 转换函数:
284 std::function<Element(bool open, Element checkbox, Element radiobox)>
286};
287
288} // namespace ftxui
289
290#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_OPTIONS_HPP */
一个适配器。拥有或引用一个不可变对象。
定义 ref.hpp:17
一个适配器。引用一个字符串列表。
一个适配器。拥有或引用一个常量字符串。为了方便,这个 类将多个不可变字符串转换为共享表示。
定义 ref.hpp:94
一个适配器。拥有或引用一个可变对象。
定义 ref.hpp:46
一个适配器。拥有或引用一个常量字符串。为了方便,这个 类将多个可变字符串转换为共享表示。
定义 ref.hpp:82
static ButtonOption Animated()
创建一个使用动画颜色的ButtonOption。
bool active
窗口是否为活动状态。
std::function< void()> on_click
std::function< Element()> elements_prefix
static MenuOption Toggle()
带有分隔符的水平菜单的标准选项。 这对于实现选项卡栏非常有用。
animation::Duration follower_duration
animation::easing::Function leader_function
bool drag
窗口是否正在被拖动。
static InputOption Default()
创建默认输入样式:
animation::easing::Function function
static ButtonOption Border()
创建一个ButtonOption。按钮使用边框显示,聚焦时反转。这是当前的默认值。
bool hover_down
可调整大小的底部是否被悬停。
const std::string & title
窗口的标题。
void SetAnimationFunction(animation::easing::Function f)
设置下划线应如何动画。
static InputOption Spacious()
带有大边距的白底黑字样式:
Ref< bool > insert
插入或覆盖字符模式。
static CheckboxOption Simple()
标准Checkbox的选项。
bool resize
窗口是否正在被调整大小。
std::function< void()> on_enter
Element inner
包装在此窗口内的元素。
static ButtonOption Simple()
创建一个ButtonOption,聚焦时反转显示。
std::function< Element(const EntryState &state)> transform
static MenuOption Horizontal()
水平菜单的标准选项。 这对于实现选项卡栏非常有用。
static MenuOption VerticalAnimated()
动画垂直菜单的标准选项。 这对于实现可选择项目列表非常有用。
animation::Duration leader_duration
static MenuOption Vertical()
垂直菜单的标准选项。 这对于实现可选择项目列表非常有用。
static ButtonOption Ascii()
创建一个ButtonOption,使用[]字符高亮显示。
void SetAnimation(animation::Duration d, animation::easing::Function f)
设置下划线应如何动画。
void SetAnimationDuration(animation::Duration d)
设置下划线应如何动画。
animation::easing::Function follower_function
bool hover_right
可调整大小的右侧是否被悬停。
Ref< bool > password
使用 '*' 遮盖输入内容。
std::function< Element(InputState)> transform
std::function< Element()> elements_infix
Ref< bool > open
下拉菜单是打开还是关闭:
StringRef placeholder
当输入框为空时显示的内容。
std::function< Element()> elements_postfix
AnimatedColorsOption animated_colors
bool hover_left
可调整大小的左侧是否被悬停。
std::function< void()> on_change
StringRef content
输入框的内容。
bool hover_top
可调整大小的顶部是否被悬停。
void Set(Color inactive, Color active, animation::Duration duration=std::chrono::milliseconds(250), animation::easing::Function function=animation::easing::QuadraticInOut)
一个可动画的颜色选项。 @params _inactive 当组件不活动时的颜色。 @params _active 当组件活动时的颜色。 @params _duration 动画的持续时间。 @para...
std::function< Element(bool open, Element checkbox, Element radiobox)> transform
static MenuOption HorizontalAnimated()
动画水平菜单的标准选项。 这对于实现选项卡栏非常有用。
Ref< bool > multiline
输入框是否可以多行。
static RadioboxOption Simple()
标准Radiobox的选项
std::function< Element(const EntryState &)> transform
可能是动画颜色的选项。
AnimatedButton 组件的选项。
Checkbox 组件的选项。
Dropdown 组件的选项。下拉菜单是打开/关闭单选框的复选框。
Input 组件的选项。
MenuEntry 组件的选项。
Menu 组件的选项。
Radiobox 组件的选项。
下划线效果的选项。
传递给 Window 组件渲染函数的 State。
Direction
Direction 是一个枚举,表示四个基本方向。
Color 是一个表示终端用户界面中颜色的类。
std::function< float(float)> Function
std::chrono::duration< float > Duration
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
std::shared_ptr< Node > Element
std::shared_ptr< ComponentBase > Component
来自 |ButtonOption|、|CheckboxOption|、 |RadioboxOption|、|MenuEntryOption|、|MenuOption| 的转换参数。
bool active
条目是否为活动状态。
std::string label
要显示的标签。
bool focused
条目是否被用户聚焦。
int index
适用时为条目的索引,否则为 -1。
bool state
按钮/复选框/单选框的状态
用于定义 Input 组件的样式。
bool focused
输入框是否被用户聚焦。
bool hovered
输入框是否被鼠标悬停。
bool is_placeholder
输入框是否为空并显示占位符。
std::function< Element()> separator_func
std::function< void()> on_change
Ref< bool > resize_down
底部是否可以调整大小?
Component inner
此窗口包装的组件。
Ref< bool > resize_left
左侧是否可以调整大小?
Ref< int > height
窗口的高度。
Ref< bool > resize_top
顶部是否可以调整大小?
Ref< int > width
窗口的宽度。
std::function< Element(const WindowRenderState &)> render
用于自定义窗口外观的可选函数:
ConstStringRef title
此窗口显示的标题。
Ref< bool > resize_right
右侧是否可以调整大小?
Ref< int > left
窗口的左侧位置。
Ref< int > top
窗口的顶部位置。