-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rectangle.Contains
must be exclusive on Width
and Height
#8594
Comments
As a small addition, currently I observe that wrong element receives the mouse click. Lets say we have two buttons: |
This is the same as WPF/UWP: in these frameworks Also if you look at QT, their https://doc.qt.io/qt-6/qrect.html#contains In Avalonia we have recently added the https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Base/Rect.cs#L262 This method should be used for hit-testing, though we've not yet updated our code to use it in all cases. Interestingly WPF also has the erroneous behavior you mention above when hit-testing controls. Now I'd be the first to admit that the |
@grokys Thank you for the answer. It is a bug, and currently for me it is a game stopper. I also checked Hans answer. In the case which I'm describing it is nothing to do with the drawing system. I'm talking more about HitTest geometry, which uses transformed coordinates which eventually are exactly pixels, like GDI. |
I certainly agree that if a pixel does not contain a rectangle when drawn on the screen, it should not register a hit for said rectangle at that pixel. At least that much certainly must be a bug. |
Yeah, the bug is that Avalonia doesn't use |
Ah here we go: #3079 |
@grokys If we use Relative to the topic: Rust-SDL2/rust-sdl2#569 |
Yeah, I mean I agree with you: exclusive makes a lot more sense to me, but WPF and UWP (and by extension Avalonia) use bottom/right inclusive and our general rule is to follow WPF and UWP behavior. My only argument for inclusive
Which make sense as well. Anyway, as much sense as I think bottom/right excusive makes I'd be hesitant to change this behavior now though because:
|
Just a few comments, none actionable.
|
Yeah, I'm really not sure why If I'd not done that, then at this point I'd be saying "Avalonia is correct, WPF is wrong" but since I did do that, I think as you say, changing it silently at this point would be causing more trouble than its worth because it's not functionality that will obviously break for anyone already using it - it's an insidious change that will probably break things in minor ways. Of course it may also fix just as many things in minor ways, but hard to know. So given that, I think we should fix our hit-testing to use |
In my case it was very special I think, I've been introducing mouse support here https://github.com/jinek/ToolUI |
Describe the bug
Current implementation of
Rectangle.Contains
includes additional row and column also, which means, for instance, that zero height rectangle contains 1 horizontal line of height 1, which means that height=0 is not less than height=1, which is mathematically wrong.Right and down boundaries must be exclusive, like
p.Y < _y + _height
rather thanp.Y <= _y + _height
.One more example is rectangle with height=1. It's drawn like a line, 1 pixel height (not like two lines of 1 pixel height). If we click on it, avalonia by mistake will count next line (where no rectangle is drawn) also as a part of rectangle:
To Reproduce
Rectangle with height=1:
---- - represents a rectangle with height=1 (0,0,20,1)
*-represents point of mouse click (4,1)
As you see, we have clicked below the rectangle, but Avalonia counts it as a click on the rectangle.
Additional context
Standard .NET class rectangle also contains wrong implementation and includes one more horizontal and one more vertical lines with width=1 in to considiration.
The text was updated successfully, but these errors were encountered: