Checkbox button debounce (#774)

This fixes: https://github.com/ArthurSonzogni/FTXUI/issues/773

Dragging the mouse with the left button pressed now avoids activating multiple
checkboxes.

Add support for detecting mouse press transition. Added:
```cpp
// The previous mouse event.
Mouse Mouse::previous;

// Return whether the mouse transitionned from:
// released to pressed => IsPressed()
// pressed to pressed => IsHeld()
// pressed to released => IsReleased()
bool Mouse::IsPressed(Button button) const;
bool Mouse::IsHeld(Button button) const;
bool Mouse::IsReleased(Button button) const;
```
A couple of components are now activated when the mouse is pressed,
as opposed to released.

Co-authored-by: ArthurSonzogni <sonzogniarthur@gmail.com>
This commit is contained in:
Clément Roblot
2023-11-11 23:33:50 +07:00
committed by GitHub
parent e8589dd533
commit c31aecf2ed
14 changed files with 81 additions and 18 deletions

View File

@@ -689,11 +689,17 @@ void ScreenInteractive::HandleTask(Component component, Task& task) {
if (arg.is_mouse()) {
arg.mouse().x -= cursor_x_;
arg.mouse().y -= cursor_y_;
arg.mouse().previous = &latest_mouse_event_;
}
arg.screen_ = this;
component->OnEvent(arg);
frame_valid_ = false;
if (arg.is_mouse()) {
latest_mouse_event_ = arg.mouse();
latest_mouse_event_.previous = nullptr;
}
return;
}