Skip to content

Commit

Permalink
Fixing a spacing issue that is tied to orientation (#632)
Browse files Browse the repository at this point in the history
* flip the spacing

* fixes
  • Loading branch information
ranjeshj authored Apr 30, 2019
1 parent 2981c34 commit 1703a98
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
30 changes: 17 additions & 13 deletions dev/Repeater/APITests/FlowLayoutTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,16 @@ public void ValidateGridLayout()
canvas.Children.Add(panel);
Content = canvas;
Content.UpdateLayout();
int minItemSpacing = 0;
int lineSpacing = 0;
ValidateGridLayoutChildrenLayoutBounds(om, (i) => panel.Children[i], itemMinorSize, itemMajorSize, minItemSpacing, lineSpacing, panel.Children.Count, panel.DesiredSize);

minItemSpacing = 10;
lineSpacing = 10;
((UniformGridLayout)panel.Layout).MinRowSpacing = minItemSpacing;
((UniformGridLayout)panel.Layout).MinColumnSpacing = lineSpacing;
int minRowSpacing = 0;
int minColumnSpacing = 0;
ValidateGridLayoutChildrenLayoutBounds(om, (i) => panel.Children[i], itemMinorSize, itemMajorSize, minRowSpacing, minColumnSpacing, panel.Children.Count, panel.DesiredSize);

minRowSpacing = 5;
minColumnSpacing = 10;
((UniformGridLayout)panel.Layout).MinRowSpacing = minRowSpacing;
((UniformGridLayout)panel.Layout).MinColumnSpacing = minColumnSpacing;
Content.UpdateLayout();
ValidateGridLayoutChildrenLayoutBounds(om, (i) => panel.Children[i], itemMinorSize, itemMajorSize, minItemSpacing, lineSpacing, panel.Children.Count, panel.DesiredSize);
ValidateGridLayoutChildrenLayoutBounds(om, (i) => panel.Children[i], itemMinorSize, itemMajorSize, minRowSpacing, minColumnSpacing, panel.Children.Count, panel.DesiredSize);
}
}
});
Expand Down Expand Up @@ -1245,13 +1245,16 @@ private void ValidateGridLayoutChildrenLayoutBounds(
Func<int, UIElement> elementAtIndexFunc,
double itemMinorSize,
double itemMajorSize,
double minItemSpacing,
double lineSpacing,
double minRowSpacing,
double minColumnSpacing,
int childCount,
Size desiredSize)
{
var expectedRect = om.MinorMajorRect(0, 0, itemMinorSize, itemMajorSize);
double extentMajor = 0;
var minItemSpacing = om.ScrollOrientation == ScrollOrientation.Vertical ? minColumnSpacing : minRowSpacing;
var lineSpacing = om.ScrollOrientation == ScrollOrientation.Vertical ? minRowSpacing : minColumnSpacing;

for (int i = 0; i < childCount; i++)
{
var child = (FrameworkElement)elementAtIndexFunc(i);
Expand Down Expand Up @@ -1384,8 +1387,9 @@ private void ValidateLayoutEstimations(ScrollOrientation scrollOrientation, Layo
break;

case LayoutChoice.Grid:

layout = new UniformGridLayout() { MinItemWidth = itemSize, MinItemHeight = itemSize, MinColumnSpacing = lineSpacing };
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:
Expand Down
5 changes: 3 additions & 2 deletions dev/Repeater/UniformGridLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ class UniformGridLayout :

double LineSpacing()
{
return ScrollOrientation() == ScrollOrientation::Vertical ? m_minColumnSpacing : m_minRowSpacing;
return Orientation() == winrt::Orientation::Horizontal ? m_minRowSpacing: m_minColumnSpacing;

}

double MinItemSpacing()
{
return ScrollOrientation() == ScrollOrientation::Vertical ? m_minRowSpacing : m_minColumnSpacing;
return Orientation() == winrt::Orientation::Horizontal ? m_minColumnSpacing: m_minRowSpacing;
}

// Fields
Expand Down
2 changes: 1 addition & 1 deletion dev/Repeater/UniformGridLayoutState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void UniformGridLayoutState::SetSize(
m_effectiveItemHeight = (std::isnan(LayoutItemHeight) ? UIElement.DesiredSize().Height : LayoutItemHeight);

auto availableSizeMinor = orientation == winrt::Orientation::Horizontal ? availableSize.Width : availableSize.Height;
auto minorItemSpacing = orientation == winrt::Orientation::Horizontal ? minRowSpacing : minColumnSpacing;
auto minorItemSpacing = orientation == winrt::Orientation::Vertical ? minRowSpacing : minColumnSpacing;

auto itemSizeMinor = orientation == winrt::Orientation::Horizontal ? m_effectiveItemWidth : m_effectiveItemHeight;
itemSizeMinor += minorItemSpacing;
Expand Down

0 comments on commit 1703a98

Please sign in to comment.