FTXUI 6.1.9 C++ functional terminal UI.

Loading...
Searching...
No Matches
dropdown_custom.cpp
Go to the documentation of this file.
1// Copyright 2020 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.
4#include <string> // for basic_string, string, allocator
5#include <vector> // for vector
6
7#include "ftxui/component/captured_mouse.hpp" // for ftxui
8#include "ftxui/component/component.hpp" // for Dropdown, Horizontal, Vertical
9#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
10
11 int main() {
12 using namespace ftxui;
13
14 std::vector<std::string> entries = {
15 "tribute", "clearance", "ally", "bend", "electronics",
16 "module", "era", "cultural", "sniff", "nationalism",
17 "negotiation", "deliver", "figure", "east", "tribute",
18 "clearance", "ally", "bend", "electronics", "module",
19 "era", "cultural", "sniff", "nationalism", "negotiation",
20 "deliver", "figure", "east", "tribute", "clearance",
21 "ally", "bend", "electronics", "module", "era",
22 "cultural", "sniff", "nationalism", "negotiation", "deliver",
23 "figure", "east",
24 };
25
26 auto dropdown_1 = Dropdown({
27 .radiobox = {.entries = &entries},
28 .transform =
29 [](bool open, Element checkbox, Element radiobox) {
30 if (open) {
31 return vbox({
32 checkbox | inverted,
33 radiobox | vscroll_indicator | frame |
34 size(HEIGHT, LESS_THAN, 10),
35 filler(),
36 });
37 }
38 return vbox({
39 checkbox,
40 filler(),
41 });
42 },
43 });
44
45 auto dropdown_2 = Dropdown({
46 .radiobox = {.entries = &entries},
47 .transform =
48 [](bool open, Element checkbox, Element radiobox) {
49 if (open) {
50 return vbox({
51 checkbox | inverted,
52 radiobox | vscroll_indicator | frame |
53 size(HEIGHT, LESS_THAN, 10) | bgcolor(Color::Blue),
54 filler(),
55 });
56 }
57 return vbox({
58 checkbox | bgcolor(Color::Blue),
59 filler(),
60 });
61 },
62 });
63
64 auto dropdown_3 = Dropdown({
65 .radiobox =
66 {
67 .entries = &entries,
68 .transform =
69 [](const EntryState& s) {
70 auto t = text(s.label) | borderEmpty;
71 if (s.active) {
72 t |= bold;
73 }
74 if (s.focused) {
75 t |= inverted;
76 }
77 return t;
78 },
79 },
80 .transform =
81 [](bool open, Element checkbox, Element radiobox) {
82 checkbox |= borderEmpty;
83 if (open) {
84 return vbox({
85 checkbox | inverted,
86 radiobox | vscroll_indicator | frame |
87 size(HEIGHT, LESS_THAN, 20) | bgcolor(Color::Red),
88 filler(),
89 });
90 }
91 return vbox({
92 checkbox | bgcolor(Color::Red),
93 filler(),
94 });
95 },
96 });
97
98 auto screen = ScreenInteractive::FitComponent();
99 screen.Loop(Container::Horizontal({
100 dropdown_1,
101 dropdown_2,
102 dropdown_3,
103 }));
104}
captured_mouse.hpp
component.hpp
main
int main()
Definition dropdown_custom.cpp:11
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
ftxui::Element
std::shared_ptr< Node > Element
Definition elements.hpp:22
screen_interactive.hpp
ftxui::EntryState
arguments for transform from |ButtonOption|, |CheckboxOption|, |RadioboxOption|, |MenuEntryOption|,...
Definition component_options.hpp:22