mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-05-06 09:13:48 +08:00
55 lines
1.4 KiB
C++
55 lines
1.4 KiB
C++
![]() |
#include "ftxui/component/component.hpp"
|
||
|
#include "ftxui/component/component_base.hpp"
|
||
|
#include "ftxui/component/event.hpp"
|
||
|
|
||
|
namespace ftxui {
|
||
|
|
||
|
Component Dropdown(ConstStringListRef entries, int* selected) {
|
||
|
class Impl : public ComponentBase {
|
||
|
public:
|
||
|
Impl(ConstStringListRef entries, int* selected)
|
||
|
: entries_(std::move(entries)), selected_(selected) {
|
||
|
CheckboxOption option;
|
||
|
option.style_checked = "↓│";
|
||
|
option.style_unchecked = "→│";
|
||
|
checkbox_ = Checkbox(&title_, &show_, option),
|
||
|
radiobox_ = Radiobox(entries_, selected_);
|
||
|
|
||
|
Add(Container::Vertical({
|
||
|
checkbox_,
|
||
|
Maybe(radiobox_, &show_),
|
||
|
}));
|
||
|
}
|
||
|
|
||
|
Element Render() override {
|
||
|
title_ = entries_[*selected_];
|
||
|
if (show_) {
|
||
|
return vbox({
|
||
|
checkbox_->Render(),
|
||
|
separator(),
|
||
|
radiobox_->Render() | vscroll_indicator | frame |
|
||
|
size(HEIGHT, LESS_THAN, 12),
|
||
|
}) |
|
||
|
border;
|
||
|
}
|
||
|
|
||
|
return vbox({
|
||
|
checkbox_->Render() | border,
|
||
|
filler(),
|
||
|
});
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
ConstStringListRef entries_;
|
||
|
bool show_ = false;
|
||
|
int* selected_;
|
||
|
std::string title_;
|
||
|
Component checkbox_;
|
||
|
Component radiobox_;
|
||
|
};
|
||
|
|
||
|
return Make<Impl>(std::move(entries), selected);
|
||
|
}
|
||
|
|
||
|
} // namespace ftxui
|