Add mouse implementation of most components.

This commit is contained in:
ArthurSonzogni
2021-04-18 22:33:41 +02:00
parent d685a8655e
commit 890a41a64c
20 changed files with 239 additions and 12 deletions

View File

@@ -9,10 +9,14 @@ Element CheckBox::Render() {
auto style = is_focused ? focused_style : unfocused_style;
auto focus_management = is_focused ? focus : state ? select : nothing;
return hbox(text(state ? checked : unchecked),
text(label) | style | focus_management);
text(label) | style | focus_management) |
reflect(box_);
}
bool CheckBox::OnEvent(Event event) {
if (event.is_mouse())
return OnMouseEvent(event);
if (event == Event::Character(' ') || event == Event::Return) {
state = !state;
on_change();
@@ -21,6 +25,24 @@ bool CheckBox::OnEvent(Event event) {
return false;
}
bool CheckBox::OnMouseEvent(Event event) {
if (!box_.Contain(event.mouse_x(), event.mouse_y()))
return false;
if (event.is_mouse_move()) {
TakeFocus();
return true;
}
if (event.is_mouse_left_down()) {
state = !state;
on_change();
return true;
}
return false;
}
} // namespace ftxui
// Copyright 2020 Arthur Sonzogni. All rights reserved.