Skip to content

Commit

Permalink
chore: Clean-up code before merge
Browse files Browse the repository at this point in the history
  • Loading branch information
carldebilly committed May 17, 2023
1 parent cf1ba82 commit 1c0d602
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ protected override Size ArrangeOverride(Size finalSize)
var justify = Justify;
var primaryAxisAlignment = PrimaryAxisAlignment;
var padding = Padding;
var spacing = Spacing is > double.NegativeInfinity and < double.PositiveInfinity and { } s ? s : 0d;
var spacing = Spacing.FiniteOrDefault(0d);
var isHorizontal = orientation == Orientation.Horizontal;
// BorderBrush is not set, so we don't need to consider the border thickness
var borderThickness = BorderBrush == null ? default : BorderThickness;
var borderThicknessLenght = borderThickness.GetLength(orientation);
var borderThickness = BorderBrush is null ? default : BorderThickness;

var borderThicknessLength = borderThickness.GetLength(orientation);

var totalNonFilledStackedSize = 0d;
var numberOfFilledChildren = 0;
Expand Down Expand Up @@ -100,7 +100,7 @@ protected override Size ArrangeOverride(Size finalSize)
var totalPaddingSize = startPadding + endPadding;

// Available Size is the final size minus the border thickness and the padding
var availableSizeForStackedChildren = finalSize.GetLength(orientation) - (borderThicknessLenght + totalPaddingSize);
var availableSizeForStackedChildren = finalSize.GetLength(orientation) - (borderThicknessLength + totalPaddingSize);
EnsureZeroFloor(ref availableSizeForStackedChildren);

// Start the offset at the border + start padding
Expand All @@ -124,7 +124,12 @@ protected override Size ArrangeOverride(Size finalSize)
: spacing;

var primaryAxisAlignmentOffset = PrimaryAxisAlignmentOffsetSize(
primaryAxisAlignment, availableSizeForStackedChildren, totalNonFilledStackedSize, atLeastOneFilledChild, spacing, numberOfStackedChildren);
primaryAxisAlignment,
availableSizeForStackedChildren,
totalNonFilledStackedSize,
atLeastOneFilledChild,
spacing,
numberOfStackedChildren);

currentOffset += primaryAxisAlignmentOffset;

Expand Down Expand Up @@ -154,7 +159,7 @@ protected override Size ArrangeOverride(Size finalSize)
? filledChildrenSize
: child.MeasuredLength;

var offsetRelativeToPadding = currentOffset - (startPadding + borderThicknessLenght);
var offsetRelativeToPadding = currentOffset - (startPadding + borderThicknessLength);

