Browse Source

Fix stack layout arrange when items use stretch and final size is mor…

…e than desired size.

Ported from f37ebd5bb2
pull/3424/head
Steven Kirk 7 years ago
parent
commit
55275e09de
  1. 18
      src/Avalonia.Layout/FlowLayoutAlgorithm.cs
  2. 1
      src/Avalonia.Layout/StackLayout.cs
  3. 1
      src/Avalonia.Layout/UniformGridLayout.cs

18
src/Avalonia.Layout/FlowLayoutAlgorithm.cs

@ -116,10 +116,11 @@ namespace Avalonia.Layout
public Size Arrange( public Size Arrange(
Size finalSize, Size finalSize,
VirtualizingLayoutContext context, VirtualizingLayoutContext context,
bool isWrapping,
LineAlignment lineAlignment, LineAlignment lineAlignment,
string layoutId) string layoutId)
{ {
ArrangeVirtualizingLayout(finalSize, lineAlignment, layoutId); ArrangeVirtualizingLayout(finalSize, lineAlignment, isWrapping, layoutId);
return new Size( return new Size(
Math.Max(finalSize.Width, _lastExtent.Width), Math.Max(finalSize.Width, _lastExtent.Width),
@ -546,6 +547,7 @@ namespace Avalonia.Layout
private void ArrangeVirtualizingLayout( private void ArrangeVirtualizingLayout(
Size finalSize, Size finalSize,
LineAlignment lineAlignment, LineAlignment lineAlignment,
bool isWrapping,
string layoutId) string layoutId)
{ {
// Walk through the realized elements one line at a time and // Walk through the realized elements one line at a time and
@ -565,7 +567,7 @@ namespace Avalonia.Layout
if (_orientation.MajorStart(currentBounds) != currentLineOffset) if (_orientation.MajorStart(currentBounds) != currentLineOffset)
{ {
spaceAtLineEnd = _orientation.Minor(finalSize) - _orientation.MinorStart(previousElementBounds) - _orientation.MinorSize(previousElementBounds); spaceAtLineEnd = _orientation.Minor(finalSize) - _orientation.MinorStart(previousElementBounds) - _orientation.MinorSize(previousElementBounds);
PerformLineAlignment(i - countInLine, countInLine, spaceAtLineStart, spaceAtLineEnd, currentLineSize, lineAlignment, layoutId); PerformLineAlignment(i - countInLine, countInLine, spaceAtLineStart, spaceAtLineEnd, currentLineSize, lineAlignment, isWrapping, finalSize, layoutId);
spaceAtLineStart = _orientation.MinorStart(currentBounds); spaceAtLineStart = _orientation.MinorStart(currentBounds);
countInLine = 0; countInLine = 0;
currentLineOffset = _orientation.MajorStart(currentBounds); currentLineOffset = _orientation.MajorStart(currentBounds);
@ -582,7 +584,7 @@ namespace Avalonia.Layout
if (countInLine > 0) if (countInLine > 0)
{ {
var spaceAtEnd = _orientation.Minor(finalSize) - _orientation.MinorStart(previousElementBounds) - _orientation.MinorSize(previousElementBounds); var spaceAtEnd = _orientation.Minor(finalSize) - _orientation.MinorStart(previousElementBounds) - _orientation.MinorSize(previousElementBounds);
PerformLineAlignment(realizedElementCount - countInLine, countInLine, spaceAtLineStart, spaceAtEnd, currentLineSize, lineAlignment, layoutId); PerformLineAlignment(realizedElementCount - countInLine, countInLine, spaceAtLineStart, spaceAtEnd, currentLineSize, lineAlignment, isWrapping, finalSize, layoutId);
} }
} }
} }
@ -596,6 +598,8 @@ namespace Avalonia.Layout
double spaceAtLineEnd, double spaceAtLineEnd,
double lineSize, double lineSize,
LineAlignment lineAlignment, LineAlignment lineAlignment,
bool isWrapping,
Size finalSize,
string layoutId) string layoutId)
{ {
for (int rangeIndex = lineStartIndex; rangeIndex < lineStartIndex + countInLine; ++rangeIndex) for (int rangeIndex = lineStartIndex; rangeIndex < lineStartIndex + countInLine; ++rangeIndex)
@ -661,6 +665,14 @@ namespace Avalonia.Layout
} }
bounds = bounds.Translate(-_lastExtent.Position); bounds = bounds.Translate(-_lastExtent.Position);
if (!isWrapping)
{
_orientation.SetMinorSize(
ref bounds,
Math.Max(_orientation.MinorSize(bounds), _orientation.Minor(finalSize)));
}
var element = _elementManager.GetAt(rangeIndex); var element = _elementManager.GetAt(rangeIndex);
element.Arrange(bounds); element.Arrange(bounds);
} }

1
src/Avalonia.Layout/StackLayout.cs

@ -279,6 +279,7 @@ namespace Avalonia.Layout
var value = GetFlowAlgorithm(context).Arrange( var value = GetFlowAlgorithm(context).Arrange(
finalSize, finalSize,
context, context,
false,
FlowLayoutAlgorithm.LineAlignment.Start, FlowLayoutAlgorithm.LineAlignment.Start,
LayoutId); LayoutId);

1
src/Avalonia.Layout/UniformGridLayout.cs

@ -446,6 +446,7 @@ namespace Avalonia.Layout
var value = GetFlowAlgorithm(context).Arrange( var value = GetFlowAlgorithm(context).Arrange(
finalSize, finalSize,
context, context,
true,
(FlowLayoutAlgorithm.LineAlignment)_itemsJustification, (FlowLayoutAlgorithm.LineAlignment)_itemsJustification,
LayoutId); LayoutId);
return new Size(value.Width, value.Height); return new Size(value.Width, value.Height);

Loading…
Cancel
Save