Skip to content

Commit

Permalink
Fix FlowLayout LineSpacing and MinItemSpacing (microsoft/microsoft-ui…
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinnara committed Apr 14, 2020
1 parent e328beb commit 8f0f49e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
9 changes: 6 additions & 3 deletions ModernWpf.Controls/Repeater/Layouts/FlowLayout/FlowLayout.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Windows;
Expand Down Expand Up @@ -488,9 +491,9 @@ private bool DoesRealizationWindowOverlapExtent(Rect realizationWindow, Rect ext
return OrientationBasedMeasures.MajorEnd(realizationWindow) >= OrientationBasedMeasures.MajorStart(extent) && OrientationBasedMeasures.MajorStart(realizationWindow) <= OrientationBasedMeasures.MajorEnd(extent);
}

private double LineSpacing => new ScrollOrientation() == ScrollOrientation.Vertical ? m_minColumnSpacing : m_minRowSpacing;
private double LineSpacing => OrientationBasedMeasures.ScrollOrientation == ScrollOrientation.Vertical ? m_minRowSpacing : m_minColumnSpacing;

private double MinItemSpacing => new ScrollOrientation() == ScrollOrientation.Vertical ? m_minRowSpacing : m_minColumnSpacing;
private double MinItemSpacing => OrientationBasedMeasures.ScrollOrientation == ScrollOrientation.Vertical ? m_minColumnSpacing : m_minRowSpacing;

// Fields
private double m_minRowSpacing;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Collections.Generic;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Collections.Generic;
using System.Windows;

namespace ModernWpf.Controls
Expand Down
29 changes: 18 additions & 11 deletions test/ModernWpfTestApp/ApiTests/RepeaterTests/FlowLayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1608,22 +1608,29 @@ private void ValidateLayoutEstimations(ScrollOrientation scrollOrientation, Layo
break;
case LayoutChoice.Grid:
var minRowSpacing = om.ScrollOrientation == ScrollOrientation.Vertical ? lineSpacing : 0;
var minColumnSpacing = om.ScrollOrientation == ScrollOrientation.Horizontal ? lineSpacing : 0;
layout = new UniformGridLayout() { MinItemWidth = itemSize, MinItemHeight = itemSize, MinRowSpacing = minRowSpacing, MinColumnSpacing = minColumnSpacing };
{
var minRowSpacing = om.ScrollOrientation == ScrollOrientation.Vertical ? lineSpacing : 0;
var minColumnSpacing = om.ScrollOrientation == ScrollOrientation.Horizontal ? lineSpacing : 0;
layout = new UniformGridLayout() { MinItemWidth = itemSize, MinItemHeight = itemSize, MinRowSpacing = minRowSpacing, MinColumnSpacing = minColumnSpacing };
}
break;
case LayoutChoice.Flow:
layout = new FlowLayoutDerived()
{
MinColumnSpacing = lineSpacing,
OnLineArrangedFunc = (int startIndex, int countInLine, double lineSize, VirtualizingLayoutContext context) =>
var minRowSpacing = om.ScrollOrientation == ScrollOrientation.Vertical ? lineSpacing : 0;
var minColumnSpacing = om.ScrollOrientation == ScrollOrientation.Horizontal ? lineSpacing : 0;
layout = new FlowLayoutDerived()
{
Verify.AreEqual(0, startIndex % 4);
Verify.AreEqual(4, countInLine);
Verify.AreEqual(lineSize, itemSize);
}
};
MinRowSpacing = minRowSpacing,
MinColumnSpacing = minColumnSpacing,
OnLineArrangedFunc = (int startIndex, int countInLine, double lineSize, VirtualizingLayoutContext context) =>
{
Verify.AreEqual(0, startIndex % 4);
Verify.AreEqual(4, countInLine);
Verify.AreEqual(lineSize, itemSize);
}
};
}
break;
default:
Expand Down

0 comments on commit 8f0f49e

Please sign in to comment.