if (childLength > availableSizeForStackedChildren - offsetRelativeToPadding)
{
Expand Down Expand Up @@ -201,14 +206,14 @@ protected override Size ArrangeOverride(Size finalSize)

ApplyMinMaxValues(child.Element, orientation, ref childSize);

var counterAlignmentOffset =
var counterAlignmentOffset =
ComputeCounterAlignmentOffset(counterAlignment, childFinalCounterLength, availableCounterLength, counterStartPadding, borderThickness.GetCounterStartLength(orientation));

var childOffsetPosition = new Point(
isHorizontal ? currentOffset : counterAlignmentOffset,
isHorizontal ? counterAlignmentOffset : currentOffset);

// 3c. Arrange the child to its final position, determined by the calculated offset and size
// Arrange the child to its final position, determined by the calculated offset and size
child.Element.Arrange(new Rect(childOffsetPosition, childSize));

// Increment the offset for the next child
Expand Down Expand Up @@ -249,19 +254,19 @@ private static void ApplyMinMaxValues(UIElement element, Orientation orientation
var minWidth = frameworkElement.MinWidth;
var minHeight = frameworkElement.MinHeight;

var primaryLenght = GetPrimaryLength(element);
var counterLenght = GetCounterLength(element);
var primaryLength = GetPrimaryLength(element);
var counterLength = GetCounterLength(element);

// Apply primaryLenght and counterLenght constraints, if defined
// Apply primaryLength and counterLength constraints, if defined
if (orientation is Orientation.Horizontal)
{
if (!double.IsNaN(primaryLenght)) desiredSize.Width = primaryLenght;
if (!double.IsNaN(counterLenght)) desiredSize.Height = counterLenght;
if (!double.IsNaN(primaryLength)) desiredSize.Width = primaryLength;
if (!double.IsNaN(counterLength)) desiredSize.Height = counterLength;
}
else
{
if (!double.IsNaN(primaryLenght)) desiredSize.Height = primaryLenght;
if (!double.IsNaN(counterLenght)) desiredSize.Width = counterLenght;
if (!double.IsNaN(primaryLength)) desiredSize.Height = primaryLength;
if (!double.IsNaN(counterLength)) desiredSize.Width = counterLength;
}

// Apply Width and Height constraints, if defined
Expand All @@ -283,8 +288,7 @@ private static void ApplyMinMaxValues(UIElement element, Orientation orientation
double childCounterLength,
double availableCounterLength,
double counterStartPadding,
double counterBorderThickness
)
double counterBorderThickness)
{
var alignmentOffsetSize = availableCounterLength - childCounterLength;

Expand All @@ -299,7 +303,10 @@ private static void ApplyMinMaxValues(UIElement element, Orientation orientation
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static double ComputeSpaceBetween(double availableSizeForStackedChildren, double totalNonFilledStackedSize, int numberOfStackedChildren)
private static double ComputeSpaceBetween(
double availableSizeForStackedChildren,
double totalNonFilledStackedSize,
int numberOfStackedChildren)
{
var availableSizeForStackedSpaceBetween = availableSizeForStackedChildren - totalNonFilledStackedSize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,8 @@ protected override Size MeasureOverride(Size availableSize)
var orientation = Orientation;
var children = Children;
var justify = Justify;
var spacing = Spacing;
var borderThickness = BorderThickness;

if (BorderBrush is null)
{
// BorderBrush is not set, so we don't need to consider the border thickness
borderThickness = default;
}
var spacing = Spacing.FiniteOrDefault(0d);
var borderThickness = BorderBrush is null ? default : BorderThickness;

// 0. Establish start remaining sizes to dispatch, according to the orientation
var remainingSize = availableSize.GetLength(orientation) - borderThickness.GetLength(orientation);
Expand Down Expand Up @@ -109,8 +103,12 @@ protected override Size MeasureOverride(Size availableSize)

desiredSize = orientation switch
{
Orientation.Horizontal => new Size(desiredSizeInPrimaryOrientation + paddingSize, desiredCounterSize + Padding.GetCounterLength(orientation)),
Orientation.Vertical => new Size(desiredCounterSize + Padding.GetCounterLength(orientation), desiredSizeInPrimaryOrientation + paddingSize),
Orientation.Horizontal => new Size(
width: desiredSizeInPrimaryOrientation + paddingSize,
height: desiredCounterSize + Padding.GetCounterLength(orientation)),
Orientation.Vertical => new Size(
width: desiredCounterSize + Padding.GetCounterLength(orientation),
height: desiredSizeInPrimaryOrientation + paddingSize),
_ => throw new ArgumentOutOfRangeException(),
};
}
Expand Down Expand Up @@ -153,7 +151,6 @@ private void ApplyMinMaxValues(ref Size desiredSize)
_calculatedChildren = new CalculatedChildren[children.Count];
}


var numberOfStackedChildren = children.Count;
var atLeastOneFilledChild = false;

Expand Down Expand Up @@ -203,7 +200,11 @@ private void ApplyMinMaxValues(ref Size desiredSize)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void MeasureFixedChildren(Orientation orientation, double availableCounterSize, ref double remainingSize, ref double desiredCounterSize)
private void MeasureFixedChildren(
Orientation orientation,
double availableCounterSize,
ref double remainingSize,
ref double desiredCounterSize)
{
for (var i = 0; i < _calculatedChildren!.Length; i++)
{
Expand All @@ -228,7 +229,11 @@ private void MeasureFixedChildren(Orientation orientation, double availableCount
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void MeasureHugChildren(Orientation orientation, double availableCounterSize, ref double remainingSize, ref double desiredCounterSize)
private void MeasureHugChildren(
Orientation orientation,
double availableCounterSize,
ref double remainingSize,
ref double desiredCounterSize)
{
for (var i = 0; i < _calculatedChildren!.Length; i++)
{
Expand All @@ -254,7 +259,11 @@ private void MeasureHugChildren(Orientation orientation, double availableCounter
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool MeasureFilledChildren(Orientation orientation, double availableCounterSize, ref double remainingSize, ref double desiredCounterSize)
private bool MeasureFilledChildren(
Orientation orientation,
double availableCounterSize,
ref double remainingSize,
ref double desiredCounterSize)
{
if (double.IsInfinity(remainingSize))
{
Expand Down Expand Up @@ -347,7 +356,10 @@ private static void EnsureZeroFloor(ref double sizeValue)
}
}

private double MeasureIndependentChildren(Size availableSize, Thickness borderThickness, Orientation orientation,
private double MeasureIndependentChildren(
Size availableSize,
Thickness borderThickness,
Orientation orientation,
ref double desiredCounterSize)
{
var resultSize = new Size();
Expand Down Expand Up @@ -382,7 +394,6 @@ private static void EnsureZeroFloor(ref double sizeValue)
return -1;
}

// TODO: check if we need to do this
desiredCounterSize = Math.Max(
desiredCounterSize,
orientation switch
Expand Down
18 changes: 0 additions & 18 deletions src/Uno.Toolkit.UI/Controls/AutoLayout/AutoLayoutChildren.cs

This file was deleted.

0 comments on commit 1c0d602

Please sign in to comment.