Skip to content

Commit e3e0d96

Browse files
authored
Merge pull request #20965 from ramezgerges/textblock_padding_regression
fix(textblock): adjust rendering offsets to match Padding
2 parents a511d60 + f187543 commit e3e0d96

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_TextBlock.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,25 @@ public async Task When_TextTrimmingNone()
10011001
Assert.AreEqual(0, states.Count, $"IsTextTrimmedChanged should not proc at all. states: {(string.Join(", ", states) is string { Length: > 0 } tmp ? tmp : "(-empty-)")}");
10021002
}
10031003

1004+
[TestMethod]
1005+
public async Task When_Padding()
1006+
{
1007+
if (!ApiInformation.IsTypePresent("Microsoft.UI.Xaml.Media.Imaging.RenderTargetBitmap"))
1008+
{
1009+
Assert.Inconclusive("RenderTargetBitmap is not supported on this platform");
1010+
}
1011+
1012+
var SUT = new TextBlock
1013+
{
1014+
Text = "text",
1015+
Padding = new Thickness(50),
1016+
Foreground = new SolidColorBrush(Colors.Red),
1017+
};
1018+
await UITestHelper.Load(SUT);
1019+
var screenshot = await UITestHelper.ScreenShot(SUT);
1020+
ImageAssert.DoesNotHaveColorInRectangle(screenshot, new Rectangle(0, 0, 50, 50), Colors.Red);
1021+
}
1022+
10041023
#if HAS_UNO // GetMouse is not available on WinUI
10051024
#region IsTextSelectionEnabled
10061025

src/Uno.UI/UI/Xaml/Controls/TextBlock/TextVisual.skia.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ internal override void Paint(in PaintingSession session)
3131
{
3232
if (_owner.TryGetTarget(out var owner))
3333
{
34+
session.Canvas.Save();
35+
session.Canvas.Translate((float)owner.Padding.Left, (float)owner.Padding.Top);
3436
owner.Inlines.Draw(in session);
37+
session.Canvas.Restore();
3538
}
3639
}
3740

0 commit comments

Comments
 (0)