Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(wasm): geometry not receiving pointer events
- Loading branch information
Showing
5 changed files
with
190 additions
and
2 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Input/HitTest_GeometryGroup_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using SamplesApp.UITests.TestFramework; | ||
using Uno.UITest.Helpers; | ||
using Uno.UITest.Helpers.Queries; | ||
|
||
namespace SamplesApp.UITests.Windows_UI_Xaml_Input | ||
{ | ||
[TestFixture] | ||
public partial class HitTest_GeometryGroup_Tests : SampleControlUITestBase | ||
{ | ||
private const string _sample = "UITests.Windows_UI_Input.PointersTests.HitTest_GeometryGroup"; | ||
|
||
[Test] [AutoRetry] public void When_HollowCircle2() | ||
{ | ||
Run(_sample); | ||
|
||
var element = "HollowCircle2"; | ||
|
||
// tap on the hollow circle at the center of 12-o-clock position | ||
var rect = _app.WaitForElement(element).Single().Rect; | ||
var target = new PointF( | ||
rect.CenterX, | ||
rect.Bottom - rect.Height * (7f/8f) | ||
); | ||
_app.TapCoordinates(target.X, target.Y); | ||
|
||
var result = _app.Marked("LastPressed").GetDependencyPropertyValue<string>("Text"); | ||
var resultSrc = _app.Marked("LastPressedSrc").GetDependencyPropertyValue<string>("Text"); | ||
|
||
result.Should().Be(element); | ||
resultSrc.Should().Be(element); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/SamplesApp/UITests.Shared/Windows_UI_Input/PointersTests/HitTest_GeometryGroup.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<Page x:Class="UITests.Windows_UI_Input.PointersTests.HitTest_GeometryGroup" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:UITests.Windows_UI_Input.PointersTests" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<Grid> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="*" /> | ||
<RowDefinition Height="Auto" /> | ||
</Grid.RowDefinitions> | ||
|
||
<Grid Grid.Row="0" | ||
x:Name="TestCasePanel"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="Auto" /> | ||
<ColumnDefinition Width="Auto" /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<Path Grid.Column="0" | ||
x:Name="HollowCircle1" | ||
Fill="SkyBlue" | ||
Height="100" Width="100"> | ||
<Path.Data> | ||
<GeometryGroup FillRule="EvenOdd"> | ||
<EllipseGeometry Center="50,50" RadiusX="50" RadiusY="50" /> | ||
<EllipseGeometry Center="50,50" RadiusX="25" RadiusY="25" /> | ||
</GeometryGroup> | ||
</Path.Data> | ||
</Path> | ||
<Path Grid.Column="1" | ||
x:Name="HollowCircle2" | ||
Fill="SkyBlue" | ||
Height="100" Width="100"> | ||
<Path.Data> | ||
<GeometryGroup FillRule="EvenOdd"> | ||
<EllipseGeometry Center="50,50" RadiusX="50" RadiusY="50" /> | ||
<EllipseGeometry Center="50,50" RadiusX="25" RadiusY="25" /> | ||
</GeometryGroup> | ||
</Path.Data> | ||
</Path> | ||
</Grid> | ||
|
||
<StackPanel Grid.Row="1" Orientation="Horizontal"> | ||
<TextBlock Text="Last pressed: " /> | ||
<TextBlock x:Name="LastPressed" Text="__none__" /> | ||
<TextBlock Text=" (src: " /> | ||
<TextBlock x:Name="LastPressedSrc" Text="__none__" /> | ||
<TextBlock Text=") - Last hovered: " /> | ||
<TextBlock x:Name="LastHovered" Text="__none__" /> | ||
<TextBlock Text=" (src: " /> | ||
<TextBlock x:Name="LastHoveredSrc" Text="__none__" /> | ||
<TextBlock Text=")" /> | ||
</StackPanel> | ||
</Grid> | ||
</Page> |
79 changes: 79 additions & 0 deletions
79
src/SamplesApp/UITests.Shared/Windows_UI_Input/PointersTests/HitTest_GeometryGroup.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Windows.UI; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Input; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
using Windows.UI.Xaml.Shapes; | ||
using Uno.UI.Samples.Controls; | ||
using Uno.Extensions; | ||
|
||
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 | ||
|
||
namespace UITests.Windows_UI_Input.PointersTests | ||
{ | ||
[Sample("Pointers", "GeometryGroup")] | ||
public sealed partial class HitTest_GeometryGroup : Page | ||
{ | ||
public HitTest_GeometryGroup() | ||
{ | ||
this.InitializeComponent(); | ||
RegisterPointerEvents(); | ||
|
||
Loaded += (s, e) => | ||
{ | ||
_ = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => | ||
{ | ||
// this needs to be added on SizeChanged or on a delay | ||
HollowCircle2.Data = GenerateHollowCircle(new Size(100, 100)); | ||
}); | ||
}; | ||
} | ||
|
||
private GeometryGroup GenerateHollowCircle(Size size) | ||
{ | ||
var center = new Point(size.Width / 2, size.Height / 2); | ||
var radius = Math.Min(size.Width, size.Height) / 2; | ||
var radius2 = radius * (1.0 / 2.0); | ||
|
||
return new GeometryGroup().Apply(x => x.Children.AddRange(new EllipseGeometry[] | ||
{ | ||
new EllipseGeometry { Center = center, RadiusX = radius, RadiusY = radius }, | ||
new EllipseGeometry { Center = center, RadiusX = radius2, RadiusY = radius2 }, | ||
})); | ||
} | ||
|
||
private void RegisterPointerEvents() | ||
{ | ||
foreach (var elt in GetElements()) | ||
{ | ||
elt.PointerPressed += (snd, e) => | ||
{ | ||
e.Handled = true; | ||
LastPressed.Text = elt.Name; | ||
LastPressedSrc.Text = (e.OriginalSource as FrameworkElement)?.Name ?? "-unknown-"; | ||
}; | ||
elt.PointerMoved += (snd, e) => | ||
{ | ||
e.Handled = true; | ||
LastHovered.Text = elt.Name; | ||
LastHoveredSrc.Text = (e.OriginalSource as FrameworkElement)?.Name ?? "-unknown-"; | ||
}; | ||
} | ||
} | ||
|
||
private IEnumerable<FrameworkElement> GetElements() | ||
{ | ||
yield return HollowCircle1; | ||
yield return HollowCircle2; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters