mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-28 16:29:34 +08:00
feat: Dropdown select menu. (#214)
Dom - `vscroll_indicator`. Show a scrollback indicator on the right. Component - `Maybe`: Display an component conditionnally based on a boolean. - `Dropdown`: A dropdown select list. This address: https://github.com/ArthurSonzogni/FTXUI/issues/204
This commit is contained in:
31
src/ftxui/component/maybe.cpp
Normal file
31
src/ftxui/component/maybe.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "ftxui/component/component.hpp"
|
||||
#include "ftxui/component/component_base.hpp"
|
||||
#include "ftxui/component/event.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
Component Maybe(Component child, bool* show) {
|
||||
class Impl : public ComponentBase {
|
||||
public:
|
||||
Impl(bool* show): show_(show) {}
|
||||
|
||||
private:
|
||||
Element Render() override {
|
||||
return *show_ ? ComponentBase::Render() : std::make_unique<Node>();
|
||||
}
|
||||
bool Focusable() const override {
|
||||
return *show_ && ComponentBase::Focusable();
|
||||
}
|
||||
bool OnEvent(Event event) override {
|
||||
return *show_ && ComponentBase::OnEvent(event);
|
||||
}
|
||||
|
||||
bool* show_;
|
||||
};
|
||||
|
||||
auto maybe = Make<Impl>(show);
|
||||
maybe->Add(std::move(child));
|
||||
return maybe;
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
Reference in New Issue
Block a user