Skip to content

Commit

Permalink
feat: Improve corner radius accuracy on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Nov 14, 2022
1 parent cc91f0f commit dc358f2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
20 changes: 16 additions & 4 deletions src/Uno.UI/UI/Xaml/Controls/Border/BorderLayerRenderer.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ partial class BorderLayerRenderer
private LayoutState _currentState;

private readonly SerialDisposable _layerDisposable = new SerialDisposable();
private static readonly float[] _outerRadiiStore = new float[8];
private static readonly float[] _innerRadiiStore = new float[8];

/// <summary>
/// Updates or creates a sublayer to render a border-like shape.
Expand Down Expand Up @@ -129,8 +131,14 @@ private static IDisposable InnerCreateLayers(
drawArea.Width += fra.Width;
}

using (var backgroundPath = cornerRadius.GetInnerOutlinePath(adjustedArea.ToRectF(), borderThickness))
var outerRadii = cornerRadius.GetRadii(new Windows.Foundation.Size(drawArea.Width, drawArea.Height), borderThickness, true);
outerRadii.GetRadii(_outerRadiiStore);
var innerRadii = cornerRadius.GetRadii(new Windows.Foundation.Size(drawArea.Width, drawArea.Height), borderThickness, false);
innerRadii.GetRadii(_innerRadiiStore);

using (var backgroundPath = new Path())
{
backgroundPath.AddRoundRect(adjustedArea.ToRectF(), _innerRadiiStore, Path.Direction.Cw);
//We only need to set a background if the drawArea is non-zero
if (!drawArea.HasZeroArea())
{
Expand Down Expand Up @@ -160,10 +168,14 @@ private static IDisposable InnerCreateLayers(
// Related Issue: https://github.com/unoplatform/uno/issues/6893
using (var strokePaint = new Paint(borderBrush.GetStrokePaint(drawArea)))
{
//Create the path for the outer and inner rectangles that will become our border shape
var borderPath = cornerRadius.GetOutlinePath(drawArea.ToRectF());
borderPath.AddRoundRect(adjustedArea.ToRectF(), cornerRadius.GetInnerRadii(borderThickness), Path.Direction.Cw);
//Create the path for the outer and inner rectangles that will become our border shape
using var borderPath = new Path();

borderPath.AddRoundRect(drawArea, _outerRadiiStore, Path.Direction.Cw);
borderPath.AddRoundRect(adjustedArea, _innerRadiiStore, Path.Direction.Cw);
//Create the path for the outer and inner rectangles that will become our border shape
//var borderPath = cornerRadius.GetOutlinePath(drawArea.ToRectF());
//borderPath.AddRoundRect(adjustedArea.ToRectF(), cornerRadius.GetInnerRadii(borderThickness), Path.Direction.Cw);
var overlay = GetOverlayDrawable(
strokePaint,
physicalBorderThickness,
Expand Down
18 changes: 16 additions & 2 deletions src/Uno.UI/UI/Xaml/FullCornerRadius.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Windows.Foundation;
using Uno.UI;
using Windows.Foundation;

namespace Windows.UI.Xaml;

Expand All @@ -8,4 +9,17 @@ internal record struct FullCornerRadius
Point TopRight,
Point BottomRight,
Point BottomLeft
);
)
{
internal void GetRadii(float[] radiiStore)
{
radiiStore[0] = ViewHelper.LogicalToPhysicalPixels(TopLeft.X);
radiiStore[1] = ViewHelper.LogicalToPhysicalPixels(TopLeft.Y);
radiiStore[2] = ViewHelper.LogicalToPhysicalPixels(TopRight.X);
radiiStore[3] = ViewHelper.LogicalToPhysicalPixels(TopRight.Y);
radiiStore[4] = ViewHelper.LogicalToPhysicalPixels(BottomRight.X);
radiiStore[5] = ViewHelper.LogicalToPhysicalPixels(BottomRight.Y);
radiiStore[6] = ViewHelper.LogicalToPhysicalPixels(BottomLeft.X);
radiiStore[7] = ViewHelper.LogicalToPhysicalPixels(BottomLeft.Y);
}
}

0 comments on commit dc358f2

Please sign in to comment.