Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I scale and position buttons depending on the canvas size of a ScrollingFrame?

Asked by 6 years ago
Edited 6 years ago

So I have an inventory GUI. When items are added the canvas size of the scrolling frame increases. Unforunately, when this happens it affects the size and position of the buttons.

I just need to know how I'd calculate the size and the position of the button so it looks like the same size and is spaced out the same no matter what the size of the canvas is.

This is what I've tried. I can't get the math right.

local getInventory = player.Inventory:GetChildren()
for i,Item in pairs(getInventory) do
    if Item.ClassName == "IntValue" then

        local button = Instance.new("TextButton",GUI.Inventory.InventoryList)
        button.Size = UDim2.new(0.925,0 (0.055/GUI.Inventory.InventoryList.CanvasSize.Y.Scale),0)
        button.Position = UDim2.new(0.025,0,(PositionUI + 0.015),0)
        PositionUI = PositionUI + 0.065/GUI.Inventory.InventoryList.CanvasSize.Y.Scale

    end
end 
PositionUI = 0
0
please indent your code, it makes things easier saSlol2436 716 — 6y
1
He did, but the website's lua code block doesn't allow the code to go off the screen, so they put it on the next line. rilgundam 65 — 6y
0
Take a look at UIGirdLayouts and UIListLayouts. They perform the maths for you with the tradeoff of taking some setup lukeb50 631 — 6y
0
Use offset. hiimgoodpack 2009 — 6y
0
Ah. Using offset worked, thanks. Jesse1240 59 — 6y

Answer this question