mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-15 15:38:21 +08:00
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:
@@ -23,6 +23,11 @@ struct Mouse {
|
||||
Pressed = 1,
|
||||
};
|
||||
|
||||
// Utility function to check the variations of the mouse state.
|
||||
bool IsPressed(Button btn = Left) const; // Released => Pressed.
|
||||
bool IsHeld(Button btn = Left) const; // Pressed => Pressed.
|
||||
bool IsReleased(Button btn = Left) const; // Pressed => Released.
|
||||
|
||||
// Button
|
||||
Button button = Button::None;
|
||||
|
||||
@@ -37,6 +42,9 @@ struct Mouse {
|
||||
// Coordinates:
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
|
||||
// Previous mouse event, if any.
|
||||
Mouse* previous = nullptr;
|
||||
};
|
||||
|
||||
} // namespace ftxui
|
||||
|
@@ -112,6 +112,7 @@ class ScreenInteractive : public Screen {
|
||||
|
||||
bool frame_valid_ = false;
|
||||
|
||||
Mouse latest_mouse_event_;
|
||||
friend class Loop;
|
||||
|
||||
public:
|
||||
|
Reference in New Issue
Block a user