FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
input_style.cpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// 本原始碼的使用受 MIT 授權條款約束,該條款可在 LICENSE 檔案中找到。
3#include <ftxui/dom/linear_gradient.hpp> // for LinearGradient
4#include <ftxui/screen/color.hpp> // for Color, Color::White, Color::Red, Color::Blue, Color::Black, Color::GrayDark, ftxui
5#include <functional> // for function
6#include <string> // for allocator, string
7#include <utility> // for move
8
9#include "ftxui/component/component.hpp" // for Input, Horizontal, Vertical, operator|
10#include "ftxui/component/component_base.hpp" // for Component
11#include "ftxui/component/component_options.hpp" // for InputState, InputOption
12#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
13#include "ftxui/dom/elements.hpp" // for operator|=, Element, bgcolor, operator|, separatorEmpty, color, borderEmpty, separator, text, center, dim, hbox, vbox, border, borderDouble, borderRounded
14
15int main() {
16 using namespace ftxui;
17
18 InputOption style_1 = InputOption::Default();
19
20 InputOption style_2 = InputOption::Spacious();
21
22 InputOption style_3 = InputOption::Spacious();
23 style_3.transform = [](InputState state) {
24 state.element |= borderEmpty;
25
26 if (state.is_placeholder) {
27 state.element |= dim;
28 }
29
30 if (state.focused) {
31 state.element |= borderDouble;
32 state.element |= bgcolor(Color::White);
33 state.element |= color(Color::Black);
34 } else if (state.hovered) {
35 state.element |= borderRounded;
36 state.element |= bgcolor(LinearGradient(90, Color::Blue, Color::Red));
37 state.element |= color(Color::White);
38 } else {
39 state.element |= border;
40 state.element |= bgcolor(LinearGradient(0, Color::Blue, Color::Red));
41 state.element |= color(Color::White);
42 }
43
44 return state.element;
45 };
46
47 InputOption style_4 = InputOption::Spacious();
48 style_4.transform = [](InputState state) {
49 state.element = hbox({
50 text("Theorem") | center | borderEmpty | bgcolor(Color::Red),
51 separatorEmpty(),
52 separator() | color(Color::White),
53 separatorEmpty(),
54 std::move(state.element),
55 });
56
57 state.element |= borderEmpty;
58 if (state.is_placeholder) {
59 state.element |= dim;
60 }
61
62 if (state.focused) {
63 state.element |= bgcolor(Color::Black);
64 } else {
65 state.element |= bgcolor(Color::Blue);
66 }
67
68 if (state.hovered) {
69 state.element |= bgcolor(Color::GrayDark);
70 }
71
72 return vbox({state.element, separatorEmpty()});
73 };
74
75 auto generateUiFromStyle = [&](InputOption style) {
76 auto first_name = new std::string(); // 記憶體洩漏
77 auto middle_name = new std::string(); // 記憶體洩漏
78 auto last_name = new std::string(); // 記憶體洩漏
79 return Container::Vertical({
80 Input(first_name, "first name", style),
81 Input(middle_name, "middle name", style),
82 Input(last_name, "last name", style),
83 }) |
84 borderEmpty;
85 };
86
87 auto ui = Container::Horizontal({
88 generateUiFromStyle(style_1),
89 generateUiFromStyle(style_2),
90 generateUiFromStyle(style_3),
91 generateUiFromStyle(style_4),
92 });
93
94 auto screen = ScreenInteractive::TerminalOutput();
95 screen.Loop(ui);
96}
std::function< Element(InputState)> transform
Input 元件的選項。
表示線性漸變顏色效果設定的類別。
int main()
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
用於定義 Input 元件的樣式。