Skip to content

Commit

Permalink
fix(autolayout): Horizontal padding issue when spacebetween and indep…
Browse files Browse the repository at this point in the history
…endant. (#503)
  • Loading branch information
Robert-Louis committed Mar 15, 2023
1 parent 3edaf9f commit fdf375c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
40 changes: 25 additions & 15 deletions src/Uno.Toolkit.RuntimeTests/Tests/AutoLayoutTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ public async Task When_Padding(bool isStretch, Orientation orientation, int[] pa

[TestMethod]
[RequiresFullWindow]
public async Task When_Space_between_With_AbsolutePosition()
[DataRow(Orientation.Vertical, 10, 340, 280)]
[DataRow(Orientation.Horizontal, 10, 240, 100)]
public async Task When_Space_between_With_AbsolutePosition(Orientation orientation, double expected1, double expected2, double expected3)
{
var SUT = new AutoLayout()
{
Expand All @@ -248,35 +250,36 @@ public async Task When_Space_between_With_AbsolutePosition()
Justify = AutoLayoutJustify.SpaceBetween,
Width = 300,
Height = 400,
Orientation = orientation,
};

var border1 = new Border()
{
Background = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255)),
Width = 200,
Height = 50,
Width = SUT.Orientation == Orientation.Vertical ? 200 : 50,
Height = SUT.Orientation == Orientation.Vertical ? 50 : 200,
};

var border2 = new Border()
{
Background = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255)),
Width = 200,
Height = 50,
Width = SUT.Orientation == Orientation.Vertical ? 200 : 50,
Height = SUT.Orientation == Orientation.Vertical ? 50 : 200,
};

var border3 = new Border()
{
Background = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255)),
Width = 200,
Height = 50,
Width = SUT.Orientation == Orientation.Vertical ? 200 : 50,
Height = SUT.Orientation == Orientation.Vertical ? 50 : 200,
};

var border4 = new Border()
{
Background = new SolidColorBrush(Color.FromArgb(255, 0, 0, 255)),
Width = 200,
Height = 50,
Margin = new Thickness(10, 280,0 ,0),
Width = SUT.Orientation == Orientation.Vertical ? 200 : 50,
Height = SUT.Orientation == Orientation.Vertical ? 50 : 200,
Margin = SUT.Orientation == Orientation.Vertical ? new Thickness(10, 280,0 ,0) : new Thickness(100, 10, 0, 0),
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Left,
};
Expand All @@ -294,10 +297,17 @@ public async Task When_Space_between_With_AbsolutePosition()
var border3Transform = (MatrixTransform)border3.TransformToVisual(SUT);
var border4Transform = (MatrixTransform)border4.TransformToVisual(SUT);


Assert.AreEqual(10, border1Transform!.Matrix.OffsetY!);
Assert.AreEqual(340, border3Transform!.Matrix.OffsetY!);
Assert.AreEqual(280, border4Transform!.Matrix.OffsetY!);
if (orientation == Orientation.Vertical)
{
Assert.AreEqual(expected1, border1Transform!.Matrix.OffsetY!);
Assert.AreEqual(expected2, border3Transform!.Matrix.OffsetY!);
Assert.AreEqual(expected3, border4Transform!.Matrix.OffsetY!);
}
else
{
Assert.AreEqual(expected1, border1Transform!.Matrix.OffsetX!);
Assert.AreEqual(expected2, border3Transform!.Matrix.OffsetX!);
Assert.AreEqual(expected3, border4Transform!.Matrix.OffsetX!);
}
}

}
2 changes: 1 addition & 1 deletion src/Uno.Toolkit.UI/Controls/AutoLayout/AutoLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ private void UpdateAutoLayout()
}
}

if (hasIndependentLayout && atLeastOneChildFillAvailableSpaceInPrimaryAxis is not true && PrimaryAxisAlignment != AutoLayoutAlignment.End)
if (hasIndependentLayout && atLeastOneChildFillAvailableSpaceInPrimaryAxis is not true && PrimaryAxisAlignment != AutoLayoutAlignment.End && !hasSpaceBetween)
{
//We need to make sure that the independent layout can span all across his parent
_grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
Expand Down

0 comments on commit fdf375c

Please sign in to comment.