Viewport Swipe Pagination


#1

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?


#2

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

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

#3

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);
}