123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- using Avalonia.Controls;
- using Avalonia.Media;
- using Avalonia.Platform;
- using Avalonia.Rendering;
- using Avalonia.UnitTests;
- using Moq;
- using Xunit;
- namespace Avalonia.Base.UnitTests
- {
- public class RenderTests_Culling
- {
- [Fact]
- public void In_Bounds_Control_Should_Be_Rendered()
- {
- using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
- {
- TestControl target;
- var container = new Canvas
- {
- Width = 100,
- Height = 100,
- ClipToBounds = true,
- Children =
- {
- (target = new TestControl
- {
- Width = 10, Height = 10, [Canvas.LeftProperty] = 98, [Canvas.TopProperty] = 98,
- })
- }
- };
- Render(container);
- Assert.True(target.Rendered);
- }
- }
- [Fact]
- public void Out_Of_Bounds_Control_Should_Not_Be_Rendered()
- {
- using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
- {
- TestControl target;
- var container = new Canvas
- {
- Width = 100,
- Height = 100,
- ClipToBounds = true,
- Children =
- {
- (target = new TestControl
- {
- Width = 10,
- Height = 10,
- ClipToBounds = true,
- [Canvas.LeftProperty] = 110,
- [Canvas.TopProperty] = 110,
- })
- }
- };
- Render(container);
- Assert.False(target.Rendered);
- }
- }
- [Fact]
- public void Out_Of_Bounds_Child_Control_Should_Not_Be_Rendered()
- {
- using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
- {
- TestControl target;
- var container = new Canvas
- {
- Width = 100,
- Height = 100,
- ClipToBounds = true,
- Children =
- {
- new Canvas
- {
- Width = 100,
- Height = 100,
- [Canvas.LeftProperty] = 50,
- [Canvas.TopProperty] = 50,
- Children =
- {
- (target = new TestControl
- {
- Width = 10,
- Height = 10,
- ClipToBounds = true,
- [Canvas.LeftProperty] = 50,
- [Canvas.TopProperty] = 50,
- })
- }
- }
- }
- };
- Render(container);
- Assert.False(target.Rendered);
- }
- }
- [Fact]
- public void RenderTransform_Should_Be_Respected()
- {
- using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
- {
- TestControl target;
- var container = new Canvas
- {
- Width = 100,
- Height = 100,
- ClipToBounds = true,
- Children =
- {
- (target = new TestControl
- {
- Width = 10,
- Height = 10,
- [Canvas.LeftProperty] = 110,
- [Canvas.TopProperty] = 110,
- RenderTransform = new TranslateTransform(-100, -100),
- })
- }
- };
- Render(container);
- Assert.True(target.Rendered);
- }
- }
- [Fact]
- public void Negative_Margin_Should_Be_Respected()
- {
- using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
- {
- TestControl target;
- var container = new Canvas
- {
- Width = 100,
- Height = 100,
- ClipToBounds = true,
- Children =
- {
- new Border
- {
- Margin = new Thickness(100, 100, 0, 0),
- Child = target = new TestControl
- {
- Width = 10, Height = 10, Margin = new Thickness(-100, -100, 0, 0),
- }
- }
- }
- };
- Render(container);
- Assert.True(target.Rendered);
- }
- }
- private void Render(Control control)
- {
- var ctx = CreateDrawingContext();
- control.Measure(Size.Infinity);
- control.Arrange(new Rect(control.DesiredSize));
- ImmediateRenderer.Render(control, ctx);
- }
- private DrawingContext CreateDrawingContext()
- {
- return new PlatformDrawingContext(Mock.Of<IDrawingContextImpl>());
- }
- private class TestControl : Control
- {
- public bool Rendered { get; private set; }
- public override void Render(DrawingContext context)
- {
- Rendered = true;
- }
- }
- }
- }
|