Viewport Swipe Pagination

Trying to create a viewport (in android app) that swipes horizontally through a photo album. I want it to snap to each photo rather than stop halfway between photos. Tried viewPort.setSingleStepSizes(area.getWidth(),0); but didn’t work because it seems to only work with buttons.

Anything else I can try?

I don’t know the exact answer, but I would start by looking into

virtual void Viewport::visibleAreaChanged (const Rectangle< int > & newVisibleArea)	

Thanks I was able to write this function and it worked nicely.

void MyCustomViewPort::visibleAreaChanged (const Rectangle<int>& newVisibleArea)
{
    if(isCurrentlyScrollingOnDrag())
        return;

    Component * c = getViewedComponent();
    int width = c->getLocalBounds().getHeight(); // my components are square, so height = width
    int x = newVisibleArea.getX();
    int p = x % width;

    x += p >= width / 2 ? width-p : -p;

    setViewPosition (x, 0);
}
2 Likes