Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(autoLayout): when hug and have a alignment (backport #892) #893

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/Uno.Toolkit.RuntimeTests/Tests/AutoLayoutTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,45 @@ public async Task When_Fixed_Dimensions_Padding_And_SpaceBetween_Vertical()
Assert.AreEqual(160, SUT.ActualHeight);
Assert.AreEqual(122, SUT.ActualWidth);
}

[TestMethod]
[RequiresFullWindow]
public async Task When_Hug_With_CounterAlignment()
{
var SUT = new AutoLayout()
{
PrimaryAxisAlignment = AutoLayoutAlignment.Center,
Background = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255)),
Width = 300,
Height = 100
};

var textBlock = new TextBlock()
{
Text = "Oh no!",
};

var button = new Button()
{
Content = "Something went wrong",
};

AutoLayout.SetCounterAlignment(textBlock, AutoLayoutAlignment.Center);
AutoLayout.SetCounterAlignment(button, AutoLayoutAlignment.End);

SUT.Children.Add(textBlock);
SUT.Children.Add(button);

await UnitTestUIContentHelperEx.SetContentAndWait(SUT);


var textBlockTransform = textBlock.TransformToVisual(SUT).TransformPoint(new Windows.Foundation.Point(0, 0));
var buttonTransform = button.TransformToVisual(SUT).TransformPoint(new Windows.Foundation.Point(0, 0));

var autoLayoutAcutalWidth = SUT.ActualWidth / 2;
var textBlockCenter = textBlock.ActualWidth / 2;

Assert.AreEqual(Math.Ceiling(autoLayoutAcutalWidth - textBlockCenter), Math.Ceiling(textBlockTransform!.X));
Assert.AreEqual(Math.Ceiling(SUT.ActualWidth - button.ActualWidth), Math.Ceiling(buttonTransform!.X));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ private static double MeasureChild(

if (child as FrameworkElement is { } frameworkElement)
{
UpdateCounterAlignmentToStretch(ref frameworkElement, isOrientationHorizontal, isPrimaryAlignmentStretch, isCounterAlignmentStretch);
UpdateCounterAlignment(ref frameworkElement, isOrientationHorizontal, isPrimaryAlignmentStretch, GetCounterAlignment(child));

var isStretch = isOrientationHorizontal ?
frameworkElement.VerticalAlignment is VerticalAlignment.Stretch :
Expand Down Expand Up @@ -481,19 +481,17 @@ private enum AutoLayoutRole : byte
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void UpdateCounterAlignmentToStretch(ref FrameworkElement frameworkElement, bool isHorizontal, bool isPrimaryAlignmentStretch, bool isCounterAlignmentStretch)
private static void UpdateCounterAlignment(ref FrameworkElement frameworkElement, bool isHorizontal, bool isPrimaryAlignmentStretch, AutoLayoutAlignment counterAlignment)
{
if (isHorizontal)
{
frameworkElement.HorizontalAlignment = isPrimaryAlignmentStretch ? HorizontalAlignment.Stretch : frameworkElement.HorizontalAlignment;
frameworkElement.VerticalAlignment = isCounterAlignmentStretch ? VerticalAlignment.Stretch : frameworkElement.VerticalAlignment;
frameworkElement.VerticalAlignment = counterAlignment.ToVerticalAlignment();
}
else
{
frameworkElement.VerticalAlignment = isPrimaryAlignmentStretch ? VerticalAlignment.Stretch : frameworkElement.VerticalAlignment;
frameworkElement.HorizontalAlignment = isCounterAlignmentStretch ? HorizontalAlignment.Stretch : frameworkElement.HorizontalAlignment;
frameworkElement.HorizontalAlignment = counterAlignment.ToHorizontalAlignment();
}
}


}
Loading