From adf63f67b5e90d70b734da54f0803f5ea8fe01a8 Mon Sep 17 00:00:00 2001 From: fufesou Date: Wed, 6 May 2026 14:19:43 +0800 Subject: [PATCH] feat(cavas): margin, refact toDouble() Signed-off-by: fufesou --- .../lib/desktop/widgets/remote_toolbar.dart | 6 +++++- flutter/lib/models/input_model.dart | 18 +++++++++++------- flutter/lib/models/model.dart | 10 ++++++---- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/flutter/lib/desktop/widgets/remote_toolbar.dart b/flutter/lib/desktop/widgets/remote_toolbar.dart index f87b64211..6e2e6d77b 100644 --- a/flutter/lib/desktop/widgets/remote_toolbar.dart +++ b/flutter/lib/desktop/widgets/remote_toolbar.dart @@ -1125,7 +1125,11 @@ class _DisplayMenuState extends State<_DisplayMenu> { final scrollVisible = data['scrollVisible'] as bool; final groupValue = data['scrollStyle'] as String; final edgeScrollEdgeThickness = - (data['edgeScrollEdgeThickness'] as int?) ?? 0; + ((data['edgeScrollEdgeThickness'] as int?) ?? + EdgeThicknessControl.kMin.round()) + .clamp(EdgeThicknessControl.kMin.round(), + EdgeThicknessControl.kMax.round()) + .toInt(); final supportsRemoteCanvasMargin = data['supportsRemoteCanvasMargin'] as bool; final remoteCanvasMargin = data['remoteCanvasMargin'] as double; diff --git a/flutter/lib/models/input_model.dart b/flutter/lib/models/input_model.dart index 76031559a..cbbb7afda 100644 --- a/flutter/lib/models/input_model.dart +++ b/flutter/lib/models/input_model.dart @@ -62,18 +62,21 @@ class CanvasCoords { static CanvasCoords fromJson(Map json) { final model = CanvasCoords(); - model.x = json['x']; - model.y = json['y']; - model.scale = json['scale']; - model.scrollX = json['scrollX']; - model.scrollY = json['scrollY']; + model.x = (json['x'] ?? 0).toDouble(); + model.y = (json['y'] ?? 0).toDouble(); + model.scale = (json['scale'] ?? 1).toDouble(); + model.scrollX = (json['scrollX'] ?? 0).toDouble(); + model.scrollY = (json['scrollY'] ?? 0).toDouble(); model.displayWidth = (json['displayWidth'] ?? 0).toDouble(); model.displayHeight = (json['displayHeight'] ?? 0).toDouble(); model.paddingX = (json['paddingX'] ?? 0).toDouble(); model.paddingY = (json['paddingY'] ?? 0).toDouble(); model.scrollStyle = ScrollStyle.fromJson(json['scrollStyle'], ScrollStyle.scrollauto); - model.size = Size(json['size']['w'], json['size']['h']); + model.size = Size( + (json['size']['w'] ?? 0).toDouble(), + (json['size']['h'] ?? 0).toDouble(), + ); return model; } @@ -1461,7 +1464,8 @@ class InputModel { if (e is PointerScrollEvent) { final rawDx = e.scrollDelta.dx; final rawDy = e.scrollDelta.dy; - final dominantDelta = rawDx.abs() > rawDy.abs() ? rawDx.abs() : rawDy.abs(); + final dominantDelta = + rawDx.abs() > rawDy.abs() ? rawDx.abs() : rawDy.abs(); final isSmooth = dominantDelta < 1; final nowUs = DateTime.now().microsecondsSinceEpoch; final dtUs = _lastWheelTsUs == 0 ? 0 : nowUs - _lastWheelTsUs; diff --git a/flutter/lib/models/model.dart b/flutter/lib/models/model.dart index 9af4903b4..afc1bdab0 100644 --- a/flutter/lib/models/model.dart +++ b/flutter/lib/models/model.dart @@ -2226,14 +2226,16 @@ class CanvasModel with ChangeNotifier { } final sessionValue = await bind.sessionGetFlutterOption( sessionId: sessionId, k: kOptionRemoteCanvasMargin); + if (_remoteCanvasMarginInitialized || !supportsRemoteCanvasMargin) { + return; + } final defaultValue = bind.mainGetUserDefaultOption(key: kOptionRemoteCanvasMargin); final value = sessionValue?.isNotEmpty == true ? sessionValue : defaultValue; - _remoteCanvasMargin = - (double.tryParse(value ?? '') ?? 0) - .clamp(0, kMaxRemoteCanvasMargin) - .toDouble(); + _remoteCanvasMargin = (double.tryParse(value ?? '') ?? 0) + .clamp(0, kMaxRemoteCanvasMargin) + .toDouble(); _remoteCanvasMarginInitialized = true; }