Browse Source

update(annotation): 修正卡尺大小同步 #0009369 Review by melon

gavin.chen 2 years ago
parent
commit
29d9078188

+ 10 - 0
lib/view/gesture/mouse_gesture.dart

@@ -171,6 +171,16 @@ class _MeasureMouseGesturePanelState extends State<MeasureMouseGesturePanel> {
 
   void _onResize(_, e) {
     _findMultiRegions();
+
+    /// 延迟进行同步,避免窗口手动缩放时引发 Error: Build scheduled during frame.
+    Future.delayed(const Duration(milliseconds: 1000), () {
+      _setScaleRatio();
+    });
+  }
+
+  /// 同步缩放比
+  void _setScaleRatio() {
+    mouseState.cursorScaleRatio = application.displayScaleRatio;
   }
 
   void _onActiveMeasureItemChanged(_, IMeasureItem? e) {

+ 27 - 2
lib/view/gesture/positioned_cursor.dart

@@ -17,15 +17,21 @@ abstract class IMouseState {
   double get cursorSize;
   set cursorSize(double value);
 
+  /// 卡尺缩放比
+  double get cursorScaleRatio;
+  set cursorScaleRatio(double value);
+
   late FEventHandler<Offset?> mousePositionChanged;
   late FEventHandler<MeasureCursorType> cursorTypeChanged;
   late FEventHandler<double> cursorSizeChanged;
+  late FEventHandler<double> cursorScaleRatioChanged;
   late FEventHandler<CrossIndicatorStyle> crossIndicatorStyleChanged;
 }
 
 class MouseState implements IMouseState {
   Offset? _mousePosition;
   double _cursorSize = 16;
+  double _cursorScaleRatio = 1;
   MeasureCursorType _cursorType = MeasureCursorType.cursor01;
 
   @override
@@ -33,6 +39,8 @@ class MouseState implements IMouseState {
 
   @override
   var cursorSizeChanged = FEventHandler<double>();
+  @override
+  var cursorScaleRatioChanged = FEventHandler<double>();
 
   @override
   var cursorTypeChanged = FEventHandler<MeasureCursorType>();
@@ -60,6 +68,16 @@ class MouseState implements IMouseState {
     }
   }
 
+  @override
+  double get cursorScaleRatio => _cursorScaleRatio;
+  @override
+  set cursorScaleRatio(double value) {
+    if (value != _cursorScaleRatio) {
+      _cursorScaleRatio = value;
+      cursorScaleRatioChanged.emit(this, value);
+    }
+  }
+
   @override
   MeasureCursorType get cursorType => _cursorType;
   @override
@@ -75,7 +93,7 @@ class MouseState implements IMouseState {
     if (mousePosition == null) return null;
 
     double dx = mousePosition!.dx, dy = mousePosition!.dy;
-    final offset = cursorSize / 2;
+    final offset = cursorScaleRatio * cursorSize / 2;
     dx -= offset;
     dy -= offset;
     return Offset(dx, dy);
@@ -95,6 +113,7 @@ class _PositionedCursorState extends State<PositionedCursor> {
   @override
   void initState() {
     mouseState.cursorSizeChanged.addListener(onCursorSizeChanged);
+    mouseState.cursorScaleRatioChanged.addListener(onCursorScaleRatioChanged);
     mouseState.cursorTypeChanged.addListener(cursorTypeChanged);
     mouseState.mousePositionChanged.addListener(mousePositionChanged);
     super.initState();
@@ -103,6 +122,8 @@ class _PositionedCursorState extends State<PositionedCursor> {
   @override
   void dispose() {
     mouseState.cursorSizeChanged.removeListener(onCursorSizeChanged);
+    mouseState.cursorScaleRatioChanged
+        .removeListener(onCursorScaleRatioChanged);
     mouseState.cursorTypeChanged.removeListener(cursorTypeChanged);
     mouseState.mousePositionChanged.removeListener(mousePositionChanged);
     super.dispose();
@@ -118,7 +139,7 @@ class _PositionedCursorState extends State<PositionedCursor> {
       top: position.dy,
       child: MeasureCursor(
         type: mouseState.cursorType,
-        size: mouseState.cursorSize,
+        size: mouseState.cursorSize * mouseState.cursorScaleRatio,
         color: MeasureColors.Primary,
       ),
     );
@@ -128,6 +149,10 @@ class _PositionedCursorState extends State<PositionedCursor> {
     onUpdate();
   }
 
+  void onCursorScaleRatioChanged(Object sender, dynamic e) {
+    onUpdate();
+  }
+
   void cursorTypeChanged(Object sender, dynamic e) {
     onUpdate();
   }

+ 1 - 1
lib/view/measure/measure_config/measure_configuation_page.dart

@@ -172,7 +172,7 @@ class MeasureConfigurationPageState extends State<MeasureConfigurationPage> {
   FWidget build(BuildContext context) {
     return FSimpleDialog(
       title: FText(
-        i18nBook.measure.config.t,
+        i18nBook.user.setting.t,
         style: const TextStyle(
           color: Colors.white,
           fontSize: 18,