Skip to content

Commit 8e383ae

Browse files
committed
Replaced Horizontal/Vertical Spacing with Item/Line spacing
1 parent f02d885 commit 8e383ae

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed

components/WrapPanel2/samples/WrapPanel2BasicSample.xaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
1+
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
22
<Page x:Class="WrapPanel2Experiment.Samples.WrapPanel2BasicSample"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@@ -24,12 +24,12 @@
2424
Margin="16">
2525
<controls:WrapPanel2 HorizontalAlignment="{x:Bind LayoutHorizontalAlignment, Mode=OneWay}"
2626
VerticalAlignment="{x:Bind LayoutVerticalAlignment, Mode=OneWay}"
27+
Orientation="{x:Bind local:WrapPanel2BasicSample.ConvertStringToOrientation(LayoutOrientation), Mode=OneWay}"
28+
ItemSpacing="{x:Bind ItemSpacing, Mode=OneWay}"
29+
LineSpacing="{x:Bind LineSpacing, Mode=OneWay}"
2730
FixedRowLengths="{x:Bind FixedRowLengths, Mode=OneWay}"
2831
ForcedStretchMethod="{x:Bind local:WrapPanel2BasicSample.ConvertStringToForcedStretchMethod(LayoutForcedStretchMethod), Mode=OneWay}"
29-
HorizontalSpacing="{x:Bind HorizontalSpacing, Mode=OneWay}"
30-
Orientation="{x:Bind local:WrapPanel2BasicSample.ConvertStringToOrientation(LayoutOrientation), Mode=OneWay}"
31-
OverflowBehavior="{x:Bind local:WrapPanel2BasicSample.ConvertStringToOverflowBehavior(LayoutOverflowBehavior), Mode=OneWay}"
32-
VerticalSpacing="{x:Bind VerticalSpacing, Mode=OneWay}">
32+
OverflowBehavior="{x:Bind local:WrapPanel2BasicSample.ConvertStringToOverflowBehavior(LayoutOverflowBehavior), Mode=OneWay}">
3333
<Border controls:WrapPanel2.LayoutLength="2*">
3434
<TextBlock HorizontalAlignment="Center"
3535
Text="2*" />

components/WrapPanel2/samples/WrapPanel2BasicSample.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ namespace WrapPanel2Experiment.Samples;
1212
[ToolkitSampleMultiChoiceOption("LayoutOrientation", "Horizontal", "Vertical", Title = "Orientation")]
1313
[ToolkitSampleMultiChoiceOption("LayoutHorizontalAlignment", "Left", "Center", "Right", "Stretch", Title = "Horizontal Alignment")]
1414
[ToolkitSampleMultiChoiceOption("LayoutVerticalAlignment", "Top", "Center", "Bottom", "Stretch", Title = "Vertical Alignment")]
15-
[ToolkitSampleNumericOption("HorizontalSpacing", 8, 0, 16, Title = "Horizontal Spacing")]
16-
[ToolkitSampleNumericOption("VerticalSpacing", 2, 0, 16, Title = "Vertical Spacing")]
15+
[ToolkitSampleNumericOption("ItemSpacing", 8, 0, 16, Title = "Item Spacing")]
16+
[ToolkitSampleNumericOption("LineSpacing", 2, 0, 16, Title = "Line Spacing")]
1717
[ToolkitSampleBoolOption("FixedRowLengths", false, Title = "Fixed Row Lengths")]
1818
[ToolkitSampleMultiChoiceOption("LayoutForcedStretchMethod", "None", "First", "Last", "Equal", "Proportional", Title = "Forced Stretch Method")]
1919
[ToolkitSampleMultiChoiceOption("LayoutOverflowBehavior", "Wrap", "Drop", Title = "Overflow Behavior")]

components/WrapPanel2/src/WrapPanel2.Properties.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ public partial class WrapPanel2
2626
new PropertyMetadata(default(Orientation), OnPropertyChanged));
2727

