18 class 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 : option_->style_selected)
39 : (hovered_ ? option_->style_focused
40 : option_->style_normal);
42 return hbox(
text(*state_ ? option_->style_checked
43 : option_->style_unchecked),
44 text(*label_) | style | focus_management) |
48 bool OnEvent(Event event)
override {
50 return OnMouseEvent(event);
61 bool OnMouseEvent(Event event) {
62 hovered_ = box_.Contain(event.mouse().x, event.mouse().y);
64 if (!CaptureMouse(event))
80 bool Focusable() const final {
return true; }
82 ConstStringRef label_;
84 bool hovered_ =
false;
85 Ref<CheckboxOption> option_;
115 return Make<CheckboxBase>(label, checked, std::move(option));