Skip to content

Commit

Permalink
fix(viewbox): Fixed viewbox layout & clipping with the right solution…
Browse files Browse the repository at this point in the history
… after PR review.
  • Loading branch information
carldebilly committed Feb 2, 2021
1 parent cc6a097 commit 9de4e14
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Uno.UI/Extensions/UIViewExtensions.iOSmacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ string GetTransforms(Transform transform)
.Append(uiElement != null ? $" AvailableSize={uiElement.LastAvailableSize}" : "")
.Append(uiElement?.NeedsClipToSlot ?? false ? " CLIPPED_TO_SLOT" : "")
.Append(innerView is TextBlock textBlock ? $" Text=\"{textBlock.Text}\" - {textBlock.FontFamily}/{textBlock.FontSize}" : "")
.Append(innerView is Viewbox viewBox ? $" Scale={viewBox.scaleX}x{viewBox.scaleY} - Stretch={viewBox.Stretch}/{viewBox.StretchDirection}" : "")
.Append(innerView is Viewbox viewBox ? $" Stretch={viewBox.Stretch}/{viewBox.StretchDirection}" : "")
.Append(" " + transforms)
.AppendLine();
}
Expand Down
10 changes: 4 additions & 6 deletions src/Uno.UI/UI/Xaml/Controls/ViewBox/Viewbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ namespace Windows.UI.Xaml.Controls
[ContentProperty(Name = "Child")]
public partial class Viewbox : global::Windows.UI.Xaml.FrameworkElement
{
private const double SCALE_EPSILON = 0.00001d;

private readonly Border _container;
internal double scaleX { get; private set; }
internal double scaleY { get; private set; }

public Viewbox()
{
Expand Down Expand Up @@ -47,7 +47,7 @@ protected override Size MeasureOverride(Size availableSize)
)
);

(scaleX, scaleY) = GetScale(availableSize, measuredSize);
var (scaleX, scaleY) = GetScale(availableSize, measuredSize);

return new Size(
Math.Min(availableSize.Width, measuredSize.Width * scaleX),
Expand All @@ -64,7 +64,7 @@ protected override Size ArrangeOverride(Size finalSize)

var (scaleX, scaleY) = GetScale(finalSize, _container.DesiredSize);

if (Math.Abs(scaleX - 1d) < 0.001d && Math.Abs(scaleY - 1d) < 0.001d)
if (Math.Abs(scaleX - 1d) < SCALE_EPSILON && Math.Abs(scaleY - 1d) < SCALE_EPSILON)
{
_container.RenderTransform = null;
}
Expand All @@ -73,8 +73,6 @@ protected override Size ArrangeOverride(Size finalSize)
var transform = _container.RenderTransform as ScaleTransform ?? new ScaleTransform();
transform.ScaleX = scaleX;
transform.ScaleY = scaleY;
transform.CenterX = finalSize.Width / 2d;
transform.CenterY = finalSize.Height / 2d;
_container.RenderTransform = transform;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/FrameworkElement.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override void LayoutSubviews()

OnBeforeArrange();

var finalRect = RectFromUIRect(Bounds);
var finalRect = Parent is UIElement ? LayoutSlotWithMarginsAndAlignments : RectFromUIRect(Frame);

_layouter.Arrange(finalRect);

Expand Down

0 comments on commit 9de4e14

Please sign in to comment.