2828
/// <summary>
29-
/// Backing <see cref="DependencyProperty"/> for the <see cref="HorizontalSpacing"/> property.
29+
/// Backing <see cref="DependencyProperty"/> for the <see cref="ItemSpacing"/> property.
3030
/// </summary>
31-
public static readonly DependencyProperty HorizontalSpacingProperty = DependencyProperty.Register(
32-
nameof(HorizontalSpacing),
31+
public static readonly DependencyProperty ItemSpacingProperty = DependencyProperty.Register(
32+
nameof(ItemSpacing),
3333
typeof(double),
3434
typeof(WrapPanel2),
3535
new PropertyMetadata(default(double), OnPropertyChanged));
3636

3737
/// <summary>
38-
/// Backing <see cref="DependencyProperty"/> for the <see cref="VerticalSpacing"/> property.
38+
/// Backing <see cref="DependencyProperty"/> for the <see cref="LineSpacing"/> property.
3939
/// </summary>
40-
public static readonly DependencyProperty VerticalSpacingProperty = DependencyProperty.Register(
41-
nameof(VerticalSpacing),
40+
public static readonly DependencyProperty lineSpacingProperty = DependencyProperty.Register(
41+
nameof(LineSpacing),
4242
typeof(double),
4343
typeof(WrapPanel2),
4444
new PropertyMetadata(default(double), OnPropertyChanged));
@@ -80,21 +80,21 @@ public Orientation Orientation
8080
}
8181

8282
/// <summary>
83-
/// Gets or sets the horizontal spacing between items.
83+
/// Gets or sets the spacing between items.
8484
/// </summary>
85-
public double HorizontalSpacing
85+
public double ItemSpacing
8686
{
87-
get => (double)GetValue(HorizontalSpacingProperty);
88-
set => SetValue(HorizontalSpacingProperty, value);
87+
get => (double)GetValue(ItemSpacingProperty);
88+
set => SetValue(ItemSpacingProperty, value);
8989
}
9090

9191
/// <summary>
9292
/// Gets or sets the vertical spacing between items.
9393
/// </summary>
94-
public double VerticalSpacing
94+
public double LineSpacing
9595
{
96-
get => (double)GetValue(VerticalSpacingProperty);
97-
set => SetValue(VerticalSpacingProperty, value);
96+
get => (double)GetValue(lineSpacingProperty);
97+
set => SetValue(lineSpacingProperty, value);
9898
}
9999

100100
/// <summary>

components/WrapPanel2/src/WrapPanel2.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ protected override Size MeasureOverride(Size availableSize)
2020

2121
// Define XY/UV coordinate variables
2222
var uvAvailableSize = new UVCoord(availableSize.Width, availableSize.Height, Orientation);
23-
var uvSpacing = new UVCoord(HorizontalSpacing, VerticalSpacing, Orientation);
2423

2524
RowSpec currentRowSpec = default;
2625

@@ -41,7 +40,7 @@ protected override Size MeasureOverride(Size availableSize)
4140

4241
// Attempt to add the child to the current row/column
4342
var spec = new RowSpec(layoutLength, uvDesiredSize);
44-
if (!currentRowSpec.TryAdd(spec, uvSpacing.U, uvAvailableSize.U))
43+
if (!currentRowSpec.TryAdd(spec, ItemSpacing, uvAvailableSize.U))
4544
{
4645
// If the overflow behavior is drop, just end the row here.
4746
if (OverflowBehavior is OverflowBehavior.Drop)
@@ -50,20 +49,20 @@ protected override Size MeasureOverride(Size availableSize)
5049
// Could not add to current row/column
5150
// Start a new row/column
5251
_rowSpecs.Add(currentRowSpec);
53-
_longestRowSize = Math.Max(_longestRowSize, currentRowSpec.Measure(uvSpacing.U));
52+
_longestRowSize = Math.Max(_longestRowSize, currentRowSpec.Measure(ItemSpacing));
5453
currentRowSpec = spec;
5554
}
5655
}
5756

5857
// Add the final row/column
5958
_rowSpecs.Add(currentRowSpec);
60-
_longestRowSize = Math.Max(_longestRowSize, currentRowSpec.Measure(uvSpacing.U));
59+
_longestRowSize = Math.Max(_longestRowSize, currentRowSpec.Measure(ItemSpacing));
6160

