Browse Source

Respect negative margins when culling.

And make ClipToBounds = true as default on TemplatedControl to allow us
to cull more.
Steven Kirk 10 years ago
parent
commit
416eb1d7a5

+ 1 - 0
src/Perspex.Controls/Primitives/TemplatedControl.cs

@@ -91,6 +91,7 @@ namespace Perspex.Controls.Primitives
         /// </summary>
         static TemplatedControl()
         {
+            ClipToBoundsProperty.OverrideDefaultValue<TemplatedControl>(true);
             TemplateProperty.Changed.AddClassHandler<TemplatedControl>(x => x.OnTemplateChanged);
         }
 

+ 1 - 1
src/Perspex.SceneGraph/Rendering/RendererMixin.cs

@@ -127,7 +127,7 @@ namespace Perspex.Rendering
                     {
                         var childBounds = GetTransformedBounds(child);
 
-                        if (clipRect.Intersects(childBounds))
+                        if (!child.ClipToBounds || clipRect.Intersects(childBounds))
                         {
                             var childClipRect = clipRect.Translate(-childBounds.Position);
                             context.Render(child, childClipRect);

+ 1 - 0
tests/Perspex.Layout.UnitTests/Perspex.Layout.UnitTests.csproj

@@ -86,6 +86,7 @@
   </Choose>
   <ItemGroup>
     <Compile Include="FullLayoutTests.cs" />
+    <Compile Include="MeasureTests.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>

+ 21 - 26
tests/Perspex.SceneGraph.UnitTests/RenderTests_Culling.cs

@@ -52,6 +52,7 @@ namespace Perspex.SceneGraph.UnitTests
                     {
                         Width = 10,
                         Height = 10,
+                        ClipToBounds = true,
                         [Canvas.LeftProperty] = 110,
                         [Canvas.TopProperty] = 110,
                     })
@@ -86,6 +87,7 @@ namespace Perspex.SceneGraph.UnitTests
                             {
                                 Width = 10,
                                 Height = 10,
+                                ClipToBounds = true,
                                 [Canvas.LeftProperty] = 50,
                                 [Canvas.TopProperty] = 50,
                             })
@@ -99,9 +101,8 @@ namespace Perspex.SceneGraph.UnitTests
             Assert.False(target.Rendered);
         }
 
-
         [Fact]
-        public void Nested_ClipToBounds_Should_Be_Respected()
+        public void RenderTransform_Should_Be_Respected()
         {
             TestControl target;
             var container = new Canvas
@@ -111,32 +112,24 @@ namespace Perspex.SceneGraph.UnitTests
                 ClipToBounds = true,
                 Children = new Controls.Controls
                 {
-                    new Canvas
+                    (target = new TestControl
                     {
-                        Width = 50,
-                        Height = 50,
-                        ClipToBounds = true,
-                        Children = new Controls.Controls
-                        {
-                            (target = new TestControl
-                            {
-                                Width = 10,
-                                Height = 10,
-                                [Canvas.LeftProperty] = 50,
-                                [Canvas.TopProperty] = 50,
-                            })
-                        }
-                    }
+                        Width = 10,
+                        Height = 10,
+                        [Canvas.LeftProperty] = 110,
+                        [Canvas.TopProperty] = 110,
+                        RenderTransform = new TranslateTransform(-100, -100),
+                    })
                 }
             };
 
             Render(container);
 
-            Assert.False(target.Rendered);
+            Assert.True(target.Rendered);
         }
 
         [Fact]
-        public void RenderTransform_Should_Be_Respected()
+        public void Negative_Margin_Should_Be_Respected()
         {
             TestControl target;
             var container = new Canvas
@@ -146,14 +139,16 @@ namespace Perspex.SceneGraph.UnitTests
                 ClipToBounds = true,
                 Children = new Controls.Controls
                 {
-                    (target = new TestControl
+                    new Border
                     {
-                        Width = 10,
-                        Height = 10,
-                        [Canvas.LeftProperty] = 110,
-                        [Canvas.TopProperty] = 110,
-                        RenderTransform = new TranslateTransform(-100, -100),
-                    })
+                        Margin = new Thickness(100, 100, 0, 0),
+                        Child = target = new TestControl
+                        {
+                            Width = 10,
+                            Height = 10,
+                            Margin = new Thickness(-100, -100, 0, 0),
+                        }
+                    }
                 }
             };