Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bda11df
Fix Border corners clipping mistake on Windows
jsuarezruiz Apr 4, 2023
fccccd2
Merge branch 'main' into housekeeping-border-corners
jsuarezruiz Apr 10, 2023
0726a3d
Merge branch 'main' into housekeeping-border-corners
jsuarezruiz Apr 12, 2023
341b69b
Merge branch 'main' into fix-10407
jsuarezruiz Apr 13, 2023
f531dac
Merge branch 'main' into housekeeping-border-corners
jsuarezruiz Apr 20, 2023
7934531
Merge branch 'main' into housekeeping-border-corners
jsuarezruiz Apr 28, 2023
ca2180e
Merge branch 'main' into housekeeping-border-corners
jsuarezruiz May 3, 2023
521ad3b
Merge branch 'main' into housekeeping-border-corners
jsuarezruiz May 8, 2023
9a975ea
Merge branch 'main' into housekeeping-border-corners
jsuarezruiz May 31, 2023
d61d149
Updated impl
jsuarezruiz May 31, 2023
62013e5
Merge branch 'main' into housekeeping-border-corners
jsuarezruiz Jun 6, 2023
5c3fc09
Merge branch 'main' into housekeeping-border-corners
jsuarezruiz Jun 19, 2023
cc1e9ee
Merge branch 'main' into housekeeping-border-corners
jsuarezruiz Jun 22, 2023
7110f6a
Created method to avoid duplicated code
jsuarezruiz Jun 22, 2023
1a93828
Revert uneccesary changes
jsuarezruiz Jun 22, 2023
9c73f9f
Merge branch 'main' into housekeeping-border-corners
jsuarezruiz Jun 30, 2023
30d99e7
Changes in clipping sizing
jsuarezruiz Jul 13, 2023
7b5ba62
Fix Rui issue
jsuarezruiz Jul 13, 2023
6af3205
Added device tests
jsuarezruiz Jul 13, 2023
b0b5c1c
Remove unnecessary changes
jsuarezruiz Jul 13, 2023
10cfdeb
Merge branch 'main' into housekeeping-border-corners
jsuarezruiz Jul 14, 2023
08e88ae
Merge branch 'main' into housekeeping-border-corners
jsuarezruiz Jul 18, 2023
a49adcd
Merge branch 'main' into housekeeping-border-corners
jsuarezruiz Jul 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
<Grid
Padding="12">
<Grid.RowDefinitions>
<RowDefinition Height="80" />
<RowDefinition Height="110" />
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<Border x:Name="BorderView" Margin="5"
Stroke="Red" Padding="0"
HorizontalOptions="Center" HeightRequest="100" WidthRequest="100">
<Border
x:Name="BorderView" Margin="5"
Stroke="Red" Padding="0"
HorizontalOptions="Center" HeightRequest="100" WidthRequest="100">
<Image x:Name="BorderContent" Aspect="AspectFill" Source="oasis.jpg" />
</Border>

Expand Down
2 changes: 1 addition & 1 deletion src/Controls/src/Core/Border/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void OnStrokeDashArrayChanged(object? sender, NotifyCollectionChangedEventArgs e

void UpdateStrokeShape()
{
if (StrokeShape is Shape strokeShape)
if (StrokeShape is Shape strokeShape && StrokeThickness == 0)
{
strokeShape.StrokeThickness = StrokeThickness;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Xunit;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Controls.Shapes;
using Microsoft.Maui.Handlers;
using Microsoft.UI.Xaml.Hosting;
using Microsoft.Maui.Platform;
using System.Threading.Tasks;
using Microsoft.UI.Composition;

namespace Microsoft.Maui.DeviceTests
{
public partial class BorderTests : ControlsHandlerTestBase
{
[Theory(DisplayName = "Inner CornerRadius Initializes Correctly")]
[InlineData(0)]
[InlineData(12)]
[InlineData(24)]
public async Task InnerCornerRadiusInitializesCorrectly(int cornerRadius)
{
SetupBuilder();

var expected = Colors.Red;

var border = new Border()
{
Content = new Label { Text = "Background", TextColor = Colors.White },
StrokeShape = new RoundRectangle { CornerRadius = cornerRadius },
Background = new SolidPaint(expected),
StrokeThickness = 0,
HeightRequest = 100,
WidthRequest = 300
};

await AttachAndRun(border, (handler) =>
{
var contentPanel = GetNativeBorder(handler as BorderHandler);
var content = contentPanel.Content;
var visual = ElementCompositionPreview.GetElementVisual(content);

var clip = visual.Clip as CompositionGeometricClip;
Assert.NotNull(clip);

var geometry = clip.Geometry as CompositionPathGeometry;
var path = geometry.Path;
Assert.NotNull(path);

Assert.True(contentPanel.IsInnerPath);
});

await AssertColorAtPoint(border, expected, typeof(BorderHandler), cornerRadius, cornerRadius);
}

ContentPanel GetNativeBorder(BorderHandler borderHandler) =>
borderHandler.PlatformView;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ void SetupBuilder()
{
builder.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler<Label, LabelHandler>();
handlers.AddHandler<Border, BorderHandler>();
handlers.AddHandler<Grid, LayoutHandler>();
handlers.AddHandler<Label, LabelHandler>();
});
});
}
Expand Down
75 changes: 59 additions & 16 deletions src/Core/src/Platform/Windows/ContentPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.Maui.Platform
public class ContentPanel : MauiPanel
{
readonly Path? _borderPath;
IShape? _borderShape;
IBorderStroke? _borderStroke;
FrameworkElement? _content;

internal Path? BorderPath => _borderPath;
Expand All @@ -30,6 +30,8 @@ internal FrameworkElement? Content
}
}

