FTXUI  0.10.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
dropdown.cpp
Go to the documentation of this file.
4
5namespace ftxui {
6
7Component Dropdown(ConstStringListRef entries, int* selected) {
8 class Impl : public ComponentBase {
9 public:
10 Impl(ConstStringListRef entries, int* selected)
11 : entries_(std::move(entries)), selected_(selected) {
12 CheckboxOption option;
13 option.style_checked = "↓│";
14 option.style_unchecked = "→│";
15 checkbox_ = Checkbox(&title_, &show_, option),
16 radiobox_ = Radiobox(entries_, selected_);
17
18 Add(Container::Vertical({
19 checkbox_,
20 Maybe(radiobox_, &show_),
21 }));
22 }
23
24 Element Render() override {
25 title_ = entries_[*selected_];
26 if (show_) {
27 return vbox({
28 checkbox_->Render(),
29 separator(),
30 radiobox_->Render() | vscroll_indicator | frame |
31 size(HEIGHT, LESS_THAN, 12),
32 }) |
33 border;
34 }
35
36 return vbox({
37 checkbox_->Render() | border,
38 filler(),
39 });
40 }
41
42 private:
43 ConstStringListRef entries_;
44 bool show_ = false;
45 int* selected_;
46 std::string title_;
47 Component checkbox_;
48 Component radiobox_;
49 };
50
51 return Make<Impl>(std::move(entries), selected);
52}
53
54} // namespace ftxui
It implement rendering itself as ftxui::Element. It implement keyboard navigation by responding to ft...
An adapter. Reference a list of strings.
Definition ref.hpp:94
Component Checkbox(ConstStringRef label, bool *checked, Ref< CheckboxOption > option={})
Draw checkable element.
Definition checkbox.cpp:117
Component Radiobox(ConstStringListRef entries, int *selected_, Ref< RadioboxOption > option={})
A list of element, where only one can be selected.
Definition radiobox.cpp:190
std::string style_unchecked
Prefix for a "unchecked" state.
Element vscroll_indicator(Element)
Add a filter that will invert the foreground and the background colors.
@ HEIGHT
Definition elements.hpp:90
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:25
std::shared_ptr< Node > Element
Definition elements.hpp:15
std::string style_checked
Prefix for a "checked" state.
Element separator(void)
Definition separator.cpp:61
Component Dropdown(ConstStringListRef entries, int *selected)
Definition dropdown.cpp:7
Element filler()
An element that will take expand proportionnally to the space left in a container.
Definition flex.cpp:94
Element frame(Element)
Allow an element to be displayed inside a 'virtual' area. It size can be larger than its container....
Definition frame.cpp:138
void Render(Screen &screen, const Element &node)
Display an element on a ftxui::Screen.
Definition node.cpp:34
Decorator size(Direction, Constraint, int value)
Apply a constraint on the size of an element.
Definition size.cpp:86
@ LESS_THAN
Definition elements.hpp:91
Element border(Element)
Draw a border around the element.
Definition border.cpp:148
std::shared_ptr< ComponentBase > Component
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition vbox.cpp:77
Option for the Checkbox component.
Component Maybe(Component child, bool *show)
Definition show.cpp:3