mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-28 16:29:34 +08:00
Add mouse implementation of most components.
This commit is contained in:
@@ -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.
|
||||
|
Reference in New Issue
Block a user