From 7b884f90883fbb496c528ee8783cf4509be6ac03 Mon Sep 17 00:00:00 2001 From: Serge Matveenko Date: Sat, 16 Jan 2021 01:43:56 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Use=20`Offset`=20type=20directly?= =?UTF-8?q?=20in=20`JoystickAction.update`=20calculations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + lib/components/joystick/joystick_action.dart | 10 +++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd83a53b09d..7eb5d51f9f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # CHANGELOG ## [next] + - Use `Offset` type directly in `JoystickAction.update` calculations - Changed `parseAnchor` in `examples/widgets` to throw an exception instead of returning null when it cannot parse an anchor name - Code improvements and preparing APIs to null-safety - BaseComponent removes children marked as shouldRemove during update diff --git a/lib/components/joystick/joystick_action.dart b/lib/components/joystick/joystick_action.dart index fa449be99ad..8200f05c2f8 100644 --- a/lib/components/joystick/joystick_action.dart +++ b/lib/components/joystick/joystick_action.dart @@ -136,15 +136,11 @@ class JoystickAction { // Calculate the knob position final double nextX = dist * cos(_radAngle); final double nextY = dist * sin(_radAngle); - final Offset nextPoint = Offset(nextX, nextY); + final nextPoint = Offset(nextX, nextY); if (_rectAction != null) { - final Offset diff = Offset( - _rectBackgroundDirection.center.dx + nextPoint.dx, - _rectBackgroundDirection.center.dy + nextPoint.dy, - ) - - _rectAction.center; - + final diff = + _rectBackgroundDirection.center + nextPoint - _rectAction.center; _rectAction = _rectAction.shift(diff); }