-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ScaleUpdateDetails focalPointDelta #89
Comments
The most important design dicision on InteractiveViewer (and of course, PdfViewer) is It means that you can be notified when any zoom or scroll position change by subscribing(addListener/removeListener) the controller. The largest headache with the approach is that it's too difficult to obtain zoom/offset from the matrix. But PdfViewerController provides you with several helper methods that eases to get current zoom, center position, and so on. |
I've checked the InteractiveViewer's code (that is just forked version from the Flutter original), only the following lines handles pdfrx/lib/src/widgets/interactive_viewer.dart Lines 952 to 966 in c985b45
It seems that the value might be non-zero if the event is from |
Thanks for the reply. Yes, I also tried using matrix properties eg. X,Y, delta X, delta Y, but as you said it was not working as expected. I will try convert my position scaling algorithm to use centerPosition and reply with the result. Also thanks for the explanation with focalPointDelta. |
I am working on widgets scaling/ positioning on zooming using PdfViewerController properties (currentZoom, centerPosition). I added listener to controller, but on zooming it is called 2 times with the same currentZoom, but different centerPosition offset. Is it rule that for every zoom value, listener will be called 2 times for the same currentZoom value? To be honest it would be nice feature to add to listener parameters indicating whether it was zoomed or scrolled. |
Bascally, they're handled on a single matrix value using asynchronous animations. And I cannot tell when or how many times it is changed. And future versions may change the internal logic anyway. |
As u advised above I tried using PdfViewerController properties to scale widget above pdfViewer, but using centerPosition does not give results as expected and I do not know if I am doing anything wrong or is it not working correctly. I used onInteractionStart and onInteractionUpdate callbacks because they are called just one time with the same scale value. onInteractionStart: (details) {
pageController.onStartCenterPosition.value = pageController.pdfViewerController.centerPosition;
pageController.onStartZoomCombined.value = pageController.pdfViewerController.currentZoom;
}, On interaction callbacks are called not only on scale but on every user interaction, so at begginning of onInteractionUpdate I am checking if scale value changed regarding one set in onInteractionStart and if yes then I am starting to resize widget size and position. onInteractionUpdate: (details) {
final startZomm =
(pageController.onStartZoomCombined.value * 1000).round();
final updatedZoom =
(pageController.pdfViewerController.currentZoom * 1000).round();
if (startZomm == updatedZoom) {
return;
}
pageController.combinedScale.value =
pageController.pdfViewerController.currentZoom;
pageController.stampWidth.value =
pageController.baseStampWidth * pageController.combinedScale.value;
pageController.stampHeight.value =
pageController.baseStampHeight * pageController.combinedScale.value;
final deltaX = pageController.onStartCenterPosition.value.dx -
pageController.pdfViewerController.centerPosition.dx;
final deltaY = pageController.onStartCenterPosition.value.dy -
pageController.pdfViewerController.centerPosition.dy;
pageController.position.value = Offset(
pageController.basePosition.dx +
(deltaX * pageController.combinedScale.value),
pageController.basePosition.dy +
(deltaY * pageController.combinedScale.value),
);
}, After scale check I am setting new scaleValue and resizing widget regarding new scale and baseSize. After that I am trying to scale position counting deltaX, deltaY then multiplying it by scale and adding to start position. |
For example: OnInteractionStartPosX = 297.6 OnInteractionUpdatePosX = 317.3 then OnInteractionStartPosX = 302 OnInteractionUpdatePosX = 375.3 Calculated deltaX = 77.7 * 5 = 388,5 real pdfViewer deltaX = 543.1 For every zooming onInteractionCallbacs are called two times. First one with small zoom change and second one with target zoom. |
Sorry, I didn't understand what you want to achieve. Could you please explain what is your first motivation? |
I'm thinking... One possible option is PdfViewerParams.pageOverlaysBuilder, which directly places widgets on the page. But it may not be suitable for your situation. |
I am placing my rectangle in stack above pdfViewer and moving it is working correctly, the only thing that I have problem with is scalling its position on Zoom using controllers' CenterPosition to be exactly the same relatively to pdfViewer. Do you have any idea why? Above I tried step by step explain how I am trying to do it. |
OK, so we need to create some simple code to illustrate/check/test the current behavior. |
Do you want me to create that and share it? |
Please wait. I'm still thinking. PdfViewerParams.viewerOverlayBuilder is also implemented using Stack and the approach may be really straight forward. It realizes scroll thumb. It calculate the view position based on pdfrx/lib/src/widgets/pdf_viewer_scroll_thumb.dart Lines 54 to 60 in c5b6d77
|
I'm not sure what is the best approach for us. Furthermore, I don't know whether we already have the tool or not. |
I will think about your approach with scroll thumb and try to convert my algorithm this way, and get back to you. |
Using controller's visibleRect, the intended effect was achieved and scaling of the relative position in relation to the PDF when zooming works correctly. Thank you for the idea. Also I have one more question. I am trying to use PdfViewerParams - minScale and maxScale. Setting maxScale works correctly, but when I am trying to set minScale it does not effect viewer. PdfViewerController has its own value at minimum scale, equal to alternativeFitScale. Is it bug or am I using it wrongly? |
Ah, But do you have any reason to use minScale? If there's some reason to justify the existance of |
To be honest I have. When I load a document, it initially tries to occupy the entire available screen for example zooming it to 290% and I want this 2.9 to be my minimum scale. I mean i want to enable scaling but just for zooming in, not zooming out bigger than full screen. |
Do you want to disable |
Yes, I want to have the ability to disable alternativeFitScale in some cases. Also I want to be able to set minScale to some value and not allow to zoom out smaller than this value. In my case this value is zoom ratio of page to fit full width - maybe this value also can be useful for someone like alternativeFitScale. |
Is there any way to move pdfImage to top instead of centering it like in this example? |
For |
What about this? On above photo I am displaying a map pdf file of 3600 width and 1700 height. Is there any way to move map image it to top instead of center it? |
@espresso3389 What about that? #89 (comment) |
Currently, it's too difficult to place the PDF on the top of the view. It's kind of design tradeoff or such and if I introduce some new feature, it breaks the current consistency. I should think some better handling... |
For the centering issue, I opened a new issue #111. |
Hey, I am working with PdfViewer version 0.4.47. Over my pdfViewer I have custom positioned widget placed in stack that i want to scale on zoom (its size and position). I am using onInteractionUpdate callback, getting scale from ScaleUpdateDetails, multiplying its size with it works correctly but I also want to scale position and I assumed that focalPointDelta could be useful in that case - documentation says ( The amount the gesture's focal point has moved in the coordinate space of the event receiver since the previous update.) but its value is always 0 and I did not find any part in documentation which explains how to use it.
What should i do to use it?
Or is there any other way to scale position on zoom?
I would really appreciate any help.
The text was updated successfully, but these errors were encountered: