Skip to content

Commit 16d2897

Browse files
committed
Exracted UpdateSelectionThumbs and UpdateMaskArea out of TryUpdateImageLayout
1 parent 56fd8d1 commit 16d2897

File tree

4 files changed

+51
-17
lines changed

4 files changed

+51
-17
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Events.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ private void ImageCropperThumb_KeyUp(object sender, KeyRoutedEventArgs e)
106106
_currentCroppedRect = croppedRect;
107107
}
108108

109-
UpdateImageLayout(true);
109+
if (TryUpdateImageLayout(true))
110+
{
111+
UpdateSelectionThumbs(true);
112+
UpdateMaskArea(true);
113+
}
110114
}
111115

112116
private void ImageCropperThumb_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
@@ -119,7 +123,11 @@ private void ImageCropperThumb_ManipulationCompleted(object sender, Manipulation
119123
_currentCroppedRect = croppedRect;
120124
}
121125

122-
UpdateImageLayout(true);
126+
if (TryUpdateImageLayout(true))
127+
{
128+
UpdateSelectionThumbs(true);
129+
UpdateMaskArea(true);
130+
}
123131
}
124132

125133
private void ImageCropperThumb_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
@@ -161,7 +169,12 @@ private void SourceImage_ManipulationDelta(object sender, ManipulationDeltaRoute
161169
var croppedRect = _inverseImageTransform.TransformBounds(selectedRect);
162170
croppedRect.Intersect(_restrictedCropRect);
163171
_currentCroppedRect = croppedRect;
164-
UpdateImageLayout();
172+
173+
if (TryUpdateImageLayout())
174+
{
175+
UpdateSelectionThumbs();
176+
UpdateMaskArea();
177+
}
165178
}
166179

167180
private void ImageCanvas_SizeChanged(object sender, SizeChangedEventArgs e)
@@ -171,12 +184,21 @@ private void ImageCanvas_SizeChanged(object sender, SizeChangedEventArgs e)
171184
return;
172185
}
173186

174-
UpdateImageLayout();
187+
if (TryUpdateImageLayout())
188+
{
189+
UpdateSelectionThumbs();
190+
UpdateMaskArea();
191+
}
192+
175193
UpdateMaskArea();
176194

177195
if (TryUpdateAspectRatio())
178196
{
179-
UpdateImageLayout();
197+
if (TryUpdateImageLayout())
198+
{
199+
UpdateSelectionThumbs();
200+
UpdateMaskArea();
201+
}
180202
}
181203
}
182204
}

Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Logic.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ private void InitImageLayout(bool animate = false)
3030
if (IsValidRect(_restrictedCropRect))
3131
{
3232
_currentCroppedRect = KeepAspectRatio ? GetUniformRect(_restrictedCropRect, ActualAspectRatio) : _restrictedCropRect;
33-
UpdateImageLayout(animate);
33+
34+
if (TryUpdateImageLayout(animate))
35+
{
36+
UpdateSelectionThumbs(animate);
37+
UpdateMaskArea(animate);
38+
}
3439
}
3540
}
3641

@@ -41,19 +46,13 @@ private void InitImageLayout(bool animate = false)
4146
/// Update image source transform.
4247
/// </summary>
4348
/// <param name="animate">Whether animation is enabled.</param>
44-
private bool UpdateImageLayout(bool animate = false)
49+
private bool TryUpdateImageLayout(bool animate = false)
4550
{
4651
if (Source != null && IsValidRect(CanvasRect))
4752
{
4853
var uniformSelectedRect = GetUniformRect(CanvasRect, _currentCroppedRect.Width / _currentCroppedRect.Height);
4954

50-
if (TryUpdateImageLayoutWithViewport(uniformSelectedRect, _currentCroppedRect, animate))
51-
{
52-
UpdateSelectionThumbs(animate);
53-
UpdateMaskArea(animate);
54-
}
55-
56-
return true;
55+
return TryUpdateImageLayoutWithViewport(uniformSelectedRect, _currentCroppedRect, animate);
5756
}
5857

5958
return false;

Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.Properties.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ private static void OnAspectRatioChanged(
5454

5555
if (target.TryUpdateAspectRatio())
5656
{
57-
target.UpdateImageLayout(true);
57+
if (target.TryUpdateImageLayout(true))
58+
{
59+
target.UpdateSelectionThumbs(true);
60+
target.UpdateMaskArea(true);
61+
}
5862
}
5963
}
6064

@@ -67,7 +71,11 @@ private static void OnCropShapeChanged(
6771

6872
if (target.TryUpdateAspectRatio())
6973
{
70-
target.UpdateImageLayout();
74+
if (target.TryUpdateImageLayout())
75+
{
76+
target.UpdateSelectionThumbs();
77+
target.UpdateMaskArea();
78+
}
7179
}
7280

7381
target.UpdateMaskArea();

Microsoft.Toolkit.Uwp.UI.Controls.Media/ImageCropper/ImageCropper.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,12 @@ public bool TrySetCroppedRegion(Rect rect)
455455
}
456456

457457
_currentCroppedRect = rect;
458-
UpdateImageLayout(true);
458+
if (TryUpdateImageLayout(true))
459+
{
460+
UpdateSelectionThumbs(true);
461+
UpdateMaskArea(true);
462+
}
463+
459464
return true;
460465
}
461466
}

0 commit comments

Comments
 (0)