Browse Source

Merge pull request #2382 from AvaloniaUI/fixes/2381-textnode-offset

Fix incorrect dirty rects for text drawn with an offset
Steven Kirk 6 years ago
parent
commit
a450303fb3

+ 1 - 1
src/Avalonia.Visuals/Rendering/SceneGraph/TextNode.cs

@@ -27,7 +27,7 @@ namespace Avalonia.Rendering.SceneGraph
             Point origin,
             IFormattedTextImpl text,
             IDictionary<IVisual, Scene> childScenes = null)
-            : base(text.Bounds, transform, null)
+            : base(text.Bounds.Translate(origin), transform, null)
         {
             Transform = transform;
             Foreground = foreground?.ToImmutable();

+ 25 - 0
tests/Avalonia.Visuals.UnitTests/Rendering/SceneGraph/TextNodeTests.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Avalonia.Platform;
+using Avalonia.Rendering.SceneGraph;
+using Moq;
+using Xunit;
+
+namespace Avalonia.Visuals.UnitTests.Rendering.SceneGraph
+{
+    public class TextNodeTests
+    {
+        [Fact]
+        public void Bounds_Should_Be_Offset_By_Origin()
+        {
+            var target = new TextNode(
+                Matrix.Identity,
+                null,
+                new Point(10, 10),
+                Mock.Of<IFormattedTextImpl>(x => x.Bounds == new Rect(5, 5, 50, 50)));
+
+            Assert.Equal(new Rect(15, 15, 50, 50), target.Bounds);
+        }
+    }
+}