input_position_panel.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // ignore_for_file: constant_identifier_names
  2. import 'package:fis_measure/interfaces/process/workspace/application.dart';
  3. import 'package:fis_measure/interfaces/process/workspace/point_info.dart';
  4. import 'package:fis_measure/values/colors.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:get/get.dart';
  7. import '../positioned_cursor.dart';
  8. /// 自定义注释文本框定位面板
  9. class AnnotationInputPositionPanel extends StatefulWidget {
  10. const AnnotationInputPositionPanel({Key? key}) : super(key: key);
  11. @override
  12. State<AnnotationInputPositionPanel> createState() => _PanelState();
  13. }
  14. class _PanelState extends State<AnnotationInputPositionPanel> {
  15. late final application = Get.find<IApplication>();
  16. final mouseState = Get.put<IMouseState>(MouseState()..cursorSize = 10);
  17. Offset? position;
  18. @override
  19. Widget build(BuildContext context) {
  20. return GestureDetector(
  21. onPanDown: (details) {
  22. setState(() {
  23. position = details.localPosition;
  24. application.createPointInfo(position!, PointInfoType.mouseDown);
  25. });
  26. },
  27. child: MouseRegion(
  28. cursor: SystemMouseCursors.none,
  29. onHover: (event) {
  30. mouseState.mousePosition = event.localPosition +
  31. const Offset(
  32. _InputWidget.C_MIN_WIDTH / 2,
  33. _InputWidget.C_MAX_HEIGHT / 2,
  34. );
  35. },
  36. child: Stack(
  37. children: [
  38. if (position != null)
  39. Positioned(
  40. child: _InputWidget(
  41. key: UniqueKey(),
  42. onChanged: (value) {
  43. application.activeAnnotationItem?.text = value;
  44. },
  45. ),
  46. left: position!.dx,
  47. top: position!.dy,
  48. ),
  49. const PositionedCursor(),
  50. ],
  51. ),
  52. ),
  53. );
  54. }
  55. }
  56. typedef _InputValueChanged = void Function(String value);
  57. class _InputWidget extends StatelessWidget {
  58. static const C_BG_COLOR = Color.fromARGB(255, 121, 135, 151);
  59. static const C_MIN_WIDTH = 40.0;
  60. static const C_MAX_HEIGHT = 28.0;
  61. final FocusNode? focusNode;
  62. final _InputValueChanged onChanged;
  63. const _InputWidget({
  64. required this.onChanged,
  65. Key? key,
  66. this.focusNode,
  67. }) : super(key: key);
  68. @override
  69. Widget build(BuildContext context) {
  70. const border = OutlineInputBorder(
  71. borderSide: BorderSide(color: C_BG_COLOR),
  72. borderRadius: BorderRadius.all(Radius.circular(4.0)),
  73. );
  74. final input = TextField(
  75. expands: false,
  76. autofocus: true,
  77. focusNode: focusNode,
  78. style: const TextStyle(color: MeasureColors.Primary),
  79. cursorColor: MeasureColors.Primary,
  80. cursorWidth: 1.0,
  81. onChanged: onChanged,
  82. decoration: const InputDecoration(
  83. border: border,
  84. enabledBorder: border,
  85. focusedBorder: border,
  86. counterText: '',
  87. filled: true,
  88. fillColor: C_BG_COLOR,
  89. isCollapsed: false,
  90. contentPadding: EdgeInsets.symmetric(horizontal: 2, vertical: 8),
  91. constraints:
  92. BoxConstraints(minWidth: C_MIN_WIDTH, maxHeight: C_MAX_HEIGHT),
  93. ),
  94. );
  95. return Container(
  96. padding: const EdgeInsets.symmetric(horizontal: 1),
  97. alignment: Alignment.topLeft,
  98. child: IntrinsicWidth(child: input),
  99. );
  100. }
  101. }