Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit c412815

Browse files
committed
code style
1 parent 679cf58 commit c412815

File tree

4 files changed

+101
-81
lines changed

4 files changed

+101
-81
lines changed

Runtime/gestures/constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static class Constants {
99
public const float kDoubleTapSlop = 100.0f;
1010

1111
public const float kPanSlop = kTouchSlop * 2.0f;
12-
12+
1313
public const float kScaleSlop = kTouchSlop;
1414

1515
public static readonly TimeSpan kPressTimeout = new TimeSpan(0, 0, 0, 0, 100);

Runtime/gestures/scale.cs

Lines changed: 71 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using UnityEngine;
55

66
namespace Unity.UIWidgets.gestures {
7-
87
enum _ScaleState {
98
ready,
109
possible,
@@ -16,7 +15,7 @@ public class ScaleStartDetails {
1615
public ScaleStartDetails(Offset focalPoint = null) {
1716
this.focalPoint = focalPoint ?? Offset.zero;
1817
}
19-
18+
2019
public readonly Offset focalPoint;
2120

2221
public override string ToString() {
@@ -34,7 +33,7 @@ public ScaleUpdateDetails(
3433
float rotation = 0.0f
3534
) {
3635
focalPoint = focalPoint ?? Offset.zero;
37-
36+
3837
D.assert(scale >= 0.0f);
3938
D.assert(horizontalScale >= 0.0f);
4039
D.assert(verticalScale >= 0.0f);
@@ -45,7 +44,7 @@ public ScaleUpdateDetails(
4544
this.verticalScale = verticalScale;
4645
this.rotation = rotation;
4746
}
48-
47+
4948
public readonly Offset focalPoint;
5049

5150
public readonly float scale;
@@ -57,15 +56,16 @@ public ScaleUpdateDetails(
5756
public readonly float rotation;
5857

5958
public override string ToString() {
60-
return $"ScaleUpdateDetails(focalPoint: {this.focalPoint}, scale: {this.scale}, horizontalScale: {this.horizontalScale}, verticalScale: {this.verticalScale}, rotation: {this.rotation}";
59+
return
60+
$"ScaleUpdateDetails(focalPoint: {this.focalPoint}, scale: {this.scale}, horizontalScale: {this.horizontalScale}, verticalScale: {this.verticalScale}, rotation: {this.rotation}";
6161
}
6262
}
6363

6464
public class ScaleEndDetails {
6565
public ScaleEndDetails(Velocity velocity = null) {
6666
this.velocity = velocity ?? Velocity.zero;
6767
}
68-
68+
6969
public readonly Velocity velocity;
7070

7171
public override string ToString() {
@@ -95,15 +95,15 @@ public _LineBetweenPointers(
9595
int pointerEndId = 1) {
9696
pointerStartLocation = pointerEndLocation ?? Offset.zero;
9797
pointerEndLocation = pointerEndLocation ?? Offset.zero;
98-
98+
9999
D.assert(pointerStartId != pointerEndId);
100100

101101
this.pointerStartLocation = pointerStartLocation;
102102
this.pointerStartId = pointerStartId;
103103
this.pointerEndLocation = pointerEndLocation;
104104
this.pointerEndId = pointerEndId;
105105
}
106-
106+
107107
public readonly Offset pointerStartLocation;
108108

109109
public readonly int pointerStartId;
@@ -116,17 +116,16 @@ public _LineBetweenPointers(
116116

117117
class ScaleGestureRecognizer : OneSequenceGestureRecognizer {
118118
public ScaleGestureRecognizer(object debugOwner) : base(debugOwner: debugOwner) {
119-
120119
}
121-
120+
122121
public GestureScaleStartCallback onStart;
123-
122+
124123
public GestureScaleUpdateCallback onUpdate;
125124

126125
public GestureScaleEndCallback onEnd;
127126

128127
_ScaleState _state = _ScaleState.ready;
129-
128+
130129
Offset _initialFocalPoint;
131130
Offset _currentFocalPoint;
132131
float _initialSpan;
@@ -146,17 +145,24 @@ float _scaleFactor {
146145
}
147146

148147
float _horizontalScaleFactor {
149-
get { return this._initialHorizontalSpan > 0.0f ? this._currentHorizontalSpan / this._initialHorizontalSpan : 1.0f; }
148+
get {
149+
return this._initialHorizontalSpan > 0.0f
150+
? this._currentHorizontalSpan / this._initialHorizontalSpan
151+
: 1.0f;
152+
}
150153
}
151154

152155
float _verticalScaleFactor {
153-
get { return this._initialVerticalSpan > 0.0f ? this._currentVerticalSpan / this._initialVerticalSpan : 1.0f; }
156+
get {
157+
return this._initialVerticalSpan > 0.0f ? this._currentVerticalSpan / this._initialVerticalSpan : 1.0f;
158+
}
154159
}
155-
160+
156161
float _computeRotationFactor() {
157162
if (this._initialLine == null || this._currentLine == null) {
158163
return 0.0f;
159164
}
165+
160166
float fx = this._initialLine.pointerStartLocation.dx;
161167
float fy = this._initialLine.pointerStartLocation.dy;
162168
float sx = this._initialLine.pointerEndLocation.dx;
@@ -172,7 +178,7 @@ float _computeRotationFactor() {
172178

173179
return angle2 - angle1;
174180
}
175-
181+
176182
public override void addAllowedPointer(PointerDownEvent evt) {
177183
this.startTrackingPointer(evt.pointer);
178184
this._velocityTrackers[evt.pointer] = new VelocityTracker();
@@ -188,12 +194,12 @@ public override void addAllowedPointer(PointerDownEvent evt) {
188194
this._pointerQueue = new List<int>();
189195
}
190196
}
191-
197+
192198
protected override void handleEvent(PointerEvent evt) {
193199
D.assert(this._state != _ScaleState.ready);
194200
bool didChangeConfiguration = false;
195201
bool shouldStartIfAccepted = false;
196-
202+
197203
if (evt is PointerMoveEvent) {
198204
VelocityTracker tracker = this._velocityTrackers[evt.pointer];
199205
D.assert(tracker != null);
@@ -203,12 +209,14 @@ protected override void handleEvent(PointerEvent evt) {
203209

204210
this._pointerLocations[evt.pointer] = evt.position;
205211
shouldStartIfAccepted = true;
206-
} else if (evt is PointerDownEvent) {
212+
}
213+
else if (evt is PointerDownEvent) {
207214
this._pointerLocations[evt.pointer] = evt.position;
208215
this._pointerQueue.Add(evt.pointer);
209216
didChangeConfiguration = true;
210217
shouldStartIfAccepted = true;
211-
} else if (evt is PointerUpEvent || evt is PointerCancelEvent) {
218+
}
219+
else if (evt is PointerUpEvent || evt is PointerCancelEvent) {
212220
this._pointerLocations.Remove(evt.pointer);
213221
this._pointerQueue.Remove(evt.pointer);
214222
didChangeConfiguration = true;
@@ -223,7 +231,7 @@ protected override void handleEvent(PointerEvent evt) {
223231

224232
this.stopTrackingIfPointerNoLongerDown(evt);
225233
}
226-
234+
227235
void _update() {
228236
int count = this._pointerLocations.Keys.Count;
229237

@@ -237,33 +245,36 @@ void _update() {
237245
float totalDeviation = 0.0f;
238246
float totalHorizontalDeviation = 0.0f;
239247
float totalVerticalDeviation = 0.0f;
240-
248+
241249
foreach (int pointer in this._pointerLocations.Keys) {
242250
totalDeviation += (this._currentFocalPoint - this._pointerLocations[pointer]).distance;
243251
totalHorizontalDeviation += (this._currentFocalPoint.dx - this._pointerLocations[pointer].dx).abs();
244252
totalVerticalDeviation += (this._currentFocalPoint.dy - this._pointerLocations[pointer].dy).abs();
245253
}
254+
246255
this._currentSpan = count > 0 ? totalDeviation / count : 0.0f;
247256
this._currentHorizontalSpan = count > 0 ? totalHorizontalDeviation / count : 0.0f;
248257
this._currentVerticalSpan = count > 0 ? totalVerticalDeviation / count : 0.0f;
249258
}
250-
259+
251260
void _updateLines() {
252261
int count = this._pointerLocations.Keys.Count;
253262
D.assert(this._pointerQueue.Count >= count);
254-
263+
255264
if (count < 2) {
256265
this._initialLine = this._currentLine;
257-
} else if (this._initialLine != null &&
258-
this._initialLine.pointerStartId == this._pointerQueue[0] &&
259-
this._initialLine.pointerEndId == this._pointerQueue[1]) {
266+
}
267+
else if (this._initialLine != null &&
268+
this._initialLine.pointerStartId == this._pointerQueue[0] &&
269+
this._initialLine.pointerEndId == this._pointerQueue[1]) {
260270
this._currentLine = new _LineBetweenPointers(
261271
pointerStartId: this._pointerQueue[0],
262272
pointerStartLocation: this._pointerLocations[this._pointerQueue[0]],
263273
pointerEndId: this._pointerQueue[1],
264274
pointerEndLocation: this._pointerLocations[this._pointerQueue[1]]
265275
);
266-
} else {
276+
}
277+
else {
267278
this._initialLine = new _LineBetweenPointers(
268279
pointerStartId: this._pointerQueue[0],
269280
pointerStartLocation: this._pointerLocations[this._pointerQueue[0]],
@@ -273,7 +284,7 @@ void _updateLines() {
273284
this._currentLine = null;
274285
}
275286
}
276-
287+
277288
bool _reconfigure(int pointer) {
278289
this._initialFocalPoint = this._currentFocalPoint;
279290
this._initialSpan = this._currentSpan;
@@ -288,25 +299,33 @@ bool _reconfigure(int pointer) {
288299
Velocity velocity = tracker.getVelocity();
289300
if (_ScaleGestureUtils._isFlingGesture(velocity)) {
290301
Offset pixelsPerSecond = velocity.pixelsPerSecond;
291-
if (pixelsPerSecond.distanceSquared > Constants.kMaxFlingVelocity * Constants.kMaxFlingVelocity)
292-
velocity = new Velocity(pixelsPerSecond: (pixelsPerSecond / pixelsPerSecond.distance) * Constants.kMaxFlingVelocity);
302+
if (pixelsPerSecond.distanceSquared >
303+
Constants.kMaxFlingVelocity * Constants.kMaxFlingVelocity) {
304+
velocity = new Velocity(
305+
pixelsPerSecond: (pixelsPerSecond / pixelsPerSecond.distance) *
306+
Constants.kMaxFlingVelocity);
307+
}
308+
293309
this.invokeCallback<object>("onEnd", () => {
294310
this.onEnd(new ScaleEndDetails(velocity: velocity));
295311
return null;
296312
});
297-
} else {
313+
}
314+
else {
298315
this.invokeCallback<object>("onEnd", () => {
299316
this.onEnd(new ScaleEndDetails(velocity: Velocity.zero));
300317
return null;
301318
});
302319
}
303320
}
321+
304322
this._state = _ScaleState.accepted;
305323
return false;
306324
}
325+
307326
return true;
308327
}
309-
328+
310329
void _advanceStateMachine(bool shouldStartIfAccepted) {
311330
if (this._state == _ScaleState.ready) {
312331
this._state = _ScaleState.possible;
@@ -318,7 +337,8 @@ void _advanceStateMachine(bool shouldStartIfAccepted) {
318337
if (spanDelta > Constants.kScaleSlop || focalPointDelta > Constants.kPanSlop) {
319338
this.resolve(GestureDisposition.accepted);
320339
}
321-
} else if (this._state >= _ScaleState.accepted) {
340+
}
341+
else if (this._state >= _ScaleState.accepted) {
322342
this.resolve(GestureDisposition.accepted);
323343
}
324344

@@ -327,39 +347,41 @@ void _advanceStateMachine(bool shouldStartIfAccepted) {
327347
this._dispatchOnStartCallbackIfNeeded();
328348
}
329349

330-
if (this._state == _ScaleState.started && this.onUpdate != null)
350+
if (this._state == _ScaleState.started && this.onUpdate != null) {
331351
this.invokeCallback<object>("onUpdate", () => {
332-
this.onUpdate(new ScaleUpdateDetails(
333-
scale: this._scaleFactor,
334-
horizontalScale: this._horizontalScaleFactor,
335-
verticalScale: this._verticalScaleFactor,
336-
focalPoint: this._currentFocalPoint,
337-
rotation: this._computeRotationFactor()
338-
));
352+
this.onUpdate(new ScaleUpdateDetails(
353+
scale: this._scaleFactor,
354+
horizontalScale: this._horizontalScaleFactor,
355+
verticalScale: this._verticalScaleFactor,
356+
focalPoint: this._currentFocalPoint,
357+
rotation: this._computeRotationFactor()
358+
));
339359
return null;
340360
});
361+
}
341362
}
342-
363+
343364
void _dispatchOnStartCallbackIfNeeded() {
344365
D.assert(this._state == _ScaleState.started);
345-
if (this.onStart != null)
366+
if (this.onStart != null) {
346367
this.invokeCallback<object>("onStart", () => {
347368
this.onStart(new ScaleStartDetails(focalPoint: this._currentFocalPoint));
348369
return null;
349370
});
371+
}
350372
}
351-
373+
352374
public override void acceptGesture(int pointer) {
353375
if (this._state == _ScaleState.possible) {
354376
this._state = _ScaleState.started;
355377
this._dispatchOnStartCallbackIfNeeded();
356378
}
357379
}
358-
380+
359381
public override void rejectGesture(int pointer) {
360382
this.stopTrackingPointer(pointer);
361383
}
362-
384+
363385
protected override void didStopTrackingLastPointer(int pointer) {
364386
switch (this._state) {
365387
case _ScaleState.possible:
@@ -374,10 +396,10 @@ protected override void didStopTrackingLastPointer(int pointer) {
374396
D.assert(false);
375397
break;
376398
}
377-
399+
378400
this._state = _ScaleState.ready;
379401
}
380-
402+
381403
public override void dispose() {
382404
this._velocityTrackers.Clear();
383405
base.dispose();

0 commit comments

Comments
 (0)