Search code examples
delphifiremonkeydelphi-10.2-tokyo

How can I get the position of TScrollBox in TLayout while panning?


I'm using a parent FMX.Layouts.TScrollBox to zoom and pan through a child TLayout. Once the TLayout gets bigger than the TScrollBox, panning is possible.

I'd like the (top left) position of the TScrollBox (image).

Looking through both TScrollBox & TLayout properties I cannot find a position that works for me (tried many). There's other ways to do it, but it seems standard to me and should(?) be included in the base class.

PS: For panning I use TScrollBox.AniCalculations but I don't think that matters/helps.


Solution

  • To read the position use the ViewportPosition property of the TScrollBox. It's a TPointF and is described as:

    Coordinates of the origin of the scrolling viewport specified as the offset from the origin of the content layout of this scroll box.

    It is documented here

    If you need an event during panning, use the OnViewportPositionChange() event of type TPositionChangeEvent() It is not properly documented but is declared as:

    TPositionChangeEvent = procedure (Sender: TObject;
                             const OldViewportPosition, NewViewportPosition: TPointF;
                             const ContentSizeChanged: Boolean) of object;
    

    Should be quite self explanatory

    alternatively OnHScrollChange() and/or OnVScrollChange() of type TNotifyEvent