18class CheckboxBase :
public ComponentBase {
20 CheckboxBase(ConstStringRef label,
bool* state, Ref<CheckboxOption> option)
21 : label_(std::move(label)), state_(state), option_(std::move(option)) {}
26 bool is_focused = Focused();
27 bool is_active = Active();
29 auto state = EntryState{
33 is_focused || hovered_,
36 (option_->transform ? option_->transform
38 return element | focus_management |
reflect(box_);
41 bool OnEvent(Event event)
override {
42 if (!CaptureMouse(event)) {
46 if (event.is_mouse()) {
47 return OnMouseEvent(event);
51 if (event == Event::Character(
' ') || event ==
Event::Return) {
60 bool OnMouseEvent(Event event) {
61 hovered_ = box_.Contain(event.mouse().x, event.mouse().y);
63 if (!CaptureMouse(event)) {
81 bool Focusable() const final {
return true; }
83 ConstStringRef label_;
85 bool hovered_ =
false;
86 Ref<CheckboxOption> option_;
An adapter. Own or reference a constant string. For convenience, this class convert multiple immutabl...
An adapter. Own or reference an mutable object.
Component Checkbox(ConstStringRef label, bool *checked, Ref< CheckboxOption > option=CheckboxOption::Simple())
Draw checkable element.
Element nothing(Element element)
A decoration doing absolutely nothing.
std::shared_ptr< T > Make(Args &&... args)
std::shared_ptr< Node > Element
Decorator reflect(Box &box)
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
std::shared_ptr< ComponentBase > Component
static CheckboxOption Simple()
Option for standard Checkbox.
std::function< Element(const EntryState &)> transform
static const Event Return