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();
82 if (open_old && open_()) {
83 const bool should_close =
84 (selected_() != selected_old) ||
85 (event == Event::Return) ||
86 (
event == Event::Character(
' ')) ||
87 (event == Event::Escape) ||
88 (
event.is_mouse() && event.mouse().button == Mouse::Left &&
89 event.mouse().motion == Mouse::Pressed);
92 checkbox_->TakeFocus();
102 open_ = checkbox.checked;
103 selected_ = radiobox.selected;
104 checkbox.checked = &*open_;
105 radiobox.selected = &*selected_;
106 checkbox.label = &title_;
108 if (!checkbox.transform) {
109 checkbox.transform = [](
const EntryState& s) {
110 auto prefix = text(s.state ?
"↓ " :
"→ ");
111 auto t = text(s.label);
118 return hbox({prefix, t});
123 transform = [](
bool is_open,
Element checkbox_element,
126 const int max_height = 12;
128 std::move(checkbox_element),
130 std::move(radiobox_element) | vscroll_indicator | frame |
135 return vbox({std::move(checkbox_element), filler()}) | border;