Add keyboard shortcuts for usage with BT Pedal
This commit is contained in:
42
lib/bt_pedal_shortcuts.dart
Normal file
42
lib/bt_pedal_shortcuts.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class BtPedalShortcuts extends StatefulWidget {
|
||||
final Widget child;
|
||||
final VoidCallback? onTurnPageForward;
|
||||
final VoidCallback? onTurnPageBackward;
|
||||
|
||||
const BtPedalShortcuts({
|
||||
super.key,
|
||||
required this.child,
|
||||
this.onTurnPageForward,
|
||||
this.onTurnPageBackward,
|
||||
});
|
||||
|
||||
@override
|
||||
State<BtPedalShortcuts> createState() => _BtPedalShortcutsState();
|
||||
}
|
||||
|
||||
class _BtPedalShortcutsState extends State<BtPedalShortcuts> {
|
||||
String lastAction = "Press pedal...";
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CallbackShortcuts(
|
||||
bindings: <ShortcutActivator, VoidCallback>{
|
||||
// Shortcuts for page forward
|
||||
const SingleActivator(LogicalKeyboardKey.arrowUp):
|
||||
widget.onTurnPageForward ?? () => {},
|
||||
const SingleActivator(LogicalKeyboardKey.arrowRight):
|
||||
widget.onTurnPageForward ?? () => {},
|
||||
|
||||
// Shortcuts for page backward
|
||||
const SingleActivator(LogicalKeyboardKey.arrowDown):
|
||||
widget.onTurnPageBackward ?? () => {},
|
||||
const SingleActivator(LogicalKeyboardKey.arrowLeft):
|
||||
widget.onTurnPageBackward ?? () => {},
|
||||
},
|
||||
child: Focus(autofocus: true, child: widget.child),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter_drawing_board/flutter_drawing_board.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:pdfrx/pdfrx.dart';
|
||||
import 'package:sheetless/api.dart';
|
||||
import 'package:sheetless/bt_pedal_shortcuts.dart';
|
||||
import 'package:sheetless/sheet.dart';
|
||||
import 'package:sheetless/storage_helper.dart';
|
||||
|
||||
@@ -86,9 +87,19 @@ class _SheetViewerPageState extends State<SheetViewerPage> {
|
||||
}
|
||||
}
|
||||
|
||||
void turnPage(int numTurns) {
|
||||
setState(() {
|
||||
page += numTurns;
|
||||
page = page.clamp(1, numPages);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
return BtPedalShortcuts(
|
||||
onTurnPageForward: () => turnPage(1),
|
||||
onTurnPageBackward: () => turnPage(-1),
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(widget.sheet.name),
|
||||
actions: [
|
||||
@@ -136,7 +147,9 @@ class _SheetViewerPageState extends State<SheetViewerPage> {
|
||||
child: GestureDetector(
|
||||
onTapUp: (TapUpDetails details) {
|
||||
// Get the size of the screen
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
final screenWidth = MediaQuery.of(
|
||||
context,
|
||||
).size.width;
|
||||
|
||||
// print("Touch at y = ${details.localPosition.dy}");
|
||||
// print("Touch at x = ${details.localPosition.dx}");
|
||||
@@ -149,14 +162,10 @@ class _SheetViewerPageState extends State<SheetViewerPage> {
|
||||
// });
|
||||
if (details.localPosition.dx < screenWidth / 2) {
|
||||
// Left half of the screen
|
||||
setState(() {
|
||||
page = page > 1 ? page - 1 : 1;
|
||||
});
|
||||
turnPage(-1);
|
||||
} else {
|
||||
// Right half of the screen
|
||||
setState(() {
|
||||
page = page < numPages ? page + 1 : numPages;
|
||||
});
|
||||
turnPage(1);
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
@@ -203,7 +212,9 @@ class _SheetViewerPageState extends State<SheetViewerPage> {
|
||||
child: Container(
|
||||
alignment: Alignment.bottomCenter,
|
||||
padding: EdgeInsets.only(bottom: 5),
|
||||
child: Text('${page + 1} / $numPages'),
|
||||
child: Text(
|
||||
'${page + 1} / $numPages',
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -273,6 +284,7 @@ class _SheetViewerPageState extends State<SheetViewerPage> {
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user