Horizontal scrolling frame with left and right buttons (how to manipulate scroll?)

for a horizontal scrolling frame having 2 selection buttons (left and right)… would i change manipulate the canvas position when player presses those buttons? or does someone have any other suggestions.

Yes you would change the CanvasPosition.

1 Like

okay, thought so. i’m thinking i could have an equation that takes the size of the frame and the size of elements inside of the frame (also somehow compensating for the padding…) to get accurate scroll. so you’re not scrolling and end up only seeing half of something. or do you know of a better option to accomplish this?

Are your ui elements positioned automatically by a ui layout (ie a UIListLayout, UIPageLayout…)?

If so you can just use the layout object’s AbsoluteContentSize property to get how much space they take up in the scrolling frame, then you would have to add the padding onto the AbsoluteContentSize to find out the canvas’s size in pixels.

If you aren’t using a ui layout, you can just use a simple bounding box algorithm to find out the bottom-right corner of the ScrollingFrames’ children which will be the same as the scrolling frame’s canvas’s contents (for each child convert the position to pixels and then add its AbsoluteSize to find the bottom right; if the x or y axis is bigger than the current biggest, overwrite the old biggest with the new biggest.

All in all it would look something like this:

local totalAbsoluteCanvasSize = Vector2.zero -- 0, 0

totalAbsoluteCanvasSize += uiLayout.AbsoluteContentSize -- again if not using a ui layout, do the bounding box method to find bottom right corner

local paddingTop = uiPadding.PaddingTop
totalAbsoluteCanvasSize += paddingTop.Scale * scrollingFrame.AbsoluteCanvasSize + paddingTop.Offset
-- continue for the other 3 padding properties

You can then subtract the AbsoluteSize (not absolute canvas size) from the respective axis (X or Y depending on which direction you want to allow scrolling), from what we defined earlier as the totalAbsoluteCanvasSize’s respective axis, this final number will be the maximum CanvasPosition before the scrollbar starts going out of bounds.

1 Like

i am using list layout so i will go with the first method thank you.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.