FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
dropdown_custom.cpp
Go to the documentation of this file.
1// 版權所有 2020 Arthur Sonzogni. 保留所有權利。
2// 本原始碼受 MIT 許可證管理,詳情請參閱 LICENSE 文件。
3#include <string> // for basic_string, string, allocator
4#include <vector> // for vector
5
6#include "ftxui/component/captured_mouse.hpp" // for ftxui
7#include "ftxui/component/component.hpp" // for Dropdown, Horizontal, Vertical
8#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
9
10int main() {
11 using namespace ftxui;
12
13 std::vector<std::string> entries = {
14 "tribute", "clearance", "ally", "bend", "electronics",
15 "module", "era", "cultural", "sniff", "nationalism",
16 "negotiation", "deliver", "figure", "east", "tribute",
17 "clearance", "ally", "bend", "electronics", "module",
18 "era", "cultural", "sniff", "nationalism", "negotiation",
19 "deliver", "figure", "east", "tribute", "clearance",
20 "ally", "bend", "electronics", "module", "era",
21 "cultural", "sniff", "nationalism", "negotiation", "deliver",
22 "figure", "east",
23 };
24
25 auto dropdown_1 = Dropdown({
26 .radiobox = {.entries = &entries},
27 .transform =
28 [](bool open, Element checkbox, Element radiobox) {
29 if (open) {
30 return vbox({
31 checkbox | inverted,
32 radiobox | vscroll_indicator | frame |
33 size(HEIGHT, LESS_THAN, 10),
34 filler(),
35 });
36 }
37 return vbox({
38 checkbox,
39 filler(),
40 });
41 },
42 });
43
44 auto dropdown_2 = Dropdown({
45 .radiobox = {.entries = &entries},
46 .transform =
47 [](bool open, Element checkbox, Element radiobox) {
48 if (open) {
49 return vbox({
50 checkbox | inverted,
51 radiobox | vscroll_indicator | frame |
52 size(HEIGHT, LESS_THAN, 10) | bgcolor(Color::Blue),
53 filler(),
54 });
55 }
56 return vbox({
57 checkbox | bgcolor(Color::Blue),
58 filler(),
59 });
60 },
61 });
62
63 auto dropdown_3 = Dropdown({
64 .radiobox =
65 {
66 .entries = &entries,
67 .transform =
68 [](const EntryState& s) {
69 auto t = text(s.label) | borderEmpty;
70 if (s.active) {
71 t |= bold;
72 }
73 if (s.focused) {
74 t |= inverted;
75 }
76 return t;
77 },
78 },
79 .transform =
80 [](bool open, Element checkbox, Element radiobox) {
81 checkbox |= borderEmpty;
82 if (open) {
83 return vbox({
84 checkbox | inverted,
85 radiobox | vscroll_indicator | frame |
86 size(HEIGHT, LESS_THAN, 20) | bgcolor(Color::Red),
87 filler(),
88 });
89 }
90 return vbox({
91 checkbox | bgcolor(Color::Red),
92 filler(),
93 });
94 },
95 });
96
97 auto screen = ScreenInteractive::FitComponent();
98 screen.Loop(Container::Horizontal({
99 dropdown_1,
100 dropdown_2,
101 dropdown_3,
102 }));
103}
int main()
auto radiobox
Definition gallery.cpp:73
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
std::shared_ptr< Node > Element
Definition elements.hpp:22
來自 |ButtonOption|、|CheckboxOption|、 |RadioboxOption|、|MenuEntryOption|、|MenuOption| 的轉換參數。