How to Calculate CanvasPosition to Show a Specific Child in a ScrollingFrame?

Hey devs,
how would I calculate the offset of the canvasposition of a scrolling frame in order to make a specific child in that scrolling frame visible?
here is my current attempt:

  • doesn’t work
local CanvasPosition 
local Difficulty = "specificChildinScrollingFrameIwantToMakeVisible"
local index = Difficulty.LayoutOrder - 1 -- Zero-based index
local cellHeight = gridLayout.CellSize.Y.Scale * scrollingFrame.AbsoluteSize.Y
local paddingHeight = gridLayout.CellPadding.Y.Scale * scrollingFrame.AbsoluteSize.Y

local yOffset = index * (cellHeight + paddingHeight)
CanvasPosition = Vector2.new(0, yOffset)

any tips highly appreciated!

PS: my scrolling frame has an UIGridLayout, CellSize = {0.9, 0},{0.45, 0}, CellPadding = {0, 0},{0.04, 0}

i believe that AbsoluteCanvasSize should be used instead of AbsoluteSize.

other than that, my intelligence can’t find anything else to fix :sob:

1 Like

forgot about that. Still does not really work. In general, my approach seems not to work at all :confused:

Got it to work. I got the index of the child I want to show, took the actual pixel size of it and multiplied it by the index (added all the other children with the same size on top). works for every size, since the pixel size when changed is considered
(named every frame alphabetically and set layout order to names, script looks like this:)

local scrollingFrame = GameModeFrame.DifficultySelection.ScrollingFrame
local gridLayout = scrollingFrame:FindFirstChildWhichIsA("UIGridLayout")

local Difficulty = "thechildrenofthescrollingframeIwanttoshow!"
local frames = scrollingFrame:GetChildren()
local indexA = string.byte(Difficulty.Name) - string.byte("A")
yOffset = indexA * Difficulty.AbsoluteSize.Y
--GameModeFrame.DifficultySelection.ScrollingFrame.CanvasPosition = Vector2.new(0, yOffset)

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