From f0450db2030f71df423b5c508b98b7332de0a355 Mon Sep 17 00:00:00 2001 From: fufesou <13586388+fufesou@users.noreply.github.com> Date: Tue, 29 Oct 2024 09:49:04 +0800 Subject: [PATCH] refact: mobile reset canvas (#9766) Signed-off-by: fufesou --- flutter/lib/models/model.dart | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index bd91949843b..ecbfd6fa439 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -1659,11 +1659,25 @@ class CanvasModel with ChangeNotifier { notifyListeners(); } - clear([bool notify = false]) { + // For reset canvas to the last view style + reset() { + _scale = _lastViewStyle.scale; + _devicePixelRatio = ui.window.devicePixelRatio; + if (kIgnoreDpi && _lastViewStyle.style == kRemoteViewStyleOriginal) { + _scale = 1.0 / _devicePixelRatio; + } + final displayWidth = getDisplayWidth(); + final displayHeight = getDisplayHeight(); + _x = (size.width - displayWidth * _scale) / 2; + _y = (size.height - displayHeight * _scale) / 2; + bind.sessionSetViewStyle(sessionId: sessionId, value: _lastViewStyle.style); + notifyListeners(); + } + + clear() { _x = 0; _y = 0; _scale = 1.0; - if (notify) notifyListeners(); } updateScrollPercent() { @@ -1988,7 +2002,7 @@ class CursorModel with ChangeNotifier { _x = _displayOriginX; _y = _displayOriginY; parent.target?.inputModel.moveMouse(_x, _y); - parent.target?.canvasModel.clear(true); + parent.target?.canvasModel.reset(); notifyListeners(); }