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_()];
61 if (open_() && !Focused()) {
62 container_->SetActiveChild(checkbox_);
66 return transform(*open_, checkbox_->Render(), radiobox_->Render());
70 bool OnEvent(ftxui::Event event)
override {
71 const bool open_old = open_();
72 const int selected_old = selected_();
73 bool handled = ComponentBase::OnEvent(event);
76 if (!open_old && open_()) {
77 radiobox_->TakeFocus();
81 if (open_old && open_()) {
82 const bool should_close =
83 (selected_() != selected_old) ||
84 (event == Event::Return) ||
85 (
event == Event::Character(
' ')) ||
86 (event == Event::Escape) ||
87 (
event.is_mouse() && event.mouse().button == Mouse::Left &&
88 event.mouse().motion == Mouse::Pressed);
91 checkbox_->TakeFocus();
101 open_ = checkbox.checked;
102 selected_ = radiobox.selected;
103 checkbox.checked = &*open_;
104 radiobox.selected = &*selected_;
105 checkbox.label = &title_;
107 if (!checkbox.transform) {
108 checkbox.transform = [](
const EntryState& s) {
109 auto prefix = text(s.state ?
"↓ " :
"→ ");
110 auto t = text(s.label);
117 return hbox({prefix, t});
122 transform = [](
bool is_open,
Element checkbox_element,
125 const int max_height = 12;
127 std::move(checkbox_element),
129 std::move(radiobox_element) | vscroll_indicator | frame |
134 return vbox({std::move(checkbox_element), filler()}) | border;