Skip to content

Commit

Permalink
Merge pull request #19004 from unoplatform/dev/mazi/translate-load
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund authored Dec 10, 2024
2 parents a6667aa + 640a0c0 commit ee8d7d9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml/Given_UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,32 @@ public async Task When_Element_Has_Translation_And_Visual_Has_Offset()
}
#endif

[TestMethod]
[RunsOnUIThread]
#if !__SKIA__
[Ignore("Translation X and Y axis is currently supported on Skia only")]
#endif
public async Task When_Translation_On_Load()
{
var sut = new Rectangle()
{
Width = 100,
Height = 100,
Fill = new SolidColorBrush(Microsoft.UI.Colors.Blue),
};
var canvas = new Canvas();
canvas.Width = 200;
canvas.Height = 200;
canvas.Children.Add(sut);
TestServices.WindowHelper.WindowContent = canvas;
await TestServices.WindowHelper.WaitForLoaded(sut);
sut.Translation += new Vector3(100, 100, 128);
await TestServices.WindowHelper.WaitForIdle();
var bitmap = await UITestHelper.ScreenShot(canvas);
ImageAssert.DoesNotHaveColorAt(bitmap, new Windows.Foundation.Point(50, 50), Microsoft.UI.Colors.Blue);
ImageAssert.HasColorAt(bitmap, new Windows.Foundation.Point(150, 150), Microsoft.UI.Colors.Blue);
}

#if HAS_UNO
[TestMethod]
[RunsOnUIThread]
Expand Down
16 changes: 16 additions & 0 deletions src/Uno.UI/UI/Xaml/UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ namespace Microsoft.UI.Xaml
public partial class UIElement : DependencyObject, IXUidProvider
{
private protected static bool _traceLayoutCycle;
#if !__SKIA__
private bool _warnedAboutTranslation;
#endif

private static readonly TypedEventHandler<UIElement, BringIntoViewRequestedEventArgs> OnBringIntoViewRequestedHandler =
(UIElement sender, BringIntoViewRequestedEventArgs args) => sender.OnBringIntoViewRequested(args);
Expand Down Expand Up @@ -265,6 +268,19 @@ public Vector3 Translation
if (_translation != value)
{
_translation = value;

#if !__SKIA__
if (!_warnedAboutTranslation &&
(_translation.X != 0 || _translation.Y != 0))
{
_warnedAboutTranslation = true;
if (this.Log().IsEnabled(LogLevel.Warning))
{
this.Log().LogWarning("Translation supports only Z-axis on this target.");
}
}
#endif

UpdateShadow();
InvalidateArrange();
}
Expand Down
8 changes: 7 additions & 1 deletion src/Uno.UI/UI/Xaml/UIElement.skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public partial class UIElement : DependencyObject, IVisualElement, IVisualElemen
private protected ContainerVisual _visual;
private Rect _lastFinalRect;
private Rect? _lastClippedFrame;
private Vector3 _lastTranslation;

public UIElement()
{
Expand Down Expand Up @@ -278,16 +279,21 @@ internal void ArrangeVisual(Rect finalRect, Rect? clippedFrame = default)

var oldFinalRect = _lastFinalRect;
var oldClippedFrame = _lastClippedFrame;
var oldTranslation = _lastTranslation;
_lastFinalRect = finalRect;
_lastClippedFrame = clippedFrame;
_lastTranslation = _translation;

var oldRect = oldFinalRect;
var newRect = finalRect;

var oldClip = oldClippedFrame;
var newClip = clippedFrame;

if (oldRect != newRect || oldClip != newClip || (_renderTransform?.FlowDirectionTransform ?? Matrix3x2.Identity) != GetFlowDirectionTransform())
if (oldRect != newRect ||
oldClip != newClip ||
oldTranslation != _translation ||
(_renderTransform?.FlowDirectionTransform ?? Matrix3x2.Identity) != GetFlowDirectionTransform())
{
if (
newRect.Width < 0
Expand Down

0 comments on commit ee8d7d9

Please sign in to comment.