Skip to content

Commit

Permalink
fix(ShadowContainer): ensure canvas does not have negative dimension (#…
Browse files Browse the repository at this point in the history
…804)

(cherry picked from commit 070bee8)

# Conflicts:
#	src/Uno.Toolkit.RuntimeTests/Tests/ShadowContainerTests.cs
  • Loading branch information
kazo0 authored and mergify[bot] committed Sep 4, 2023
1 parent 3b10bc8 commit 726344e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 18 deletions.
39 changes: 39 additions & 0 deletions src/Uno.Toolkit.RuntimeTests/Tests/ShadowContainerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,45 @@ public async Task Displays_Content()
await renderer.AssertColorAt(Colors.Green, 100, 300);
}

<<<<<<< HEAD
=======
[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__)
>>>>>>> 070bee8 (fix(ShadowContainer): ensure canvas does not have negative dimension (#804))
[TestMethod]
[DataRow(10, 10, false)]
//[DataRow(10, 10, true)]
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

0 comments on commit 726344e

Please sign in to comment.