mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-26 04:31:34 +08:00
Fix mouse wheel on checkbox. (#205)
This commit is contained in:
parent
7d4452f45c
commit
37b44e7557
@ -50,10 +50,14 @@ int main(int argc, const char* argv[]) {
|
|||||||
// -- Checkbox ---------------------------------------------------------------
|
// -- Checkbox ---------------------------------------------------------------
|
||||||
bool checkbox_1_selected = false;
|
bool checkbox_1_selected = false;
|
||||||
bool checkbox_2_selected = false;
|
bool checkbox_2_selected = false;
|
||||||
|
bool checkbox_3_selected = false;
|
||||||
|
bool checkbox_4_selected = false;
|
||||||
|
|
||||||
auto checkboxes = Container::Vertical({
|
auto checkboxes = Container::Vertical({
|
||||||
Checkbox("checkbox1", &checkbox_1_selected),
|
Checkbox("checkbox1", &checkbox_1_selected),
|
||||||
Checkbox("checkbox2", &checkbox_2_selected),
|
Checkbox("checkbox2", &checkbox_2_selected),
|
||||||
|
Checkbox("checkbox3", &checkbox_3_selected),
|
||||||
|
Checkbox("checkbox4", &checkbox_4_selected),
|
||||||
});
|
});
|
||||||
checkboxes = Wrap("Checkbox", checkboxes);
|
checkboxes = Wrap("Checkbox", checkboxes);
|
||||||
|
|
||||||
|
@ -34,18 +34,22 @@ class CheckboxBase : public ComponentBase {
|
|||||||
Element Render() override {
|
Element Render() override {
|
||||||
bool is_focused = Focused();
|
bool is_focused = Focused();
|
||||||
bool is_active = Active();
|
bool is_active = Active();
|
||||||
auto style = is_focused ? (hovered_ ? option_->style_selected_focused
|
auto style = (is_focused || hovered_) ? option_->style_selected_focused
|
||||||
: option_->style_selected)
|
: is_active ? option_->style_selected
|
||||||
: (hovered_ ? option_->style_focused
|
: option_->style_normal;
|
||||||
: option_->style_normal);
|
|
||||||
auto focus_management = is_focused ? focus : is_active ? select : nothing;
|
auto focus_management = is_focused ? focus : is_active ? select : nothing;
|
||||||
return hbox(text(*state_ ? option_->style_checked
|
return hbox({
|
||||||
|
text(*state_ ? option_->style_checked
|
||||||
: option_->style_unchecked),
|
: option_->style_unchecked),
|
||||||
text(*label_) | style | focus_management) |
|
text(*label_) | style | focus_management,
|
||||||
|
}) |
|
||||||
reflect(box_);
|
reflect(box_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OnEvent(Event event) override {
|
bool OnEvent(Event event) override {
|
||||||
|
if (!CaptureMouse(event))
|
||||||
|
return false;
|
||||||
|
|
||||||
if (event.is_mouse())
|
if (event.is_mouse())
|
||||||
return OnMouseEvent(event);
|
return OnMouseEvent(event);
|
||||||
|
|
||||||
@ -53,6 +57,7 @@ class CheckboxBase : public ComponentBase {
|
|||||||
if (event == Event::Character(' ') || event == Event::Return) {
|
if (event == Event::Character(' ') || event == Event::Return) {
|
||||||
*state_ = !*state_;
|
*state_ = !*state_;
|
||||||
option_->on_change();
|
option_->on_change();
|
||||||
|
TakeFocus();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -89,8 +89,8 @@ class VerticalContainer : public ContainerBase {
|
|||||||
for (auto& it : children_)
|
for (auto& it : children_)
|
||||||
elements.push_back(it->Render());
|
elements.push_back(it->Render());
|
||||||
if (elements.size() == 0)
|
if (elements.size() == 0)
|
||||||
return text("Empty container");
|
return text("Empty container") | reflect(box_);
|
||||||
return vbox(std::move(elements));
|
return vbox(std::move(elements)) | reflect(box_);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EventHandler(Event event) override {
|
bool EventHandler(Event event) override {
|
||||||
@ -117,7 +117,7 @@ class VerticalContainer : public ContainerBase {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Focusable())
|
if (!box_.Contain(event.mouse().x, event.mouse().y))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (event.mouse().button == Mouse::WheelUp)
|
if (event.mouse().button == Mouse::WheelUp)
|
||||||
@ -128,6 +128,8 @@ class VerticalContainer : public ContainerBase {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Box box_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class HorizontalContainer : public ContainerBase {
|
class HorizontalContainer : public ContainerBase {
|
||||||
|
@ -103,9 +103,6 @@ class RadioboxBase : public ComponentBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool OnMouseEvent(Event event) {
|
bool OnMouseEvent(Event event) {
|
||||||
if (!CaptureMouse(event))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (event.mouse().button == Mouse::WheelDown ||
|
if (event.mouse().button == Mouse::WheelDown ||
|
||||||
event.mouse().button == Mouse::WheelUp) {
|
event.mouse().button == Mouse::WheelUp) {
|
||||||
return OnMouseWheel(event);
|
return OnMouseWheel(event);
|
||||||
|
Loading…
Reference in New Issue
Block a user