forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Layout): [Android] Properly round values when converting logical …
…to physical pixels. Apply rounding offsets for Path rendering
- Loading branch information
Showing
12 changed files
with
250 additions
and
12 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/SamplesApp/SamplesApp.UITests/Windows_UI_Xaml_Shapes/Rectangle_Rounding.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,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using NUnit.Framework; | ||
using SamplesApp.UITests.Extensions; | ||
using SamplesApp.UITests.TestFramework; | ||
using Uno.UITest.Helpers.Queries; | ||
using Uno.UITests.Helpers; | ||
|
||
namespace SamplesApp.UITests.Windows_UI_Xaml_Shapes | ||
{ | ||
public partial class Rectangle_Rounding : SampleControlUITestBase | ||
{ | ||
[Test] | ||
[AutoRetry] | ||
[ActivePlatforms(Platform.Android)] | ||
public void When_Height_Rounded() | ||
{ | ||
Run("UITests.Windows_UI_Xaml_Shapes.Rectangle_Rounding"); | ||
|
||
using var screenshot = TakeScreenshot($"Rectangle_Rounding"); | ||
var container = _app.GetPhysicalRect($"GridContainer"); | ||
|
||
for (float i = container.Y; i < container.Bottom; i++) | ||
{ | ||
ImageAssert.HasColorAt(screenshot, container.CenterX, i, Color.Black); | ||
} | ||
} | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Rectangle_Rounding.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,23 @@ | ||
<Page x:Class="UITests.Windows_UI_Xaml_Shapes.Rectangle_Rounding" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:UITests.Windows_UI_Xaml_Shapes" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d"> | ||
|
||
<Grid Height="235" Background="Red" x:Name="GridContainer"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="*" /> | ||
<RowDefinition Height="*" /> | ||
<RowDefinition Height="*" /> | ||
</Grid.RowDefinitions> | ||
|
||
<Border Grid.Row="0" | ||
Background="Black" /> | ||
<Rectangle Grid.Row="1" | ||
Fill="Black" /> | ||
<Border Grid.Row="2" | ||
Background="Black" /> | ||
</Grid> | ||
</Page> |
32 changes: 32 additions & 0 deletions
32
src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Shapes/Rectangle_Rounding.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,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Uno.UI.Samples.Controls; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
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; | ||
|
||
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 | ||
|
||
namespace UITests.Windows_UI_Xaml_Shapes | ||
{ | ||
/// <summary> | ||
/// An empty page that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
[Sample("Shapes", "Rectangle_Rounding")] | ||
public sealed partial class Rectangle_Rounding : Page | ||
{ | ||
public Rectangle_Rounding() | ||
{ | ||
this.InitializeComponent(); | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Shapes/Given_Android_Relative_Shape_Rounding.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,69 @@ | ||
#if __ANDROID__ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Private.Infrastructure; | ||
using Windows.Foundation; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Shapes; | ||
|
||
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Shapes | ||
{ | ||
[TestClass] | ||
public class Given_Android_Relative_Shape_Rounding | ||
{ | ||
[TestMethod] | ||
[RunsOnUIThread] | ||
public async Task When_Rectangle_Rounded_Measure_Height() | ||
{ | ||
var grid = new Grid() | ||
{ | ||
Height = 439, | ||
}; | ||
|
||
TestServices.WindowHelper.WindowContent = grid; | ||
await TestServices.WindowHelper.WaitForIdle(); | ||
|
||
grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); | ||
grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); | ||
grid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) }); | ||
|
||
var topBorder = new Border(); | ||
Grid.SetRow(topBorder, 0); | ||
|
||
var rect = new Rectangle(); | ||
Grid.SetRow(rect, 1); | ||
|
||
var bottomBorder = new Border(); | ||
Grid.SetRow(bottomBorder, 2); | ||
|
||
grid.Children.Add(topBorder); | ||
grid.Children.Add(rect); | ||
grid.Children.Add(bottomBorder); | ||
|
||
grid.Measure(new Size(10000, 10000)); | ||
var desired = grid.DesiredSize; | ||
grid.Arrange(new Rect(0, 0, desired.Width, desired.Height)); | ||
|
||
var nativeViewTopBorder = topBorder as Android.Views.View; | ||
var nativeViewRect = rect as Android.Views.View; | ||
var nativeViewBottomBorder = bottomBorder as Android.Views.View; | ||
|
||
Assert.AreEqual(146, nativeViewTopBorder.Height); | ||
Assert.AreEqual(147, nativeViewRect.Height); | ||
Assert.AreEqual(146, nativeViewBottomBorder.Height); | ||
|
||
Assert.AreEqual(146, nativeViewRect.Top); | ||
Assert.AreEqual(293, nativeViewRect.Bottom); | ||
Assert.AreEqual(293, nativeViewBottomBorder.Top); | ||
|
||
Assert.IsNotNull(rect.FrameRoundingAdjustment); | ||
Assert.AreEqual(1, rect.FrameRoundingAdjustment.Value.Height); | ||
Assert.AreEqual(0, rect.FrameRoundingAdjustment.Value.Width); | ||
} | ||
} | ||
} | ||
#endif |
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
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
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
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
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
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
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