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 WrapPanel when ItemWidth < Available Size #17636

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions src/Avalonia.Controls/WrapPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected override Size MeasureOverride(Size constraint)
var childConstraint = new Size(
itemWidthSet ? itemWidth : constraint.Width,
itemHeightSet ? itemHeight : constraint.Height);

for (int i = 0, count = children.Count; i < count; i++)
{
var child = children[i];
Expand Down Expand Up @@ -213,14 +213,18 @@ protected override Size ArrangeOverride(Size finalSize)
if (MathUtilities.GreaterThan(sz.U, uvFinalSize.U)) // The element is wider then the constraint - give it a separate line
{
// Switch to next line which only contain one element
ArrangeLine(accumulatedV, sz.V, i, ++i, useItemU, itemU);
ArrangeLine(accumulatedV, sz.V, i, i + 1, useItemU, itemU);

accumulatedV += sz.V;
curLineSize = new UVSize(orientation);
firstInLine = i + 1;
}
else
{
firstInLine = i;
}
firstInLine = i;
}
else // Continue to accumulate a line
else // Continue to accumulate in the current line
{
curLineSize.U += sz.U;
curLineSize.V = Max(sz.V, curLineSize.V);
Expand Down