rustdesk/flutter/lib/mobile/widgets/gesture_help.dart

215 lines
8.0 KiB
Dart
Raw Normal View History

2022-02-23 21:16:30 +08:00
import 'package:flutter/material.dart';
2022-02-23 21:32:33 +08:00
import 'package:flutter_hbb/common.dart';
2022-02-23 21:16:30 +08:00
import 'package:toggle_switch/toggle_switch.dart';
class GestureIcons {
static const String _family = 'gestureicons';
GestureIcons._();
static const IconData icon_mouse = IconData(0xe65c, fontFamily: _family);
static const IconData icon_Tablet_Touch =
IconData(0xe9ce, fontFamily: _family);
static const IconData icon_gesture_f_drag =
IconData(0xe686, fontFamily: _family);
static const IconData icon_Mobile_Touch =
IconData(0xe9cd, fontFamily: _family);
static const IconData icon_gesture_press =
IconData(0xe66c, fontFamily: _family);
static const IconData icon_gesture_tap =
IconData(0xe66f, fontFamily: _family);
static const IconData icon_gesture_pinch =
IconData(0xe66a, fontFamily: _family);
static const IconData icon_gesture_press_hold =
IconData(0xe66b, fontFamily: _family);
static const IconData icon_gesture_f_drag_up_down_ =
IconData(0xe685, fontFamily: _family);
static const IconData icon_gesture_f_tap_ =
IconData(0xe68e, fontFamily: _family);
static const IconData icon_gesture_f_swipe_right =
IconData(0xe68f, fontFamily: _family);
static const IconData icon_gesture_f_double_tap =
IconData(0xe691, fontFamily: _family);
2022-05-12 22:09:45 +08:00
static const IconData icon_gesture_f_three_fingers =
IconData(0xe687, fontFamily: _family);
2022-02-23 21:16:30 +08:00
}
2022-02-24 15:59:03 +08:00
typedef OnTouchModeChange = void Function(bool);
2022-02-23 21:16:30 +08:00
class GestureHelp extends StatefulWidget {
2022-03-23 16:28:37 +08:00
GestureHelp(
{Key? key, required this.touchMode, required this.onTouchModeChange})
: super(key: key);
2022-02-24 15:59:03 +08:00
final bool touchMode;
final OnTouchModeChange onTouchModeChange;
2022-03-23 16:28:37 +08:00
2022-02-23 21:16:30 +08:00
@override
State<StatefulWidget> createState() => _GestureHelpState();
}
class _GestureHelpState extends State<GestureHelp> {
2022-02-23 21:32:33 +08:00
var _selectedIndex;
var _touchMode;
@override
void initState() {
2022-02-24 15:59:03 +08:00
_touchMode = widget.touchMode;
2022-02-23 21:32:33 +08:00
_selectedIndex = _touchMode ? 1 : 0;
super.initState();
}
2022-02-23 21:16:30 +08:00
@override
Widget build(BuildContext context) {
2022-04-05 02:02:49 +08:00
final size = MediaQuery.of(context).size;
final space = 12.0;
var width = size.width - 2 * space;
final minWidth = 90;
if (size.width > minWidth + 2 * space) {
final n = (size.width / (minWidth + 2 * space)).floor();
width = size.width / n - 2 * space;
}
2022-02-23 21:16:30 +08:00
return Center(
child: Padding(
2022-04-05 02:02:49 +08:00
padding: const EdgeInsets.symmetric(vertical: 12.0),
2022-02-23 21:16:30 +08:00
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
2022-04-05 02:02:49 +08:00
crossAxisAlignment: CrossAxisAlignment.center,
2022-02-23 21:16:30 +08:00
children: <Widget>[
ToggleSwitch(
initialLabelIndex: _selectedIndex,
2023-02-09 09:29:35 +08:00
activeFgColor: Colors.white,
inactiveFgColor: Colors.white60,
activeBgColor: [MyTheme.accent],
inactiveBgColor: Theme.of(context).hintColor,
2022-02-23 21:16:30 +08:00
totalSwitches: 2,
2022-03-23 16:28:37 +08:00
minWidth: 150,
2022-02-23 21:16:30 +08:00
fontSize: 15,
2022-03-23 16:28:37 +08:00
iconSize: 18,
2022-04-08 16:57:47 +08:00
labels: [translate("Mouse mode"), translate("Touch mode")],
2022-03-23 16:28:37 +08:00
icons: [Icons.mouse, Icons.touch_app],
2022-02-23 21:16:30 +08:00
onToggle: (index) {
setState(() {
2022-03-23 16:28:37 +08:00
if (_selectedIndex != index) {
2022-02-24 15:59:03 +08:00
_selectedIndex = index ?? 0;
_touchMode = index == 0 ? false : true;
widget.onTouchModeChange(_touchMode);
}
2022-02-23 21:16:30 +08:00
});
},
),
2022-04-05 02:02:49 +08:00
const SizedBox(height: 30),
2022-03-23 16:28:37 +08:00
Container(
2022-04-05 02:02:49 +08:00
child: Wrap(
spacing: space,
runSpacing: 2 * space,
2022-02-23 21:16:30 +08:00
children: _touchMode
2022-03-23 16:28:37 +08:00
? [
GestureInfo(
2022-04-05 02:02:49 +08:00
width,
2022-03-23 16:28:37 +08:00
GestureIcons.icon_Mobile_Touch,
translate("One-Finger Tap"),
translate("Left Mouse")),
GestureInfo(
2022-04-05 02:02:49 +08:00
width,
2022-03-23 16:28:37 +08:00
GestureIcons.icon_gesture_press_hold,
translate("One-Long Tap"),
translate("Right Mouse")),
GestureInfo(
2022-04-05 02:02:49 +08:00
width,
2022-03-23 16:28:37 +08:00
GestureIcons.icon_gesture_f_swipe_right,
translate("One-Finger Move"),
translate("Mouse Drag")),
2022-02-23 21:16:30 +08:00
GestureInfo(
2022-04-05 02:02:49 +08:00
width,
2022-05-12 22:09:45 +08:00
GestureIcons.icon_gesture_f_three_fingers,
translate("Three-Finger vertically"),
2022-03-23 16:28:37 +08:00
translate("Mouse Wheel")),
2022-02-23 21:16:30 +08:00
GestureInfo(
2022-04-05 02:02:49 +08:00
width,
2022-03-23 16:28:37 +08:00
GestureIcons.icon_gesture_f_drag,
translate("Two-Finger Move"),
translate("Canvas Move")),
2022-02-23 21:16:30 +08:00
GestureInfo(
2022-04-05 02:02:49 +08:00
width,
2022-03-23 16:28:37 +08:00
GestureIcons.icon_gesture_pinch,
translate("Pinch to Zoom"),
translate("Canvas Zoom")),
2022-02-23 21:16:30 +08:00
]
2022-03-23 16:28:37 +08:00
: [
2022-02-23 21:16:30 +08:00
GestureInfo(
2022-04-05 02:02:49 +08:00
width,
2022-03-23 16:28:37 +08:00
GestureIcons.icon_Mobile_Touch,
translate("One-Finger Tap"),
translate("Left Mouse")),
2022-02-23 21:16:30 +08:00
GestureInfo(
2022-04-05 02:02:49 +08:00
width,
2022-05-12 22:09:45 +08:00
GestureIcons.icon_gesture_press_hold,
translate("One-Long Tap"),
2022-03-23 16:28:37 +08:00
translate("Right Mouse")),
2022-02-23 21:16:30 +08:00
GestureInfo(
2022-04-05 02:02:49 +08:00
width,
2022-03-23 16:28:37 +08:00
GestureIcons.icon_gesture_f_swipe_right,
translate("Double Tap & Move"),
translate("Mouse Drag")),
2022-02-23 21:16:30 +08:00
GestureInfo(
2022-04-05 02:02:49 +08:00
width,
2022-05-12 22:09:45 +08:00
GestureIcons.icon_gesture_f_three_fingers,
translate("Three-Finger vertically"),
2022-03-23 16:28:37 +08:00
translate("Mouse Wheel")),
GestureInfo(
2022-04-05 02:02:49 +08:00
width,
2022-03-23 16:28:37 +08:00
GestureIcons.icon_gesture_f_drag,
translate("Two-Finger Move"),
translate("Canvas Move")),
GestureInfo(
2022-04-05 02:02:49 +08:00
width,
2022-03-23 16:28:37 +08:00
GestureIcons.icon_gesture_pinch,
translate("Pinch to Zoom"),
translate("Canvas Zoom")),
2022-02-23 21:16:30 +08:00
],
2022-03-23 16:28:37 +08:00
)),
2022-02-23 21:16:30 +08:00
],
)));
}
}
class GestureInfo extends StatelessWidget {
2022-04-05 02:02:49 +08:00
const GestureInfo(this.width, this.icon, this.fromText, this.toText,
{Key? key})
2022-02-23 21:16:30 +08:00
: super(key: key);
final String fromText;
final String toText;
final IconData icon;
2022-04-05 02:02:49 +08:00
final double width;
2022-02-23 21:16:30 +08:00
final iconSize = 35.0;
2022-04-05 02:02:49 +08:00
final iconColor = MyTheme.accent;
2022-02-23 21:16:30 +08:00
@override
Widget build(BuildContext context) {
2022-04-05 02:02:49 +08:00
return Container(
2023-02-09 09:29:35 +08:00
width: width,
2022-04-05 02:02:49 +08:00
child: Column(
2022-03-23 16:28:37 +08:00
children: [
2022-04-05 02:02:49 +08:00
Icon(
icon,
size: iconSize,
color: iconColor,
),
SizedBox(height: 6),
Text(fromText,
textAlign: TextAlign.center,
2023-02-09 09:29:35 +08:00
style:
TextStyle(fontSize: 9, color: Theme.of(context).hintColor)),
2022-04-05 02:02:49 +08:00
SizedBox(height: 3),
Text(toText,
textAlign: TextAlign.center,
2023-02-09 09:29:35 +08:00
style: TextStyle(
fontSize: 12,
color: Theme.of(context).textTheme.bodySmall?.color))
2022-03-23 16:28:37 +08:00
],
));
2022-02-23 21:16:30 +08:00
}
}