diff --git a/tests/Avalonia.RenderTests/Controls/CustomRenderTests.cs b/tests/Avalonia.RenderTests/Controls/CustomRenderTests.cs index f87b1b5a15..995b285df1 100644 --- a/tests/Avalonia.RenderTests/Controls/CustomRenderTests.cs +++ b/tests/Avalonia.RenderTests/Controls/CustomRenderTests.cs @@ -1,6 +1,7 @@ // Copyright (c) The Avalonia Project. All rights reserved. // Licensed under the MIT license. See licence.md file in the project root for full license information. +using System; using System.Threading.Tasks; using Avalonia.Controls; using Avalonia.Layout; @@ -23,37 +24,68 @@ namespace Avalonia.Direct2D1.RenderTests.Controls } [Fact] - public async Task Opacity() + public async Task Clip() { Decorator target = new Decorator { Padding = new Thickness(8), Width = 200, Height = 200, - Child = new OpacityRenderer(), + Child = new CustomRenderer((control, context) => + { + context.FillRectangle( + Brushes.Red, + control.Bounds, + 4); + + using (context.PushClip(control.Bounds.Deflate(20))) + { + context.FillRectangle( + Brushes.Blue, + control.Bounds, + 4); + } + }), }; await RenderToFile(target); CompareImages(); } - class OpacityRenderer : Control + [Fact] + public async Task Opacity() { - public override void Render(DrawingContext context) + Decorator target = new Decorator { - context.FillRectangle( - Brushes.Red, - Bounds, - 4); - - using (context.PushOpacity(0.5)) + Padding = new Thickness(8), + Width = 200, + Height = 200, + Child = new CustomRenderer((control, context) => { context.FillRectangle( - Brushes.Blue, - Bounds.Deflate(20), + Brushes.Red, + control.Bounds, 4); - } - } + + using (context.PushOpacity(0.5)) + { + context.FillRectangle( + Brushes.Blue, + control.Bounds.Deflate(20), + 4); + } + }), + }; + + await RenderToFile(target); + CompareImages(); + } + + class CustomRenderer : Control + { + private Action _render; + public CustomRenderer(Action render) => _render = render; + public override void Render(DrawingContext context) => _render(this, context); } } } diff --git a/tests/TestFiles/Cairo/Controls/CustomRender/Clip.expected.png b/tests/TestFiles/Cairo/Controls/CustomRender/Clip.expected.png new file mode 100644 index 0000000000..3347370368 Binary files /dev/null and b/tests/TestFiles/Cairo/Controls/CustomRender/Clip.expected.png differ diff --git a/tests/TestFiles/Direct2D1/Controls/CustomRender/Clip.expected.png b/tests/TestFiles/Direct2D1/Controls/CustomRender/Clip.expected.png new file mode 100644 index 0000000000..3347370368 Binary files /dev/null and b/tests/TestFiles/Direct2D1/Controls/CustomRender/Clip.expected.png differ diff --git a/tests/TestFiles/Skia/Controls/CustomRender/Clip.expected.png b/tests/TestFiles/Skia/Controls/CustomRender/Clip.expected.png new file mode 100644 index 0000000000..3347370368 Binary files /dev/null and b/tests/TestFiles/Skia/Controls/CustomRender/Clip.expected.png differ