internal bool IsInnerPath { get; private set; }

protected override global::Windows.Foundation.Size ArrangeOverride(global::Windows.Foundation.Size finalSize)
{
var actual = base.ArrangeOverride(finalSize);
Expand All @@ -52,9 +54,15 @@ void ContentPanelSizeChanged(object sender, UI.Xaml.SizeChangedEventArgs e)
if (_borderPath == null)
return;

_borderPath.UpdatePath(_borderShape, ActualWidth, ActualHeight);
var width = e.NewSize.Width;
var height = e.NewSize.Height;

if (width <= 0 || height <= 0)
return;

_borderPath.UpdatePath(_borderStroke?.Shape, width, height);
UpdateContent();
UpdateClip(_borderShape);
UpdateClip(_borderStroke?.Shape, width, height);
}

internal void EnsureBorderPath()
Expand All @@ -73,16 +81,40 @@ public void UpdateBackground(Paint? background)
_borderPath.UpdateBackground(background);
}

[Obsolete("Use Microsoft.Maui.Platform.UpdateBorderStroke instead")]
public void UpdateBorderShape(IShape borderShape)
{
_borderShape = borderShape;
UpdateBorder(borderShape);
}

if (_borderPath == null)
internal void UpdateBorderStroke(IBorderStroke borderStroke)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be public on net8 no @hartez ? or else the Obsolete comment will not make sense since this is internal users can't call it

{
if (borderStroke is null)
return;

_borderStroke = borderStroke;

if (_borderStroke is null)
return;

UpdateBorder(_borderStroke.Shape);
}

void UpdateBorder(IShape? strokeShape)
{
if (strokeShape is null || _borderPath is null)
return;

_borderPath.UpdateBorderShape(_borderShape, ActualWidth, ActualHeight);
_borderPath.UpdateBorderShape(strokeShape, ActualWidth, ActualHeight);
UpdateContent();
UpdateClip(_borderShape);

var width = ActualWidth;
var height = ActualHeight;

if (width <= 0 || height <= 0)
return;

UpdateClip(strokeShape, width, height);
}

void AddContent(FrameworkElement? content)
Expand All @@ -104,27 +136,38 @@ void UpdateContent()
Content.RenderTransform = new TranslateTransform() { X = -strokeThickness, Y = -strokeThickness };
}

void UpdateClip(IShape? borderShape)
void UpdateClip(IShape? borderShape, double width, double height)
{
if (Content == null)
if (Content is null)
return;

var clipGeometry = borderShape;

if (clipGeometry == null)
if (height <= 0 && width <= 0)
return;

double width = ActualWidth;
double height = ActualHeight;
var clipGeometry = borderShape;

if (height <= 0 && width <= 0)
if (clipGeometry is null)
return;

var visual = ElementCompositionPreview.GetElementVisual(Content);
var compositor = visual.Compositor;


var pathSize = new Graphics.Rect(0, 0, width, height);
var clipPath = clipGeometry.PathForBounds(pathSize);
PathF? clipPath;

if (clipGeometry is IRoundRectangle roundedRectangle)
{
float strokeThickness = (float)(_borderPath?.StrokeThickness ?? 0);
clipPath = roundedRectangle.InnerPathForBounds(pathSize, strokeThickness / 2);
IsInnerPath = true;
}
else
{
clipPath = clipGeometry.PathForBounds(pathSize);
IsInnerPath = false;
}

var device = CanvasDevice.GetSharedDevice();
var geometry = clipPath.AsPath(device);

Expand Down
6 changes: 2 additions & 4 deletions src/Core/src/Platform/Windows/StrokeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ public static class StrokeExtensions
{
public static void UpdateStrokeShape(this ContentPanel platformView, IBorderStroke border)
{
var shape = border.Shape;

if (shape == null)
if (border is null)
return;

platformView.UpdateBorderShape(shape);
platformView.UpdateBorderStroke(border);
}

public static void UpdateStroke(this ContentPanel platformView, IBorderStroke border)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Threading.Tasks;

namespace Microsoft.Maui.DeviceTests
namespace Microsoft.Maui.DeviceTests
{
public partial class BorderHandlerTests
{
Expand Down