rds1983 / Myra

UI Library for MonoGame, FNA and Stride
MIT License
704 stars 93 forks source link

Bug: incorrect click behaviour #348

Open gamedevcb opened 2 years ago

gamedevcb commented 2 years ago

Myra has an incorrect click behaviour, as it triggers clicks OnTouchup(), regardless if the user has actually pressed down the mouse button inside the target button or not. This is unlike every other application that is out there, where clicks are only valid if both 'OnTouchDown' and 'OnTouchup' events are triggered from the same button.

A simple solution would be to check the 'IsPressed' bool before firing off the click event like: if(IsPressed) Click.Invoke(this); (of course, the isPressed would have to be reset to false after the click event has been fired)

https://github.com/rds1983/Myra/blob/e46221751586d160c59ca9a44754b9d8ca61b7ce/src/Myra/Graphics2D/UI/ButtonBase.cs#:~:text=public%20override%20void-,OnTouchUp(,-)

rds1983 commented 1 year ago

I tend to disagree that every other application has different behavior. I've attached a small WPF sample(it's important to notice, that Myra is trying to mimic WPF behavior). Run it, press mouse button outside of the "Test" button, then move mouse inside the "Test" button and release. The "MouseUp" event will fire. WpfApp2.zip

rds1983 commented 1 year ago

After some more playing with WPF, I've noticed that Click event fires only if MouseDown/MouseUp events occured within the same button. Myra Button also has Click event. And a fix had been added so it would have the same behavior.