Skip to content

Commit 687137d

Browse files
committed
Factor out common string format.
1 parent 1b79903 commit 687137d

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed

Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -466,27 +466,24 @@ private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth
466466
expressionX.SetReferenceParameter(pParam, propertySetModulo);
467467
expressionY.SetReferenceParameter(pParam, propertySetModulo);
468468

469+
string Thing(string common, string diemtion)
470+
=> string.Format(
471+
"{0} == 0 " +
472+
"? 0 " +
473+
": {0} < 0 " +
474+
"? -(Abs({0} - (Ceil({0} / {1}) * {1})) % {1}) " +
475+
": -({1} - ({0} % {1}))",
476+
common,
477+
diemtion);
478+
469479
string expressionXVal;
470480
string expressionYVal;
471481
if (scrollViewer == null)
472482
{
473-
var xCommon = "Ceil(" + offsetXParam + ")";
474-
var yCommon = "Ceil(" + offsetYParam + ")";
475-
476483
// expressions are created to simulate a positive and negative modulo with the size of the image and the offset
477-
expressionXVal =
478-
$"{xCommon} == 0 " +
479-
$"? 0 " +
480-
$": {xCommon} < 0 " +
481-
$"? -(Abs({xCommon} - (Ceil({xCommon} / {imageWidthParam}) * {imageWidthParam})) % {imageWidthParam}) " +
482-
$": -({imageWidthParam} - ({xCommon} % {imageWidthParam}))";
483-
484-
expressionYVal =
485-
$"{yCommon} == 0 " +
486-
$"? 0 " +
487-
$": {yCommon} < 0 " +
488-
$"? -(Abs({yCommon} - (Ceil({yCommon} / {imageHeightParam}) * {imageHeightParam})) % {imageHeightParam}) " +
489-
$": -({imageHeightParam} - ({yCommon} % {imageHeightParam}))";
484+
expressionXVal = Thing("Ceil(" + offsetXParam + ")", imageHeightParam);
485+
486+
expressionYVal = Thing("Ceil(" + offsetYParam + ")", imageWidthParam);
490487
}
491488
else
492489
{
@@ -495,21 +492,12 @@ private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth
495492
expressionX.SetReferenceParameter("s", scrollProperties);
496493
expressionY.SetReferenceParameter("s", scrollProperties);
497494

498-
var xCommon = $"Ceil((s.Translation.X * {speedParam}) + {offsetXParam})";
499-
expressionXVal =
500-
$"{xCommon} == 0 " +
501-
"? 0 " +
502-
$": {xCommon} < 0 " +
503-
$"? -(Abs({xCommon} - (Ceil({xCommon} / {imageWidthParam}) * {imageWidthParam})) % {imageWidthParam}) " +
504-
$": -({imageWidthParam} - ({xCommon} % {imageWidthParam}))";
495+
string LocalThing(string scroll, string speed, string offset, string dimention)
496+
=> Thing(string.Format("Ceil(({0} * {1}) + {2})", scroll, speed, offset), dimention);
505497

506-
var yCommon = $"Ceil((s.Translation.Y * {speedParam}) + {offsetYParam})";
507-
expressionYVal =
508-
$"{yCommon} == 0 " +
509-
"? 0 " +
510-
$": {yCommon} < 0 " +
511-
$"? -(Abs({yCommon} - (Ceil({yCommon} / {imageHeightParam}) * {imageHeightParam})) % {imageHeightParam}) " +
512-
$": -({imageHeightParam} - ({yCommon} % {imageHeightParam}))";
498+
expressionXVal = LocalThing("s.Translation.X", speedParam, offsetXParam, imageWidthParam);
499+
500+
expressionYVal = LocalThing("s.Translation.Y", speedParam, offsetYParam, imageHeightParam);
513501
}
514502

515503
if (scrollOrientation == ScrollOrientation.Horizontal || scrollOrientation == ScrollOrientation.Both)

0 commit comments

Comments
 (0)