2022-09-27 22:16:27 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2023-01-10 14:11:49 +08:00
|
|
|
import 'package:flutter_hbb/models/state_model.dart';
|
2022-09-27 22:16:27 +08:00
|
|
|
|
|
|
|
import '../../models/input_model.dart';
|
|
|
|
|
|
|
|
class RawKeyFocusScope extends StatelessWidget {
|
|
|
|
final FocusNode? focusNode;
|
|
|
|
final ValueChanged<bool>? onFocusChange;
|
|
|
|
final InputModel inputModel;
|
|
|
|
final Widget child;
|
|
|
|
|
2022-12-21 22:39:30 +08:00
|
|
|
RawKeyFocusScope({
|
|
|
|
this.focusNode,
|
|
|
|
this.onFocusChange,
|
|
|
|
required this.inputModel,
|
|
|
|
required this.child,
|
|
|
|
});
|
2022-09-27 22:16:27 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return FocusScope(
|
|
|
|
autofocus: true,
|
|
|
|
child: Focus(
|
|
|
|
autofocus: true,
|
|
|
|
canRequestFocus: true,
|
|
|
|
focusNode: focusNode,
|
|
|
|
onFocusChange: onFocusChange,
|
2023-01-10 14:11:49 +08:00
|
|
|
onKey:
|
|
|
|
stateGlobal.grabKeyboard ? inputModel.handleRawKeyEvent : null,
|
2022-09-27 22:16:27 +08:00
|
|
|
child: child));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class RawPointerMouseRegion extends StatelessWidget {
|
|
|
|
final InputModel inputModel;
|
|
|
|
final Widget child;
|
|
|
|
final MouseCursor? cursor;
|
|
|
|
final PointerEnterEventListener? onEnter;
|
|
|
|
final PointerExitEventListener? onExit;
|
2022-12-21 22:39:30 +08:00
|
|
|
final PointerDownEventListener? onPointerDown;
|
|
|
|
final PointerUpEventListener? onPointerUp;
|
2022-09-27 22:16:27 +08:00
|
|
|
|
|
|
|
RawPointerMouseRegion(
|
|
|
|
{this.onEnter,
|
|
|
|
this.onExit,
|
|
|
|
this.cursor,
|
2022-12-21 22:39:30 +08:00
|
|
|
this.onPointerDown,
|
|
|
|
this.onPointerUp,
|
2022-09-27 22:16:27 +08:00
|
|
|
required this.inputModel,
|
|
|
|
required this.child});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Listener(
|
|
|
|
onPointerHover: inputModel.onPointHoverImage,
|
2022-12-21 22:39:30 +08:00
|
|
|
onPointerDown: (evt) {
|
|
|
|
onPointerDown?.call(evt);
|
|
|
|
inputModel.onPointDownImage(evt);
|
|
|
|
},
|
|
|
|
onPointerUp: (evt) {
|
|
|
|
onPointerUp?.call(evt);
|
|
|
|
inputModel.onPointUpImage(evt);
|
|
|
|
},
|
2022-09-27 22:16:27 +08:00
|
|
|
onPointerMove: inputModel.onPointMoveImage,
|
|
|
|
onPointerSignal: inputModel.onPointerSignalImage,
|
2022-11-20 22:46:27 +08:00
|
|
|
onPointerPanZoomStart: inputModel.onPointerPanZoomStart,
|
|
|
|
onPointerPanZoomUpdate: inputModel.onPointerPanZoomUpdate,
|
|
|
|
onPointerPanZoomEnd: inputModel.onPointerPanZoomEnd,
|
2022-09-27 22:16:27 +08:00
|
|
|
child: MouseRegion(
|
|
|
|
cursor: cursor ?? MouseCursor.defer,
|
|
|
|
onEnter: onEnter,
|
|
|
|
onExit: onExit,
|
|
|
|
child: child));
|
|
|
|
}
|
|
|
|
}
|