|
4 | 4 |
|
5 | 5 | using System; |
6 | 6 | using System.Collections.Generic; |
| 7 | +using System.Runtime.InteropServices.WindowsRuntime; |
7 | 8 | using Windows.Foundation; |
8 | 9 | using Windows.UI.Xaml; |
9 | 10 | using Windows.UI.Xaml.Controls; |
@@ -87,34 +88,28 @@ public UvRect WithVerticalAlignment(VerticalAlignment alignment, double maxHeigh |
87 | 88 |
|
88 | 89 | public UvRect WithHorizontalAlignment(HorizontalAlignment alignment, double maxHeight) |
89 | 90 | { |
| 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; |
90 | 95 | switch (alignment) |
91 | 96 | { |
92 | 97 | 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; |
100 | 100 | 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; |
108 | 103 | 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; |
114 | 106 | case HorizontalAlignment.Left: |
115 | 107 | default: |
116 | | - return this; |
| 108 | + verticalAlignment = VerticalAlignment.Top; |
| 109 | + break; |
117 | 110 | } |
| 111 | + |
| 112 | + return WithVerticalAlignment(verticalAlignment, maxHeight); |
118 | 113 | } |
119 | 114 |
|
120 | 115 | public Rect ToRect(Orientation orientation) |
|
0 commit comments