uno: [Wasm] When Css Style "clip-path" applied to Canvas, Canvas receive wrong Pointer Event.
Current behavior
Consider below example, GreenCanvas inside the RedCanvas, and I set css style “clip-path” on GreenCanvas : GreenCanvas.SetCssStyle(“clip-path”, “path(‘M300,0 500,50 300,100z’)”);
When pointer moving on red area, GreenCanvas wrongly received the pointer move events.
This error start from Uno.UI/ Uno.UI.WebAssembly version 5.4.0-dev.1485 . before this version it’s correct.
<Canvas Width="500" Height="100" Background="Red" x:Name="RedCanvas" PointerMoved="Canvas_PointerMoved" >
<Canvas Width="500" Height="100" Background="Green" x:Name="GreenCanvas" PointerMoved="Canvas_PointerMoved"> </Canvas>
</Canvas>
public TestPanel()
{
this.InitializeComponent();
GreenCanvas.SetCssStyle("clip-path", "path('M300,0 500,50 300,100z')");
}
private void Canvas_PointerMoved(object sender, PointerRoutedEventArgs e)
{
Console.WriteLine((sender as Canvas).Name + " moved");
e.Handled = true;
}
Thank you!
Expected behavior
No response
How to reproduce it (as minimally and precisely as possible)
No response
Workaround
No response
Works on UWP/WinUI
None
Environment
Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia
NuGet package version(s)
No response
Affected platforms
WebAssembly
IDE
Visual Studio 2022
IDE version
No response
Relevant plugins
No response
Anything else we need to know?
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 19 (9 by maintainers)
You can implement the same for “NativePointerPressed” via
pointerdownand “NativePointerReleased” viapointerupfollowing theclickexample. For NativePointerMoved that would bepointerover, but you would likely have to pass back the pointer x,y coords & possibly need to remap it into winui coords space.If you need further assistance in these areas, please share with us what you intent with do with these events (some examples or existing pointer handlers), so we can better update the sample.
So we did some major update regarding how the pointer are handled in wasm back in 5.4 (#17633). Instead of handling pointer events from every single view, we are now handling them centrally at
document.bodylevel with uno taking care of dispatching, rather than the browser. Now of course there are some discrepancies, as you have noticed. However, this is not something that can be easily reverted as it addresses others problem, and we can neither make it a toggle.That said, we can compromise with what we already have or take the best of both worlds. If the end goal was to
clip-pathan<Image>, while having its hitbox matches the clipped shape, we can combine your approach and the workaround proposed above. The idea is toclip-paththe image (or its container) and make them not hit-visible, and then superpose a path with the same clip as the hitbox for the pointer events. (Here, unlikeclip-pathwhich uno are blind to, the Path.Data is something known by us, so we can dispatch the event properly.)ClippableImage.cs
ClippableImage.xaml
make sure to reference this in your app.xaml directly or indirectly
usage:
full solution: u18458.zip
@easy28 unfortunately I doubt switching between managed and native pointers is possible, as it is a completely different infrastructure involved (am I correct @dr1rrb?)
@easy28 IMO, it’s in general not a good idea to alter “clip-path” yourself. For example, if we implemented https://github.com/unoplatform/uno/issues/13782, then our own layout clipping will be competing on the same property that you are trying to set (though it won’t happen for Canvas specifically as it’s never layout clipped by us).
I think a better way to achieve the same rendering would be something like this:
Can you try that and let us know if pointers don’t work properly with that code?
Note: the above will also work on all platforms, while what you have will only work on Wasm
I’m pretty sure that moving WASM pointers to managed means that any native clipping won’t affect hit-testing at all (since we do our own hit tests), but I didn’t work on that, so I’m not sure. Maybe @dr1rrb can chime in?