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

Hi @plastick,
I’m trying to implement the same behaviour and tried your custom view port.

I’m testing this with a mouse not a touch screen, my problem is that if I drag it and release when the mouse is not moving it doesn’t snap to the images. The problem I think is that the last visibleAreaChanged call is when the mouse moves so when you release without moving the mouse, it doesn’t run the callback.

Does my explanation make sense? Did you find this problem? any ideas on how to solve it?

thanks