FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
component_options.hpp
Go to the documentation of this file.
1// Copyright 2021 Arthur Sonzogni. 保留所有權利。
2// 此原始碼的使用受 MIT 授權條款約束,詳情請參閱
3// LICENSE 文件。
4#ifndef FTXUI_COMPONENT_COMPONENT_OPTIONS_HPP
5#define FTXUI_COMPONENT_COMPONENT_OPTIONS_HPP
6
7#include <chrono> // for milliseconds
8#include <ftxui/component/animation.hpp> // for Duration, QuadraticInOut, Function
9#include <ftxui/dom/direction.hpp> // for Direction, Direction::Left, Direction::Right, Direction::Down
10#include <ftxui/dom/elements.hpp> // for Element, separator
11#include <ftxui/util/ref.hpp> // for Ref, ConstRef, StringRef
13#include <functional> // for function
14#include <limits> // for numeric_limits
15#include <string> // for string
16
17#include "ftxui/component/component_base.hpp" // for Component
18#include "ftxui/screen/color.hpp" // for Color, Color::GrayDark, Color::White
19
20namespace ftxui {
21
22/// @brief 來自 |ButtonOption|、|CheckboxOption|、
23/// |RadioboxOption|、|MenuEntryOption|、|MenuOption| 的轉換參數。
24struct EntryState {
25 std::string label; ///< 要顯示的標籤。
26 bool state; ///< 按鈕/核取方塊/單選方塊的狀態
27 bool active; ///< 條目是否為啟用狀態。
28 bool focused; ///< 條目是否為使用者焦點。
29 int index; ///< 條目的索引(如果適用),否則為 -1。
30};
31
32/// @brief 底線效果的選項。
33/// @ingroup component
56
57/// @brief 關於潛在動畫顏色的選項。
58/// @ingroup component
60 void Set(
63 animation::Duration duration = std::chrono::milliseconds(250),
64 animation::easing::Function function = animation::easing::QuadraticInOut);
65
66 bool enabled = false;
69 animation::Duration duration = std::chrono::milliseconds(250);
71};
72
77
78/// @brief MenuEntry 元件的選項。
79/// @ingroup component
85
86/// @brief Menu 元件的選項。
87/// @ingroup component
88struct MenuOption {
89 // 標準建構函式:
90 static MenuOption Horizontal();
92 static MenuOption Vertical();
94 static MenuOption Toggle();
95
96 ConstStringListRef entries; ///> 條目列表。
97 Ref<int> selected = 0; ///> 所選條目的索引。
98
99 // 樣式:
103 std::function<Element()> elements_prefix;
104 std::function<Element()> elements_infix;
105 std::function<Element()> elements_postfix;
106
107 // 觀察者:
108 std::function<void()> on_change; ///> 當所選條目變更時呼叫。
109 std::function<void()> on_enter; ///> 當使用者按下 Enter 鍵時呼叫。
111};
112
113/// @brief AnimatedButton 元件的選項。
114/// @ingroup component
116 // 標準建構函式:
117 static ButtonOption Ascii();
118 static ButtonOption Simple();
119 static ButtonOption Border();
120 static ButtonOption Animated();
121 static ButtonOption Animated(Color color);
122 static ButtonOption Animated(Color background, Color foreground);
123 static ButtonOption Animated(Color background,
124 Color foreground,
125 Color background_active,
126 Color foreground_active);
127
129 std::function<void()> on_click = [] {};
130
131 // 樣式:
132 std::function<Element(const EntryState&)> transform;
134};
135
136/// @brief 核取方塊元件的選項。
137/// @ingroup component
139 // 標準建構函式:
140 static CheckboxOption Simple();
141
142 ConstStringRef label = "Checkbox";
143
145
146 // 樣式:
147 std::function<Element(const EntryState&)> transform;
148
149 // 觀察者:
150 /// 當使用者變更狀態時呼叫。
151 std::function<void()> on_change = [] {};
152};
153
154/// @brief 用於定義 Input 元件的樣式。
157 bool hovered; ///< 輸入框是否被滑鼠懸停。
158 bool focused; ///< 輸入框是否被使用者聚焦。
159 bool is_placeholder; ///< 輸入框是否為空並顯示
160 ///< 佔位符。
161};
162
163/// @brief Input 元件的選項。
164/// @ingroup component
166 // 一組預定義的樣式:
167
168 /// @brief 建立預設輸入樣式:
169 static InputOption Default();
170 /// @brief 具有高邊距的黑底白字樣式:
171 static InputOption Spacious();
172
173 /// 輸入框的內容。
175
176 /// 輸入框為空時的內容。
178
179 // 樣式:
180 std::function<Element(InputState)> transform;
181 Ref<bool> password = false; ///< 使用 '*' 隱藏輸入內容。
182 Ref<bool> multiline = true; ///< 輸入框是否可以是多行。
183 Ref<bool> insert = true; ///< 插入或覆蓋字元模式。
184
185 /// 當內容變更時呼叫。
186 std::function<void()> on_change = [] {};
187 /// 當使用者按下 Enter 鍵時呼叫。
188 std::function<void()> on_enter = [] {};
189
190 // 游標的字元位置:
192};
193
194/// @brief Radiobox 元件的選項。
195/// @ingroup component
197 // 標準建構函式:
198 static RadioboxOption Simple();
199
200 // 內容:
203
204 // 樣式:
205 std::function<Element(const EntryState&)> transform;
206
207 // 觀察者:
208 /// 當所選條目變更時呼叫。
209 std::function<void()> on_change = [] {};
211};
212
219 : 10;
220 std::function<Element()> separator_func = [] { return ::ftxui::separator(); };
221
222 // Constraints on main_size:
224 Ref<int> max = std::numeric_limits<int>::max();
225};
226
227// @brief `Slider` 元件的選項。
228// @ingroup component
229template <typename T>
240
241/// @brief 傳遞給 `Window` 元件渲染函式的狀態。
242/// @ingroup component
244 Element inner; ///< 視窗內包裝的元素。
245 const std::string& title; ///< 視窗的標題。
246 bool active = false; ///< 視窗是否為啟用狀態。
247 bool drag = false; ///< 視窗是否正在被拖曳。
248 bool resize = false; ///< 視窗是否正在被調整大小。
249 bool hover_left = false; ///< 可調整大小的左側是否被懸停。
250 bool hover_right = false; ///< 可調整大小的右側是否被懸停。
251 bool hover_top = false; ///< 可調整大小的頂部是否被懸停。
252 bool hover_down = false; ///< 可調整大小的底部是否被懸停。
253};
254
255// @brief `Window` 元件的選項。
256// @ingroup component
258 Component inner; ///< 此視窗包裝的元件。
259 ConstStringRef title = ""; ///< 此視窗顯示的標題。
260
261 Ref<int> left = 0; ///< 視窗的左側位置。
262 Ref<int> top = 0; ///< 視窗的頂部位置。
263 Ref<int> width = 20; ///< 視窗的寬度。
264 Ref<int> height = 10; ///< 視窗的高度。
265
266 Ref<bool> resize_left = true; ///< 左側是否可調整大小?
267 Ref<bool> resize_right = true; ///< 右側是否可調整大小?
268 Ref<bool> resize_top = true; ///< 頂部是否可調整大小?
269 Ref<bool> resize_down = true; ///< 底部是否可調整大小?
270
271 /// 用於自訂視窗外觀的選用函式:
272 std::function<Element(const WindowRenderState&)> render;
273};
274
275/// @brief Dropdown 元件的選項。
276/// @ingroup component
277/// 下拉式選單是開啟/關閉單選方塊的核取方塊。
279 /// 下拉式選單是開啟還是關閉:
281 // 核取方塊的選項:
283 // 單選方塊的選項:
285 // 轉換函式:
286 std::function<Element(bool open, Element checkbox, Element radiobox)>
288};
289
290} // namespace ftxui
291
292#endif /* end of include guard: FTXUI_COMPONENT_COMPONENT_OPTIONS_HPP */
一個適配器。擁有或引用一個不可變的物件。
Definition ref.hpp:17
一個適配器。引用一個字串列表。
Definition ref.hpp:114
一個適配器。擁有或引用一個常數字串。為方便起見,此類別將多個不可變字串轉換為共享表示。
Definition ref.hpp:92
一個適配器。擁有或引用一個可變的物件。
Definition ref.hpp:46
一個適配器。擁有或引用一個常數字串。為方便起見,此類別將多個可變字串轉換為共享表示。
Definition ref.hpp:81
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
MenuEntryOption entries_option
bool drag
視窗是否正在被拖曳。
static InputOption Default()
建立預設輸入樣式:
animation::easing::Function function
animation::Duration follower_delay
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,在聚焦時反轉。
UnderlineOption underline
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)
設定下劃線的動畫方式。
ConstStringListRef entries
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 動畫的持續時間。 @params...
animation::Duration leader_delay
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 元件的選項。
核取方塊元件的選項。
Dropdown 元件的選項。下拉式選單是開啟/關閉單選方塊的核取方塊。
Input 元件的選項。
MenuEntry 元件的選項。
Menu 元件的選項。
Radiobox 元件的選項。
底線效果的選項。
傳遞給 Window 元件渲染函式的狀態。
Direction
Direction 是一個列舉,表示四個主要方向。
Definition direction.hpp:12
Color 是一個在終端使用者介面中表示顏色的類別。
Definition color.hpp:20
float QuadraticInOut(float p)
Definition animation.cpp:44
std::function< float(float)> Function
Definition animation.hpp:40
std::chrono::duration< float > Duration
Definition animation.hpp:25
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
std::shared_ptr< Node > Element
Definition elements.hpp:22
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
輸入框是否被滑鼠懸停。
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
視窗的頂部位置。