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:
@@ -8,6 +8,7 @@ namespace ftxui {
|
||||
Element RadioBox::Render() {
|
||||
std::vector<Element> elements;
|
||||
bool is_focused = Focused();
|
||||
boxes_.resize(entries.size());
|
||||
for (size_t i = 0; i < entries.size(); ++i) {
|
||||
auto style =
|
||||
(focused == int(i) && is_focused) ? focused_style : unfocused_style;
|
||||
@@ -16,12 +17,15 @@ Element RadioBox::Render() {
|
||||
|
||||
const std::wstring& symbol = selected == int(i) ? checked : unchecked;
|
||||
elements.push_back(hbox(text(symbol), text(entries[i]) | style) |
|
||||
focus_management);
|
||||
focus_management | reflect(boxes_[i]));
|
||||
}
|
||||
return vbox(std::move(elements));
|
||||
}
|
||||
|
||||
bool RadioBox::OnEvent(Event event) {
|
||||
if (event.is_mouse())
|
||||
return OnMouseEvent(event);
|
||||
|
||||
if (!Focused())
|
||||
return false;
|
||||
|
||||
@@ -50,6 +54,30 @@ bool RadioBox::OnEvent(Event event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RadioBox::OnMouseEvent(Event event) {
|
||||
for (int i = 0; i < boxes_.size(); ++i) {
|
||||
if (!boxes_[i].Contain(event.mouse_x(), event.mouse_y()))
|
||||
continue;
|
||||
|
||||
if (event.is_mouse_move()) {
|
||||
focused = i;
|
||||
TakeFocus();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event.is_mouse_left_down()) {
|
||||
cursor_position = i;
|
||||
TakeFocus();
|
||||
if (selected != i) {
|
||||
selected = i;
|
||||
on_change();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
||||
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
||||
|
Reference in New Issue
Block a user