Skip to content

Commit dd49756

Browse files
committed
removed duplicated code
1 parent ff80d0f commit dd49756

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

Microsoft.Toolkit.Uwp.UI.Controls/WrapPanel/WrapPanel.Data.cs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using System.Runtime.InteropServices.WindowsRuntime;
78
using Windows.Foundation;
89
using Windows.UI.Xaml;
910
using Windows.UI.Xaml.Controls;
@@ -87,34 +88,28 @@ public UvRect WithVerticalAlignment(VerticalAlignment alignment, double maxHeigh
8788

8889
public UvRect WithHorizontalAlignment(HorizontalAlignment alignment, double maxHeight)
8990
{
91+
// Since (U,V) coordinates are flipped, we can use the exact same logic as for the vertical alignment
92+
// We just convert the HorizontalAlignment values to VerticalAlignment values (more or less a no-op
93+
// since the integer values are the same).
94+
VerticalAlignment verticalAlignment;
9095
switch (alignment)
9196
{
9297
case HorizontalAlignment.Center:
93-
return new UvRect
94-
{
95-
Position = Position.Add(
96-
u: 0,
97-
v: Math.Max((maxHeight - Size.V) / 2.0, 0.0)),
98-
Size = Size,
99-
};
98+
verticalAlignment = VerticalAlignment.Center;
99+
break;
100100
case HorizontalAlignment.Right:
101-
return new UvRect
102-
{
103-
Position = Position.Add(
104-
u: 0,
105-
v: Math.Max(maxHeight - Size.V, 0.0)),
106-
Size = Size,
107-
};
101+
verticalAlignment = VerticalAlignment.Bottom;
102+
break;
108103
case HorizontalAlignment.Stretch:
109-
return new UvRect
110-
{
111-
Position = Position,
112-
Size = new UvMeasure { U = Size.U, V = maxHeight },
113-
};
104+
verticalAlignment = VerticalAlignment.Stretch;
105+
break;
114106
case HorizontalAlignment.Left:
115107
default:
116-
return this;
108+
verticalAlignment = VerticalAlignment.Top;
109+
break;
117110
}
111+
112+
return WithVerticalAlignment(verticalAlignment, maxHeight);
118113
}
119114

120115
public Rect ToRect(Orientation orientation)

0 commit comments

Comments
 (0)