Browse Source

update(measure): 完成【窗口位置】配置项 #0009042 Review by baka

gavin.chen 2 years ago
parent
commit
6678f2750d

+ 42 - 1
lib/view/measure/measure_config/widgets/measure_configuration_style.dart

@@ -14,7 +14,7 @@ import 'package:get/get.dart';
 
 part './measure_configuration_style_components.dart';
 
-/// 下拉选择的类
+/// 字体大小下拉选择的类
 class MeasureSelectModel {
   MeasureSelectModel({required this.name, required this.value});
   final String name;
@@ -96,6 +96,8 @@ class PatternDialog extends StatelessWidget {
 
   // 保存修改结果
   Future<void> _saveMeasureSystemSettingAsync() async {
+    measureData.measureSystemSettingChanged
+        .emit(this, measureData.measureSystemSetting);
     await measureData
         .saveMeasureSystemSettingAsync(measureData.measureSystemSetting);
     mouseState.cursorType = getMeasureSystemSettingCursorType(
@@ -170,6 +172,26 @@ class _PatternBodyState extends FState<PatternBody> {
     ),
   ];
 
+  /// [窗口位置] 枚举值
+  static final List<MeasureSelectModel> C_PANEL_POSITION = [
+    MeasureSelectModel(
+      name: '左侧顶部',
+      value: 0,
+    ),
+    MeasureSelectModel(
+      name: '左侧底部',
+      value: 1,
+    ),
+    MeasureSelectModel(
+      name: '右侧顶部',
+      value: 2,
+    ),
+    MeasureSelectModel(
+      name: '右侧底部',
+      value: 3,
+    ),
+  ];
+
   @override
   void initState() {
     super.initState();
@@ -274,6 +296,25 @@ class _PatternBodyState extends FState<PatternBody> {
                   value: widget.measureSystemSetting.showResultWindow,
                 ),
               ),
+              //窗口位置
+              _PatternItem(
+                title: "窗口位置", //TODO:[Gavin] i18n
+                item: _PatternItemSelect(
+                  itemList: C_PANEL_POSITION,
+                  value:
+                      widget.measureSystemSetting.showResultLocation.toString(),
+                  onChanged: (value) {
+                    try {
+                      setState(() {
+                        measureData.measureSystemSetting.showResultLocation =
+                            int.parse(value);
+                      });
+                    } catch (e) {
+                      logger.e("int.parse failed", e);
+                    }
+                  },
+                ),
+              ),
               //字体大小
               _PatternItem(
                 title: i18nBook.measure.fontSize.t,

+ 4 - 2
lib/view/measure/measure_main_view.dart

@@ -566,6 +566,8 @@ class _LayerLayoutDelegate extends MultiChildLayoutDelegate {
     final rightSpace = (size.width - renderSize.width) / 2;
     // 如果图像右侧剩余可用空间大于60,则将按钮组放在右侧,如果小于60,则尽可能靠右,60是按钮组宽度
     final buttonGroupOffsetX = min(rightSpace, 60.0);
+    final resultPanelLayerSize =
+        Size(renderSize.width + rightSpace, renderSize.height);
 
     /// 同步图像显示尺寸
     application.displaySize = renderSize;
@@ -581,8 +583,8 @@ class _LayerLayoutDelegate extends MultiChildLayoutDelegate {
     layoutLayer(_LayerLayoutIds.gesture, offset, renderSize);
     layoutLayer(
       _LayerLayoutIds.result,
-      const Offset(20, 2),
-      renderSize,
+      Offset.zero,
+      resultPanelLayerSize,
     );
     layoutLayer(_LayerLayoutIds.pause, offset, renderSize);
     layoutLayer(_LayerLayoutIds.paintAI, offset, renderSize);

+ 67 - 36
lib/view/result/results_panel.dart

@@ -1,6 +1,7 @@
 import 'dart:ui' as ui;
 import 'package:fis_measure/interfaces/process/items/item_feature.dart';
 import 'package:fis_measure/interfaces/process/workspace/application.dart';
+import 'package:fis_measure/process/workspace/measure_data_controller.dart';
 import 'package:fis_measure/values/colors.dart';
 import 'package:fis_ui/index.dart';
 import 'package:flutter/material.dart';
@@ -20,6 +21,7 @@ class MeasureResultPanel extends StatefulWidget {
 class _MeasureResultPanelState extends State<MeasureResultPanel> {
   final _scrollController = ScrollController();
   final application = Get.find<IApplication>();
+  final measureData = Get.find<MeasureDataController>();
 
   final List<ResultLine> lines = [];
 
@@ -29,45 +31,50 @@ class _MeasureResultPanelState extends State<MeasureResultPanel> {
   Widget build(BuildContext context) {
     if (!hasOutputs) return const SizedBox();
 
-    final child = Container(
-      constraints: const BoxConstraints(
-        maxWidth: 300,
-        minWidth: 150,
-        maxHeight: 400,
-      ),
-      decoration: BoxDecoration(
-        border: Border.all(
-          color: MeasureColors.ResultBorder,
-          width: 2,
+    return Align(
+      alignment: _getAlignmentFromLocation(
+          measureData.measureSystemSetting.showResultLocation),
+      child: Container(
+        margin: const EdgeInsets.only(left: 20, top: 2, right: 20, bottom: 2),
+        constraints: const BoxConstraints(
+          maxWidth: 300,
+          minWidth: 150,
+          maxHeight: 400,
         ),
-        borderRadius: BorderRadius.circular(4),
-        color: Colors.black.withOpacity(0.7),
-      ),
-      // padding: const EdgeInsets.only(left: 2),
-      child: FThemeWidget(
-        data: Theme.of(context).copyWith(
-          scrollbarTheme: ScrollbarThemeData(
-            thumbColor: MaterialStateProperty.all(
-              MeasureColors.ResultScrollbar,
-            ),
-            crossAxisMargin: 1,
+        decoration: BoxDecoration(
+          border: Border.all(
+            color: MeasureColors.ResultBorder,
+            width: 2,
           ),
+          borderRadius: BorderRadius.circular(4),
+          color: Colors.black.withOpacity(0.7),
         ),
-        child: FScrollbar(
-          isAlwaysShown: false,
-          controller: _scrollController,
-          radius: ui.Radius.zero,
-          child: FSingleChildScrollView(
+        // padding: const EdgeInsets.only(left: 2),
+        child: FThemeWidget(
+          data: Theme.of(context).copyWith(
+            scrollbarTheme: ScrollbarThemeData(
+              thumbColor: MaterialStateProperty.all(
+                MeasureColors.ResultScrollbar,
+              ),
+              crossAxisMargin: 1,
+            ),
+          ),
+          child: FScrollbar(
+            isAlwaysShown: false,
             controller: _scrollController,
-            child: FRepaintBoundary(
-              child: FIntrinsicHeight(
-                child: FIntrinsicWidth(
-                  child: FContainer(
-                    margin: const EdgeInsets.all(8),
-                    child: FColumn(
-                      mainAxisSize: MainAxisSize.min,
-                      crossAxisAlignment: CrossAxisAlignment.start,
-                      children: _buildMainList(),
+            radius: ui.Radius.zero,
+            child: FSingleChildScrollView(
+              controller: _scrollController,
+              child: FRepaintBoundary(
+                child: FIntrinsicHeight(
+                  child: FIntrinsicWidth(
+                    child: FContainer(
+                      margin: const EdgeInsets.all(8),
+                      child: FColumn(
+                        mainAxisSize: MainAxisSize.min,
+                        crossAxisAlignment: CrossAxisAlignment.start,
+                        children: _buildMainList(),
+                      ),
                     ),
                   ),
                 ),
@@ -77,22 +84,46 @@ class _MeasureResultPanelState extends State<MeasureResultPanel> {
         ),
       ),
     );
-    return child;
   }
 
   @override
   void initState() {
     _updateOutputs();
     application.updateRenderReady.addListener(_onMeasureRerenderReady);
+    measureData.measureSystemSettingChanged
+        .addListener(_onMeasureSystemSettingChanged);
     super.initState();
   }
 
   @override
   void dispose() {
     application.updateRenderReady.removeListener(_onMeasureRerenderReady);
+    measureData.measureSystemSettingChanged
+        .removeListener(_onMeasureSystemSettingChanged);
     super.dispose();
   }
 
+  /// 样式更新事件监听
+  _onMeasureSystemSettingChanged(_, e) {
+    setState(() {});
+  }
+
+  /// 面板对齐方式
+  Alignment _getAlignmentFromLocation(int locationNum) {
+    switch (locationNum) {
+      case 0:
+        return Alignment.topLeft;
+      case 1:
+        return Alignment.bottomLeft;
+      case 2:
+        return Alignment.topRight;
+      case 3:
+        return Alignment.bottomRight;
+      default:
+        return Alignment.topLeft;
+    }
+  }
+
   List<FWidget> _buildMainList() {
     final list = <FWidget>[
       const FSizedBox(height: 6),