34 class Impl :
public ComponentBase,
public DropdownOption {
36 explicit Impl(DropdownOption option) : DropdownOption(std::move(option)) {
38 checkbox_ = Checkbox(checkbox);
39 radiobox_ = Radiobox(radiobox);
41 container_ = Container::Vertical({
43 Maybe(radiobox_, checkbox.checked),
50 util::clamp(radiobox.selected(), 0,
int(radiobox.entries.size()) - 1);
51 selected_ = util::clamp(selected_(), 0,
int(radiobox.entries.size()) - 1);
53 if (selected_() >= 0 && selected_() <
int(radiobox.entries.size())) {
54 title_ = radiobox.entries[selected_()];
62 if (open_() && !Focused()) {
63 container_->SetActiveChild(checkbox_);
67 return transform(*open_, checkbox_->Render(), radiobox_->Render());
72 bool OnEvent(ftxui::Event event)
override {
73 const bool open_old = open_();
74 const int selected_old = selected_();
75 bool handled = ComponentBase::OnEvent(event);
78 if (!open_old && open_()) {
79 radiobox_->TakeFocus();
84 if (open_old && open_()) {
85 const bool should_close =
86 (selected_() != selected_old) ||
87 (event == Event::Return) ||
88 (
event == Event::Character(
' ')) ||
89 (event == Event::Escape) ||
90 (
event.is_mouse() && event.mouse().button == Mouse::Left &&
91 event.mouse().motion == Mouse::Pressed);
94 checkbox_->TakeFocus();
104 open_ = checkbox.checked;
105 selected_ = radiobox.selected;
106 checkbox.checked = &*open_;
107 radiobox.selected = &*selected_;
108 checkbox.label = &title_;
110 if (!checkbox.transform) {
111 checkbox.transform = [](
const EntryState& s) {
112 auto prefix = text(s.state ?
"↓ " :
"→ ");
113 auto t = text(s.label);
120 return hbox({prefix, t});
125 transform = [](
bool is_open,
Element checkbox_element,
128 const int max_height = 12;
130 std::move(checkbox_element),
132 std::move(radiobox_element) | vscroll_indicator | frame |
137 return vbox({std::move(checkbox_element), filler()}) | border;