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