Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ShadowContainer): ensure canvas does not have negative dimension #804

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
35 changes: 35 additions & 0 deletions src/Uno.Toolkit.RuntimeTests/Tests/ShadowContainerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,41 @@ public async Task Displays_Content()
await renderer.AssertColorAt(Colors.Green, 100, 300);
}

[TestMethod]
public async Task Displays_Content_With_Margin()
{
var shadowContainer = new ShadowContainer
{
Content = new Border
{
Margin = new Thickness(50),
Height = 50,
Width = 50,
Background = new SolidColorBrush(Colors.Green)
}
};

var stackPanel = new StackPanel
{
Background = new SolidColorBrush(Colors.Yellow),
HorizontalAlignment = HorizontalAlignment.Center,
Children =
{
new Border { Height = 150, Width = 150, Background = new SolidColorBrush(Colors.Red) },
shadowContainer,
new Border { Height = 150, Width = 150, Background = new SolidColorBrush(Colors.Red) },
}
};

UnitTestsUIContentHelper.Content = stackPanel;

await UnitTestsUIContentHelper.WaitForIdle();
await UnitTestsUIContentHelper.WaitForLoaded(stackPanel);

var renderer = await stackPanel.TakeScreenshot();
await renderer.AssertColorAt(Colors.Green, 75, 225);
}

#if !(__ANDROID__ || __IOS__)
[TestMethod]
[DataRow(10, 10, false)]
Expand Down
21 changes: 3 additions & 18 deletions src/Uno.Toolkit.Skia.WinUI/Controls/Shadows/ShadowContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,24 +298,9 @@ private void InvalidateCanvasLayout()
// float left = (float)(-diffWidthShadowHostChild / 2 + contentAsFE.Margin.Left);
// float top = (float)(-diffHeightShadowHostChild / 2 + contentAsFE.Margin.Top);









_canvas.Width = contentAsFE.ActualWidth - contentAsFE.Margin.Left - contentAsFE.Margin.Right;
if (_canvas.Width < 0)
{
_canvas.Width = 0;
}
_canvas.Height = contentAsFE.ActualHeight - contentAsFE.Margin.Top - contentAsFE.Margin.Bottom;
if (_canvas.Height < 0)
{
_canvas.Height = 0;
}
_canvas.Width = Math.Max(contentAsFE.ActualWidth - contentAsFE.Margin.Left - contentAsFE.Margin.Right, 0);
_canvas.Height = Math.Max(contentAsFE.ActualHeight - contentAsFE.Margin.Top - contentAsFE.Margin.Bottom, 0);

_canvas.HorizontalAlignment = contentAsFE.HorizontalAlignment;
_canvas.VerticalAlignment = contentAsFE.VerticalAlignment;

Expand Down
Loading