FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
component_options.cpp
Go to the documentation of this file.
1// Copyright 2022 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
5
6#include <ftxui/screen/color.hpp> // for Color, Color::White, Color::Black, Color::GrayDark, Color::Blue, Color::GrayLight, Color::Red
7#include <memory> // for shared_ptr
8#include <utility> // for move
9#include "ftxui/component/animation.hpp" // for Function, Duration
11#include "ftxui/dom/elements.hpp" // for operator|=, Element, text, bgcolor, inverted, bold, dim, operator|, color, borderEmpty, hbox, automerge, border, borderLight
12
13namespace ftxui {
14
15/// @brief アニメーション可能なカラーオプション。
16/// @params _inactive コンポーネントが非アクティブな時の色。
17/// @params _active コンポーネントがアクティブな時の色。
18/// @params _duration アニメーションの期間。
19/// @params _function アニメーションのイージング関数。
21 Color _active,
22 animation::Duration _duration,
24 enabled = true;
25 inactive = _inactive;
26 active = _active;
27 duration = _duration;
28 function = std::move(_function);
29}
30
31/// @brief 下線のアニメーション方法を設定します。
32/// @param d アニメーションの期間。
33/// @param f アニメーションのイージング関数。
39
40/// @brief 下線のアニメーション方法を設定します。
41/// @param d アニメーションの期間。
46
47/// @brief 下線のアニメーション方法を設定します。
48/// @param f アニメーションのイージング関数。
53
54/// @brief 下線のアニメーション方法を設定します。
55/// これは、リーダーとフォロワーのアニメーションを非同期にするのに役立ちます。
56/// @param f_leader リーダーのアニメーション期間。
57/// @param f_follower フォロワーのアニメーション期間。
60 animation::easing::Function f_follower) {
61 leader_function = std::move(f_leader);
62 follower_function = std::move(f_follower);
63}
64
65/// @brief 水平メニューの標準オプション。
66/// これはタブバーの実装に役立ちます。
67// static
69 MenuOption option;
71 option.entries_option.transform = [](const EntryState& state) {
72 Element e = text(state.label);
73 if (state.focused) {
74 e |= inverted;
75 }
76 if (state.active) {
77 e |= bold;
78 }
79 if (!state.focused && !state.active) {
80 e |= dim;
81 }
82 return e;
83 };
84 option.elements_infix = [] { return text(" "); };
85
86 return option;
87}
88
89/// @brief アニメーション付き水平メニューの標準オプション。
90/// これはタブバーの実装に役立ちます。
91// static
93 auto option = Horizontal();
94 option.underline.enabled = true;
95 return option;
96}
97
98/// @brief 垂直メニューの標準オプション。
99/// これは選択可能なアイテムのリストを実装するのに役立ちます。
100// static
102 MenuOption option;
103 option.entries_option.transform = [](const EntryState& state) {
104 Element e = text((state.active ? "> " : " ") + state.label); // NOLINT
105 if (state.focused) {
106 e |= inverted;
107 }
108 if (state.active) {
109 e |= bold;
110 }
111 if (!state.focused && !state.active) {
112 e |= dim;
113 }
114 return e;
115 };
116 return option;
117}
118
119/// @brief アニメーション付き垂直メニューの標準オプション。
120/// これは選択可能なアイテムのリストを実装するのに役立ちます。
121// static
123 auto option = MenuOption::Vertical();
124 option.entries_option.transform = [](const EntryState& state) {
125 Element e = text(state.label);
126 if (state.focused) {
127 e |= inverted;
128 }
129 if (state.active) {
130 e |= bold;
131 }
132 if (!state.focused && !state.active) {
133 e |= dim;
134 }
135 return e;
136 };
137 option.underline.enabled = true;
138 return option;
139}
140
141/// @brief セパレータ付き水平メニューの標準オプション。
142/// これはタブバーの実装に役立ちます。
143// static
145 auto option = MenuOption::Horizontal();
146 option.elements_infix = [] { return text("│") | automerge; };
147 return option;
148}
149
150/// @brief []文字を使用して強調表示されるButtonOptionを作成します。
151// static
153 ButtonOption option;
154 option.transform = [](const EntryState& s) {
155 const std::string t = s.focused ? "[" + s.label + "]" //
156 : " " + s.label + " ";
157 return text(t);
158 };
159 return option;
160}
161
162/// @brief フォーカス時に反転するButtonOptionを作成します。
163// static
165 ButtonOption option;
166 option.transform = [](const EntryState& s) {
167 auto element = text(s.label) | borderLight;
168 if (s.focused) {
169 element |= inverted;
170 }
171 return element;
172 };
173 return option;
174}
175
176/// @brief ButtonOptionを作成します。ボタンはボーダーを使用して表示され、
177/// フォーカス時に反転します。これが現在のデフォルトです。
179 ButtonOption option;
180 option.transform = [](const EntryState& s) {
181 auto element = text(s.label) | border;
182 if (s.active) {
183 element |= bold;
184 }
185 if (s.focused) {
186 element |= inverted;
187 }
188 return element;
189 };
190 return option;
191}
192
193/// @brief アニメーションカラーを使用するButtonOptionを作成します。
194// static
199
200/// @brief アニメーションカラーを使用するButtonOptionを作成します。
201// static
204 Color::Interpolate(0.85F, color, Color::Black), // NOLINT
205 Color::Interpolate(0.10F, color, Color::White), // NOLINT
206 Color::Interpolate(0.10F, color, Color::Black), // NOLINT
207 Color::Interpolate(0.85F, color, Color::White)); // NOLINT
208}
209
210/// @brief アニメーションカラーを使用するButtonOptionを作成します。
211// static
213 // NOLINTBEGIN
215 /*bakground=*/background,
216 /*foreground=*/foreground,
217 /*background_active=*/foreground,
218 /*foreground_active=*/background);
219 // NOLINTEND
220}
221
222/// @brief アニメーションカラーを使用するButtonOptionを作成します。
223// static
225 Color foreground,
226 Color background_active,
227 Color foreground_active) {
228 ButtonOption option;
229 option.transform = [](const EntryState& s) {
230 auto element = text(s.label) | borderEmpty;
231 if (s.focused) {
232 element |= bold;
233 }
234 return element;
235 };
236 option.animated_colors.foreground.Set(foreground, foreground_active);
237 option.animated_colors.background.Set(background, background_active);
238 return option;
239}
240
241/// @brief 標準チェックボックスのオプション。
242// static
244 auto option = CheckboxOption();
245 option.transform = [](const EntryState& s) {
246#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
247 // Microsoft terminal do not use fonts able to render properly the default
248 // radiobox glyph.
249 auto prefix = text(s.state ? "[X] " : "[ ] "); // NOLINT
250#else
251 auto prefix = text(s.state ? "▣ " : "☐ "); // NOLINT
252#endif
253 auto t = text(s.label);
254 if (s.active) {
255 t |= bold;
256 }
257 if (s.focused) {
258 t |= inverted;
259 }
260 return hbox({prefix, t});
261 };
262 return option;
263}
264
265/// @brief 標準ラジオボックスのオプション。
266// static
268 auto option = RadioboxOption();
269 option.transform = [](const EntryState& s) {
270#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
271 // Microsoft terminal do not use fonts able to render properly the default
272 // radiobox glyph.
273 auto prefix = text(s.state ? "(*) " : "( ) "); // NOLINT
274#else
275 auto prefix = text(s.state ? "◉ " : "○ "); // NOLINT
276#endif
277 auto t = text(s.label);
278 if (s.active) {
279 t |= bold;
280 }
281 if (s.focused) {
282 t |= inverted;
283 }
284 return hbox({prefix, t});
285 };
286 return option;
287}
288
289/// @brief 入力コンポーネントの標準オプション。
290// static
292 InputOption option;
293 option.transform = [](InputState state) {
294 state.element |= color(Color::White);
295
296 if (state.is_placeholder) {
297 state.element |= dim;
298 }
299
300 if (state.focused) {
301 state.element |= inverted;
302 } else if (state.hovered) {
303 state.element |= bgcolor(Color::GrayDark);
304 }
305
306 return state.element;
307 };
308 return option;
309}
310
311/// @brief より美しい入力コンポーネントの標準オプション。
312// static
314 InputOption option;
315 option.transform = [](InputState state) {
316 state.element |= borderEmpty;
317 state.element |= color(Color::White);
318
319 if (state.is_placeholder) {
320 state.element |= dim;
321 }
322
323 if (state.focused) {
324 state.element |= bgcolor(Color::Black);
325 }
326
327 if (state.hovered) {
328 state.element |= bgcolor(Color::GrayDark);
329 }
330
331 return state.element;
332 };
333 return option;
334}
335
336} // namespace ftxui
static ButtonOption Animated()
アニメーションカラーを使用するButtonOptionを作成します。
static MenuOption Toggle()
セパレータ付き水平メニューの標準オプション。 これはタブバーの実装に役立ちます。
animation::Duration follower_duration
animation::easing::Function leader_function
MenuEntryOption entries_option
static InputOption Default()
デフォルトの入力スタイルを作成します:
animation::easing::Function function
static ButtonOption Border()
ButtonOptionを作成します。ボタンはボーダーを使用して表示され、 フォーカス時に反転します。これが現在のデフォルトです。
void SetAnimationFunction(animation::easing::Function f)
下線のアニメーション方法を設定します。
static InputOption Spacious()
余白の広い、白地に黒のスタイル:
static CheckboxOption Simple()
標準チェックボックスのオプション。
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
std::function< Element(InputState)> transform
std::function< Element()> elements_infix
AnimatedColorsOption animated_colors
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 ...
static MenuOption HorizontalAnimated()
アニメーション付き水平メニューの標準オプション。 これはタブバーの実装に役立ちます。
static RadioboxOption Simple()
標準ラジオボックスのオプション。
std::function< Element(const EntryState &)> transform
AnimatedButtonコンポーネントのオプション。
Checkboxコンポーネントのオプション。
Inputコンポーネントのオプション。
Menuコンポーネントのオプション。
Radioboxコンポーネントのオプション。
Decorator bgcolor(Color)
背景色を使用して装飾します。
Element bold(Element)
より強調したい要素に、太字フォントを使用します。
Definition bold.cpp:33
Element inverted(Element)
前景色と背景色を反転させるフィルターを追加します。
Definition inverted.cpp:32
Element text(std::wstring text)
ユニコードテキストを表示します。
Definition text.cpp:160
Element dim(Element)
強調を抑えたい要素に、明るいフォントを使用します。
Definition dim.cpp:33
Element automerge(Element child)
文字が近くの他の文字と自動的にマージされるようにします。
Definition automerge.cpp:16
Decorator color(Color)
前景色を使用して装飾します。
static Color Interpolate(float t, const Color &a, const Color &b)
Colorは、ターミナルユーザーインターフェースにおける色を表すクラスです。
Definition color.hpp:25
std::function< float(float)> Function
Definition animation.hpp:39
std::chrono::duration< float > Duration
Definition animation.hpp:24
FTXUI ftxui:: 名前空間
Definition animation.hpp:9
std::shared_ptr< Node > Element
Definition elements.hpp:21
Element borderEmpty(Element)
Element hbox(Elements)
要素を水平方向に1つずつ表示するコンテナ。
Definition hbox.cpp:93
Element border(Element)
Element borderLight(Element)
|ButtonOption|、|CheckboxOption|、|RadioboxOption|、|MenuEntryOption|、|MenuOption|からの変換の引数。
Inputコンポーネントのスタイルを定義するために使用されます。