Skip to content

Commit 007ab33

Browse files
marcelwgnStephenLPeters
authored andcommitted
Fix bug with UniformGridLayout MaximumRowsOrColumns and requested size (#1802)
* Add test for UniformGridLayout measure bug * Update test so it actually tests #1549 * Fix bug with stretching of UniformGridLayout when it should not * Fix indentation
1 parent c6858f2 commit 007ab33

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

dev/Repeater/APITests/FlowLayoutTests.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,64 @@ public void ValidateGridLayoutMaximumRowsOrColumns()
580580
});
581581
}
582582

583+
[TestMethod]
584+
public void ValidateGridLayoutDesiredSizingWithMaxRowsOrColumnsSet()
585+
{
586+
RunOnUIThread.Execute(() =>
587+
{
588+
foreach (ScrollOrientation scrollOrientation in Enum.GetValues(typeof(ScrollOrientation)))
589+
{
590+
Log.Comment(string.Format("ScrollOrientation: {0}", scrollOrientation));
591+
var om = new OrientationBasedMeasures(scrollOrientation, useLayoutRounding: true);
592+
const int numItems = 4;
593+
594+
int itemSize = 100;
595+
596+
LayoutPanel panel = new LayoutPanel();
597+
var layout = new UniformGridLayout() {
598+
Orientation = scrollOrientation.ToOrthogonalLayoutOrientation(),
599+
ItemsJustification = UniformGridLayoutItemsJustification.Start,
600+
MinItemWidth = itemSize,
601+
MinItemHeight = itemSize,
602+
MinRowSpacing = 0,
603+
MinColumnSpacing = 0
604+
};
605+
606+
for (int i = 0; i < numItems; i++)
607+
{
608+
panel.Children.Add(new Button() { Content = i,Width = itemSize,Height = itemSize });
609+
}
610+
611+
panel.Layout = layout;
612+
Content = panel;
613+
614+
// Place in top left corner to prevent stretch of panel
615+
panel.VerticalAlignment = VerticalAlignment.Top;
616+
panel.HorizontalAlignment = HorizontalAlignment.Left;
617+
layout.ItemsJustification = UniformGridLayoutItemsJustification.Start;
618+
619+
for(int i = 1; i < numItems; i++)
620+
{
621+
layout.MaximumRowsOrColumns = i;
622+
panel.UpdateLayout();
623+
624+
if (om.IsVerical)
625+
{
626+
// Vertical so fill columns first
627+
Verify.AreEqual(itemSize * i, panel.DesiredSize.Width);
628+
Verify.AreEqual(Math.Ceiling((double)numItems / (double)i) * itemSize, panel.DesiredSize.Height);
629+
}
630+
else
631+
{
632+
// Horizontal, fill rows first
633+
Verify.AreEqual(itemSize * i, panel.DesiredSize.Height);
634+
Verify.AreEqual(Math.Ceiling((double)numItems / (double)i) * itemSize, panel.DesiredSize.Width);
635+
}
636+
}
637+
638+
}
639+
});
640+
}
583641

584642
[TestMethod]
585643
public void ValidateFlowLayout()

dev/Repeater/UniformGridLayout.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,11 @@ winrt::Rect UniformGridLayout::Algorithm_GetExtent(
213213

214214
if (itemsCount > 0)
215215
{
216+
// Only use all of the space if item stretch is fill, otherwise size layout according to items placed
216217
extent.*MinorSize() =
217-
std::isfinite(availableSizeMinor) ?
218+
std::isfinite(availableSizeMinor) && m_itemsStretch == winrt::UniformGridLayoutItemsStretch::Fill ?
218219
availableSizeMinor :
219-
std::max(0.0f, itemsCount * GetMinorSizeWithSpacing(context) - static_cast<float>(MinItemSpacing()));
220+
std::max(0.0f, itemsPerLine * GetMinorSizeWithSpacing(context) - static_cast<float>(MinItemSpacing()));
220221
extent.*MajorSize() = std::max(0.0f, (itemsCount / itemsPerLine) * lineSize - static_cast<float>(LineSpacing()));
221222

222223
if (firstRealized)

0 commit comments

Comments
 (0)