Fix, cursor position, scall origin, scrollbar (#6612)
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
ebe044aee8
commit
3a82bddcd3
@ -540,8 +540,6 @@ class ImagePaint extends StatefulWidget {
|
|||||||
|
|
||||||
class _ImagePaintState extends State<ImagePaint> {
|
class _ImagePaintState extends State<ImagePaint> {
|
||||||
bool _lastRemoteCursorMoved = false;
|
bool _lastRemoteCursorMoved = false;
|
||||||
final ScrollController _horizontal = ScrollController();
|
|
||||||
final ScrollController _vertical = ScrollController();
|
|
||||||
|
|
||||||
String get id => widget.id;
|
String get id => widget.id;
|
||||||
RxBool get zoomCursor => widget.zoomCursor;
|
RxBool get zoomCursor => widget.zoomCursor;
|
||||||
@ -610,24 +608,18 @@ class _ImagePaintState extends State<ImagePaint> {
|
|||||||
: _buildScrollbarNonTextureRender(m, paintSize, s);
|
: _buildScrollbarNonTextureRender(m, paintSize, s);
|
||||||
return NotificationListener<ScrollNotification>(
|
return NotificationListener<ScrollNotification>(
|
||||||
onNotification: (notification) {
|
onNotification: (notification) {
|
||||||
final percentX = _horizontal.hasClients
|
c.updateScrollPercent();
|
||||||
? _horizontal.position.extentBefore /
|
|
||||||
(_horizontal.position.extentBefore +
|
|
||||||
_horizontal.position.extentInside +
|
|
||||||
_horizontal.position.extentAfter)
|
|
||||||
: 0.0;
|
|
||||||
final percentY = _vertical.hasClients
|
|
||||||
? _vertical.position.extentBefore /
|
|
||||||
(_vertical.position.extentBefore +
|
|
||||||
_vertical.position.extentInside +
|
|
||||||
_vertical.position.extentAfter)
|
|
||||||
: 0.0;
|
|
||||||
c.setScrollPercent(percentX, percentY);
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
child: mouseRegion(
|
child: mouseRegion(
|
||||||
child: Obx(() => _buildCrossScrollbarFromLayout(
|
child: Obx(() => _buildCrossScrollbarFromLayout(
|
||||||
context, _buildListener(paintWidget), c.size, paintSize)),
|
context,
|
||||||
|
_buildListener(paintWidget),
|
||||||
|
c.size,
|
||||||
|
paintSize,
|
||||||
|
c.scrollHorizontal,
|
||||||
|
c.scrollVertical,
|
||||||
|
)),
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
if (c.size.width > 0 && c.size.height > 0) {
|
if (c.size.width > 0 && c.size.height > 0) {
|
||||||
@ -740,7 +732,13 @@ class _ImagePaintState extends State<ImagePaint> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildCrossScrollbarFromLayout(
|
Widget _buildCrossScrollbarFromLayout(
|
||||||
BuildContext context, Widget child, Size layoutSize, Size size) {
|
BuildContext context,
|
||||||
|
Widget child,
|
||||||
|
Size layoutSize,
|
||||||
|
Size size,
|
||||||
|
ScrollController horizontal,
|
||||||
|
ScrollController vertical,
|
||||||
|
) {
|
||||||
final scrollConfig = CustomMouseWheelScrollConfig(
|
final scrollConfig = CustomMouseWheelScrollConfig(
|
||||||
scrollDuration: kDefaultScrollDuration,
|
scrollDuration: kDefaultScrollDuration,
|
||||||
scrollCurve: Curves.linearToEaseOut,
|
scrollCurve: Curves.linearToEaseOut,
|
||||||
@ -752,7 +750,7 @@ class _ImagePaintState extends State<ImagePaint> {
|
|||||||
widget = ScrollConfiguration(
|
widget = ScrollConfiguration(
|
||||||
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
|
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
controller: _horizontal,
|
controller: horizontal,
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
physics: cursorOverImage.isTrue
|
physics: cursorOverImage.isTrue
|
||||||
? const NeverScrollableScrollPhysics()
|
? const NeverScrollableScrollPhysics()
|
||||||
@ -774,7 +772,7 @@ class _ImagePaintState extends State<ImagePaint> {
|
|||||||
widget = ScrollConfiguration(
|
widget = ScrollConfiguration(
|
||||||
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
|
behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false),
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
controller: _vertical,
|
controller: vertical,
|
||||||
physics: cursorOverImage.isTrue
|
physics: cursorOverImage.isTrue
|
||||||
? const NeverScrollableScrollPhysics()
|
? const NeverScrollableScrollPhysics()
|
||||||
: null,
|
: null,
|
||||||
@ -793,13 +791,13 @@ class _ImagePaintState extends State<ImagePaint> {
|
|||||||
}
|
}
|
||||||
if (layoutSize.width < size.width) {
|
if (layoutSize.width < size.width) {
|
||||||
widget = ImprovedScrolling(
|
widget = ImprovedScrolling(
|
||||||
scrollController: _horizontal,
|
scrollController: horizontal,
|
||||||
enableCustomMouseWheelScrolling: cursorOverImage.isFalse,
|
enableCustomMouseWheelScrolling: cursorOverImage.isFalse,
|
||||||
customMouseWheelScrollConfig: scrollConfig,
|
customMouseWheelScrollConfig: scrollConfig,
|
||||||
child: RawScrollbar(
|
child: RawScrollbar(
|
||||||
thickness: kScrollbarThickness,
|
thickness: kScrollbarThickness,
|
||||||
thumbColor: Colors.grey,
|
thumbColor: Colors.grey,
|
||||||
controller: _horizontal,
|
controller: horizontal,
|
||||||
thumbVisibility: false,
|
thumbVisibility: false,
|
||||||
trackVisibility: false,
|
trackVisibility: false,
|
||||||
notificationPredicate: layoutSize.height < size.height
|
notificationPredicate: layoutSize.height < size.height
|
||||||
@ -811,13 +809,13 @@ class _ImagePaintState extends State<ImagePaint> {
|
|||||||
}
|
}
|
||||||
if (layoutSize.height < size.height) {
|
if (layoutSize.height < size.height) {
|
||||||
widget = ImprovedScrolling(
|
widget = ImprovedScrolling(
|
||||||
scrollController: _vertical,
|
scrollController: vertical,
|
||||||
enableCustomMouseWheelScrolling: cursorOverImage.isFalse,
|
enableCustomMouseWheelScrolling: cursorOverImage.isFalse,
|
||||||
customMouseWheelScrollConfig: scrollConfig,
|
customMouseWheelScrollConfig: scrollConfig,
|
||||||
child: RawScrollbar(
|
child: RawScrollbar(
|
||||||
thickness: kScrollbarThickness,
|
thickness: kScrollbarThickness,
|
||||||
thumbColor: Colors.grey,
|
thumbColor: Colors.grey,
|
||||||
controller: _vertical,
|
controller: vertical,
|
||||||
thumbVisibility: false,
|
thumbVisibility: false,
|
||||||
trackVisibility: false,
|
trackVisibility: false,
|
||||||
child: widget,
|
child: widget,
|
||||||
@ -874,11 +872,15 @@ class CursorPaint extends StatelessWidget {
|
|||||||
debugPrint('unreachable! The displays rect is null.');
|
debugPrint('unreachable! The displays rect is null.');
|
||||||
return Container();
|
return Container();
|
||||||
}
|
}
|
||||||
|
if (cx < 0) {
|
||||||
final imageWidth = rect.width * c.scale;
|
final imageWidth = rect.width * c.scale;
|
||||||
final imageHeight = rect.height * c.scale;
|
|
||||||
cx = -imageWidth * c.scrollX;
|
cx = -imageWidth * c.scrollX;
|
||||||
|
}
|
||||||
|
if (cy < 0) {
|
||||||
|
final imageHeight = rect.height * c.scale;
|
||||||
cy = -imageHeight * c.scrollY;
|
cy = -imageHeight * c.scrollY;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
double x = (m.x - hotx) * c.scale + cx;
|
double x = (m.x - hotx) * c.scale + cx;
|
||||||
double y = (m.y - hoty) * c.scale + cy;
|
double y = (m.y - hoty) * c.scale + cy;
|
||||||
|
@ -1205,6 +1205,9 @@ class CanvasModel with ChangeNotifier {
|
|||||||
ScrollStyle _scrollStyle = ScrollStyle.scrollauto;
|
ScrollStyle _scrollStyle = ScrollStyle.scrollauto;
|
||||||
ViewStyle _lastViewStyle = ViewStyle.defaultViewStyle();
|
ViewStyle _lastViewStyle = ViewStyle.defaultViewStyle();
|
||||||
|
|
||||||
|
final ScrollController _horizontal = ScrollController();
|
||||||
|
final ScrollController _vertical = ScrollController();
|
||||||
|
|
||||||
final _imageOverflow = false.obs;
|
final _imageOverflow = false.obs;
|
||||||
|
|
||||||
WeakReference<FFI> parent;
|
WeakReference<FFI> parent;
|
||||||
@ -1229,6 +1232,8 @@ class CanvasModel with ChangeNotifier {
|
|||||||
_scrollY = y;
|
_scrollY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScrollController get scrollHorizontal => _horizontal;
|
||||||
|
ScrollController get scrollVertical => _vertical;
|
||||||
double get scrollX => _scrollX;
|
double get scrollX => _scrollX;
|
||||||
double get scrollY => _scrollY;
|
double get scrollY => _scrollY;
|
||||||
|
|
||||||
@ -1289,6 +1294,7 @@ class CanvasModel with ChangeNotifier {
|
|||||||
if (refreshMousePos) {
|
if (refreshMousePos) {
|
||||||
parent.target?.inputModel.refreshMousePos();
|
parent.target?.inputModel.refreshMousePos();
|
||||||
}
|
}
|
||||||
|
updateScrollPercent();
|
||||||
}
|
}
|
||||||
|
|
||||||
updateScrollStyle() async {
|
updateScrollStyle() async {
|
||||||
@ -1424,6 +1430,22 @@ class CanvasModel with ChangeNotifier {
|
|||||||
_scale = 1.0;
|
_scale = 1.0;
|
||||||
if (notify) notifyListeners();
|
if (notify) notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateScrollPercent() {
|
||||||
|
final percentX = _horizontal.hasClients
|
||||||
|
? _horizontal.position.extentBefore /
|
||||||
|
(_horizontal.position.extentBefore +
|
||||||
|
_horizontal.position.extentInside +
|
||||||
|
_horizontal.position.extentAfter)
|
||||||
|
: 0.0;
|
||||||
|
final percentY = _vertical.hasClients
|
||||||
|
? _vertical.position.extentBefore /
|
||||||
|
(_vertical.position.extentBefore +
|
||||||
|
_vertical.position.extentInside +
|
||||||
|
_vertical.position.extentAfter)
|
||||||
|
: 0.0;
|
||||||
|
setScrollPercent(percentX, percentY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// data for cursor
|
// data for cursor
|
||||||
|
Loading…
x
Reference in New Issue
Block a user