18class CheckboxBase :
public ComponentBase {
20 CheckboxBase(ConstStringRef label,
bool* state, Ref<CheckboxOption> option)
21 : label_(label), state_(state), option_(std::move(option)) {
22#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
25 if (option_->style_checked ==
"▣ ")
26 option_->style_checked =
"[X]";
27 if (option_->style_unchecked ==
"☐ ")
28 option_->style_unchecked =
"[ ]";
35 bool is_focused = Focused();
36 bool is_active = Active();
37 auto style = (is_focused || hovered_) ? option_->style_selected_focused
38 : is_active ? option_->style_selected
39 : option_->style_normal;
42 text(*state_ ? option_->style_checked
43 : option_->style_unchecked),
44 text(*label_) | style | focus_management,
49 bool OnEvent(Event event)
override {
50 if (!CaptureMouse(event))
54 return OnMouseEvent(event);
57 if (event == Event::Character(
' ') || event ==
Event::Return) {
66 bool OnMouseEvent(Event event) {
67 hovered_ = box_.Contain(event.mouse().x, event.mouse().y);
69 if (!CaptureMouse(event))
85 bool Focusable() const final {
return true; }
87 ConstStringRef label_;
89 bool hovered_ =
false;
90 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={})
Draw checkable element.
Element nothing(Element element)
A decoration doing absolutely nothing.
std::shared_ptr< T > Make(Args &&... args)
std::shared_ptr< Node > Element
Element hbox(Elements)
A container displaying elements horizontally one by one.
Element text(std::wstring text)
Display a piece of unicode text.
Decorator reflect(Box &box)
void Render(Screen &screen, const Element &node)
Display an element on a ftxui::Screen.
std::shared_ptr< ComponentBase > Component
static const Event Return