6261
// Calculate final desired size
6362
var uvSize = new UVCoord(0, 0, Orientation)
6463
{
6564
U = IsMainAxisStretch(uvAvailableSize.U) ? uvAvailableSize.U : _longestRowSize,
66-
V = _rowSpecs.Sum(static rs => rs.MaxOffAxisSize) + (uvSpacing.V * (_rowSpecs.Count - 1))
65+
V = _rowSpecs.Sum(static rs => rs.MaxOffAxisSize) + (LineSpacing * (_rowSpecs.Count - 1))
6766
};
6867

6968
// Clamp to available size and return
@@ -82,18 +81,17 @@ protected override Size ArrangeOverride(Size finalSize)
8281
// Create XY/UV coordinate variables
8382
var pos = new UVCoord(0, 0, Orientation);
8483
var uvFinalSize = new UVCoord(finalSize, Orientation);
85-
var uvSpacing = new UVCoord(HorizontalSpacing, VerticalSpacing, Orientation);
8684

8785
// Adjust the starting position based on off-axis alignment
88-
var contentHeight = _rowSpecs.Sum(static rs => rs.MaxOffAxisSize) + (uvSpacing.V * (_rowSpecs.Count - 1));
86+
var contentHeight = _rowSpecs.Sum(static rs => rs.MaxOffAxisSize) + (LineSpacing * (_rowSpecs.Count - 1));
8987
pos.V = GetStartByAlignment(GetOffAlignment(), contentHeight, uvFinalSize.V);
9088

9189
var childQueue = new Queue<UIElement>(Children.Where(static e => e.Visibility is Visibility.Visible));
9290

9391
foreach (var row in _rowSpecs)
9492
{
9593
// Arrange the row/column
96-
ArrangeRow(ref pos, row, uvFinalSize, uvSpacing, childQueue);
94+
ArrangeRow(ref pos, row, uvFinalSize, childQueue);
9795
}
9896

9997
// "Arrange" remaning children by rendering them with zero size
@@ -106,9 +104,9 @@ protected override Size ArrangeOverride(Size finalSize)
106104
return finalSize;
107105
}
108106

109-
private void ArrangeRow(ref UVCoord pos, RowSpec row, UVCoord uvFinalSize, UVCoord uvSpacing, Queue<UIElement> childQueue)
107+
private void ArrangeRow(ref UVCoord pos, RowSpec row, UVCoord uvFinalSize, Queue<UIElement> childQueue)
110108
{
111-
var spacingTotalSize = uvSpacing.U * (row.ItemsCount - 1);
109+
var spacingTotalSize = ItemSpacing * (row.ItemsCount - 1);
112110
var remainingSpace = uvFinalSize.U - row.ReservedSpace - spacingTotalSize;
113111
var portionSize = row.MinPortionSize;
114112

@@ -130,7 +128,7 @@ private void ArrangeRow(ref UVCoord pos, RowSpec row, UVCoord uvFinalSize, UVCoo
130128
// Also do this if there are no star-sized items in the row/column and no forced streching is in use.
131129
if (!stretch || (row.PortionsSum is 0 && ForcedStretchMethod is ForcedStretchMethod.None))
132130
{
133-
var rowSize = row.Measure(uvSpacing.U);
131+
var rowSize = row.Measure(ItemSpacing);
134132
pos.U = GetStartByAlignment(GetAlignment(), rowSize, uvFinalSize.U);
135133
}
136134

@@ -184,11 +182,11 @@ private void ArrangeRow(ref UVCoord pos, RowSpec row, UVCoord uvFinalSize, UVCoo
184182
child.Arrange(new Rect(pos.X, pos.Y, size.X, size.Y));
185183

186184
// Advance the position
187-
pos.U += size.U + uvSpacing.U;
185+
pos.U += size.U + ItemSpacing;
188186
}
189187

190188
// Advance to the next row/column
191-
pos.V += row.MaxOffAxisSize + uvSpacing.V;
189+
pos.V += row.MaxOffAxisSize + LineSpacing;
192190
}
193191

194192
private UVCoord GetChildSize(UIElement child, int indexInRow, RowSpec row, double portionSize, bool forceStretch)

0 commit comments

Comments
 (0)