gesture_help.dart 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_hbb/common.dart';
  3. import 'package:toggle_switch/toggle_switch.dart';
  4. class GestureIcons {
  5. static const String _family = 'gestureicons';
  6. GestureIcons._();
  7. static const IconData iconMouse = IconData(0xe65c, fontFamily: _family);
  8. static const IconData iconTabletTouch = IconData(0xe9ce, fontFamily: _family);
  9. static const IconData iconGestureFDrag =
  10. IconData(0xe686, fontFamily: _family);
  11. static const IconData iconMobileTouch = IconData(0xe9cd, fontFamily: _family);
  12. static const IconData iconGesturePress =
  13. IconData(0xe66c, fontFamily: _family);
  14. static const IconData iconGestureTap = IconData(0xe66f, fontFamily: _family);
  15. static const IconData iconGesturePinch =
  16. IconData(0xe66a, fontFamily: _family);
  17. static const IconData iconGesturePressHold =
  18. IconData(0xe66b, fontFamily: _family);
  19. static const IconData iconGestureFDragUpDown_ =
  20. IconData(0xe685, fontFamily: _family);
  21. static const IconData iconGestureFTap_ =
  22. IconData(0xe68e, fontFamily: _family);
  23. static const IconData iconGestureFSwipeRight =
  24. IconData(0xe68f, fontFamily: _family);
  25. static const IconData iconGestureFdoubleTap =
  26. IconData(0xe691, fontFamily: _family);
  27. static const IconData iconGestureFThreeFingers =
  28. IconData(0xe687, fontFamily: _family);
  29. }
  30. typedef OnTouchModeChange = void Function(bool);
  31. class GestureHelp extends StatefulWidget {
  32. GestureHelp(
  33. {Key? key, required this.touchMode, required this.onTouchModeChange})
  34. : super(key: key);
  35. final bool touchMode;
  36. final OnTouchModeChange onTouchModeChange;
  37. @override
  38. State<StatefulWidget> createState() => _GestureHelpState(touchMode);
  39. }
  40. class _GestureHelpState extends State<GestureHelp> {
  41. late int _selectedIndex;
  42. late bool _touchMode;
  43. _GestureHelpState(bool touchMode) {
  44. _touchMode = touchMode;
  45. _selectedIndex = _touchMode ? 1 : 0;
  46. }
  47. @override
  48. Widget build(BuildContext context) {
  49. final size = MediaQuery.of(context).size;
  50. final space = 12.0;
  51. var width = size.width - 2 * space;
  52. final minWidth = 90;
  53. if (size.width > minWidth + 2 * space) {
  54. final n = (size.width / (minWidth + 2 * space)).floor();
  55. width = size.width / n - 2 * space;
  56. }
  57. return Center(
  58. child: Padding(
  59. padding: const EdgeInsets.symmetric(vertical: 12.0),
  60. child: Column(
  61. mainAxisAlignment: MainAxisAlignment.center,
  62. crossAxisAlignment: CrossAxisAlignment.center,
  63. children: <Widget>[
  64. ToggleSwitch(
  65. initialLabelIndex: _selectedIndex,
  66. activeFgColor: Colors.white,
  67. inactiveFgColor: Colors.white60,
  68. activeBgColor: [MyTheme.accent],
  69. inactiveBgColor: Theme.of(context).hintColor,
  70. totalSwitches: 2,
  71. minWidth: 150,
  72. fontSize: 15,
  73. iconSize: 18,
  74. labels: [translate("Mouse mode"), translate("Touch mode")],
  75. icons: [Icons.mouse, Icons.touch_app],
  76. onToggle: (index) {
  77. setState(() {
  78. if (_selectedIndex != index) {
  79. _selectedIndex = index ?? 0;
  80. _touchMode = index == 0 ? false : true;
  81. widget.onTouchModeChange(_touchMode);
  82. }
  83. });
  84. },
  85. ),
  86. const SizedBox(height: 30),
  87. Container(
  88. child: Wrap(
  89. spacing: space,
  90. runSpacing: 2 * space,
  91. children: _touchMode
  92. ? [
  93. GestureInfo(
  94. width,
  95. GestureIcons.iconMobileTouch,
  96. translate("One-Finger Tap"),
  97. translate("Left Mouse")),
  98. GestureInfo(
  99. width,
  100. GestureIcons.iconGesturePressHold,
  101. translate("One-Long Tap"),
  102. translate("Right Mouse")),
  103. GestureInfo(
  104. width,
  105. GestureIcons.iconGestureFSwipeRight,
  106. translate("One-Finger Move"),
  107. translate("Mouse Drag")),
  108. GestureInfo(
  109. width,
  110. GestureIcons.iconGestureFThreeFingers,
  111. translate("Three-Finger vertically"),
  112. translate("Mouse Wheel")),
  113. GestureInfo(
  114. width,
  115. GestureIcons.iconGestureFDrag,
  116. translate("Two-Finger Move"),
  117. translate("Canvas Move")),
  118. GestureInfo(
  119. width,
  120. GestureIcons.iconGesturePinch,
  121. translate("Pinch to Zoom"),
  122. translate("Canvas Zoom")),
  123. ]
  124. : [
  125. GestureInfo(
  126. width,
  127. GestureIcons.iconMobileTouch,
  128. translate("One-Finger Tap"),
  129. translate("Left Mouse")),
  130. GestureInfo(
  131. width,
  132. GestureIcons.iconGesturePressHold,
  133. translate("One-Long Tap"),
  134. translate("Right Mouse")),
  135. GestureInfo(
  136. width,
  137. GestureIcons.iconGestureFSwipeRight,
  138. translate("Double Tap & Move"),
  139. translate("Mouse Drag")),
  140. GestureInfo(
  141. width,
  142. GestureIcons.iconGestureFThreeFingers,
  143. translate("Three-Finger vertically"),
  144. translate("Mouse Wheel")),
  145. GestureInfo(
  146. width,
  147. GestureIcons.iconGestureFDrag,
  148. translate("Two-Finger Move"),
  149. translate("Canvas Move")),
  150. GestureInfo(
  151. width,
  152. GestureIcons.iconGesturePinch,
  153. translate("Pinch to Zoom"),
  154. translate("Canvas Zoom")),
  155. ],
  156. )),
  157. ],
  158. )));
  159. }
  160. }
  161. class GestureInfo extends StatelessWidget {
  162. const GestureInfo(this.width, this.icon, this.fromText, this.toText,
  163. {Key? key})
  164. : super(key: key);
  165. final String fromText;
  166. final String toText;
  167. final IconData icon;
  168. final double width;
  169. final iconSize = 35.0;
  170. final iconColor = MyTheme.accent;
  171. @override
  172. Widget build(BuildContext context) {
  173. return Container(
  174. width: width,
  175. child: Column(
  176. children: [
  177. Icon(
  178. icon,
  179. size: iconSize,
  180. color: iconColor,
  181. ),
  182. SizedBox(height: 6),
  183. Text(fromText,
  184. textAlign: TextAlign.center,
  185. style:
  186. TextStyle(fontSize: 9, color: Theme.of(context).hintColor)),
  187. SizedBox(height: 3),
  188. Text(toText,
  189. textAlign: TextAlign.center,
  190. style: TextStyle(
  191. fontSize: 12,
  192. color: Theme.of(context).textTheme.bodySmall?.color))
  193. ],
  194. ));
  195. }
  196. }