Skip to content

Commit

Permalink
feat: Support for UIElement.ActualSize
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Jan 23, 2021
1 parent ffb4795 commit a6b9cbe
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private void RecalculateRects()
return;
}

var canvasRect = new Rect(canvasOrigin, canvas.InternalActualSize);
var canvasRect = new Rect(canvasOrigin, canvas.AssignedActualSize);

var displayRects = spanningRects
.Select(r => r.PhysicalToLogicalPixels().IntersectWith(canvasRect))
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/Generated/3.0.0.0/Windows.UI.Xaml/UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public bool UseLayoutRounding
}
}
#endif
#if __ANDROID__ || __IOS__ || NET461 || __WASM__ || __SKIA__ || __NETSTD_REFERENCE__ || __MACOS__
#if false
[global::Uno.NotImplemented("__ANDROID__", "__IOS__", "NET461", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__", "__MACOS__")]
public global::System.Numerics.Vector2 ActualSize
{
Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/Services/LayoutManager.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static void Arrange()
{
typeof(LayoutManager).Log().LogDebug($"Measuring {view} with {GetAncestorCount(view)} ancestors in visual tree.");
}
IFrameworkElementHelper.Measure(view, view.InternalActualSize.Add(view.Margin));
IFrameworkElementHelper.Measure(view, view.AssignedActualSize.Add(view.Margin));
}
foreach (var view in queue)
{
Expand Down
7 changes: 2 additions & 5 deletions src/Uno.UI/UI/Xaml/FrameworkElement.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ namespace Windows.UI.Xaml
public partial class FrameworkElement
{
private Size? _lastLayoutSize;
private Size _actualSize;

internal Size InternalActualSize => _actualSize;

/// <summary>
/// The parent of the <see cref="FrameworkElement"/> in the visual tree, which may differ from its <see cref="Parent"/> (ie if it's a child of a native view).
Expand Down Expand Up @@ -269,8 +266,8 @@ protected override void OnLayoutCore(bool changed, int left, int top, int right,
);
}

var previousSize = _actualSize;
_actualSize = newSize;
var previousSize = AssignedActualSize;
AssignedActualSize = newSize;

if (
// If the layout has changed, but the final size has not, this is just a translation.
Expand Down
9 changes: 3 additions & 6 deletions src/Uno.UI/UI/Xaml/FrameworkElement.Skia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
using System.Collections;
using Microsoft.Extensions.Logging;
using Uno.UI.Xaml;
using System.Numerics;

namespace Windows.UI.Xaml
{
public partial class FrameworkElement : IEnumerable
{
private Size _actualSize;

private readonly static Thickness _thicknessCache = Thickness.Empty;

public FrameworkElement()
Expand All @@ -37,13 +36,11 @@ public bool HasParent()
return Parent != null;
}

internal void SetActualSize(Size size) => _actualSize = size;
internal void SetActualSize(Size size) => AssignedActualSize = size;

public double ActualWidth => GetActualWidth();
public double ActualHeight => GetActualHeight();

private protected virtual double GetActualWidth() => _actualSize.Width;
private protected virtual double GetActualHeight() => _actualSize.Height;
public double ActualHeight => GetActualHeight();

partial void OnMeasurePartial(Size slotSize)
{
Expand Down
8 changes: 2 additions & 6 deletions src/Uno.UI/UI/Xaml/FrameworkElement.wasm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ public bool HasParent()
{
return Parent != null;
}

private Size _actualSize;

public double ActualWidth => GetActualWidth();
public double ActualHeight => GetActualHeight();

Expand All @@ -106,10 +105,7 @@ internal void RaiseSizeChanged(SizeChangedEventArgs args)
_renderTransform?.UpdateSize(args.NewSize);
}

internal void SetActualSize(Size size) => _actualSize = size;

private protected virtual double GetActualWidth() => _actualSize.Width;
private protected virtual double GetActualHeight() => _actualSize.Height;
internal void SetActualSize(Size size) => AssignedActualSize = size;

partial void OnGenericPropertyUpdatedPartial(DependencyPropertyChangedEventArgs args);

Expand Down
5 changes: 5 additions & 0 deletions src/Uno.UI/UI/Xaml/IFrameworkElementImplementation.iOS.tt
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,10 @@ namespace <#= mixin.NamespaceName #>
public double ActualWidth => GetActualWidth();
public double ActualHeight => GetActualHeight();

#if <#= !mixin.IsUIControl #>
private protected virtual double GetActualWidth() => _actualSize.Width;
private protected virtual double GetActualHeight() => _actualSize.Height;
#endif

private Size _actualSize;
public override CGRect Frame
Expand All @@ -353,6 +355,9 @@ namespace <#= mixin.NamespaceName #>
#if <#= mixin.IsFrameworkElement #>
RenderSize = _actualSize;
#endif
#if <#= mixin.IsUIControl #>
AssignedActualSize = _actualSize;
#endif

CGAffineTransform? oldTransform = null;
if (!Transform.IsIdentity)
Expand Down
6 changes: 5 additions & 1 deletion src/Uno.UI/UI/Xaml/IFrameworkElementImplementation.macOS.tt
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,10 @@ namespace <#= mixin.NamespaceName #>
public double ActualWidth => GetActualWidth();
public double ActualHeight => GetActualHeight();

#if <#= !mixin.IsUIControl #>
private protected virtual double GetActualWidth() => _actualSize.Width;
private protected virtual double GetActualHeight() => _actualSize.Height;
#endif

private Size _actualSize;
public override CGRect Frame
Expand All @@ -355,7 +357,9 @@ namespace <#= mixin.NamespaceName #>
#if <#= mixin.IsFrameworkElement #>
RenderSize = _actualSize;
#endif

#if <#= mixin.IsUIControl #>
AssignedActualSize = _actualSize;
#endif

CoreAnimation.CATransform3D? oldTransform = null;
if (Layer != null && !Layer.Transform.IsIdentity)
Expand Down
8 changes: 8 additions & 0 deletions src/Uno.UI/UI/Xaml/UIElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ private void Initialize()
this.SetValue(KeyboardAcceleratorsProperty, new List<KeyboardAccelerator>(0), DependencyPropertyValuePrecedences.DefaultValue);
}

public Vector2 ActualSize => new Vector2((float)GetActualWidth(), (float)GetActualHeight());

internal Size AssignedActualSize { get; set; }

private protected virtual double GetActualWidth() => AssignedActualSize.Width;

private protected virtual double GetActualHeight() => AssignedActualSize.Height;

string IXUidProvider.Uid
{
get => _uid;
Expand Down

0 comments on commit a6b9cbe

Please sign in to comment.