#Trying to make auto-scaling???

1 messages · Page 1 of 1 (latest)

wicked echo
#

is this referring to text?

#

or just other gui objects in general

#

because if you're wanting text I can share how I did it

#

to keep text size consistant

#

for my backpack items

#

I found a good resource on studio but i don't think i have the link for it

#

anymore

#

@azure tendon

#

these are the two functions i found on dev forum

#
local function getSmallestSizeFactor(containerAuto) -- case of wanting to compute from the automatically calculated TextBounds
    -- get the maximum size factor of text that can fit in the label for all labels

    local minYFactor

    for _, container in containerAuto:GetChildren() do
        if not container:IsA('TextBox') then
            continue
        end

        local isDoneCalculatingTextBounds = container.TextBounds ~= Vector2.zero

        if not isDoneCalculatingTextBounds then
            container:GetPropertyChangedSignal('TextBounds'):Wait()
        end

        local yAxisFactor = container.TextBounds.Y / container.AbsoluteSize.Y -- should give us a float between 0 and 1 which is the % height of the text in the label
        print(yAxisFactor)
        if not minYFactor or yAxisFactor < minYFactor then
            minYFactor = yAxisFactor
        end
    end

    return minYFactor
end

local function getSmallestSizeFactorManual(containerManual) -- case of wanting to find the size manually
    local minYFactor

    for key, child in containerManual:GetChildren() do
        if not child:IsA('TextBox') then
            continue
        end

        textSizeParams.Width = 0 -- 0 for no wrapping
        textSizeParams.Font = child.FontFace
        textSizeParams.Size = child.AbsoluteSize.Y
        textSizeParams.Text = child.Text

        local textBounds = TextService:GetTextBoundsAsync(textSizeParams)
        local aspectRatio = textBounds.X / textBounds.Y

        -- now we have to scale it down to fit within textLabel.AbsoluteSize.X

        local requiredSize = child.AbsoluteSize.X / textBounds.X

        -- now we can multiply textBounds by requiredSize and it /should/ give us a new text bounds that fits within `child`'s bounds

        local multipliedTextBounds = textBounds * requiredSize

        -- now for the Y factor

        local yAxisFactor = multipliedTextBounds.Y / child.AbsoluteSize.Y

        if not minYFactor or yAxisFactor < minYFactor then
            minYFactor = yAxisFactor
        end
    end

    return minYFactor
end
#

i can't find where they were though

#

and this is how i used it

#

to keep text size consistant

#
        local yFactor = getSmallestSizeFactor(move)

        for _, child in move:GetChildren() do
            if not child:IsA('TextBox') then
                continue
            end
            
            local function handleChildChanged()
                child.TextSize = ((math.floor(yFactor * child.AbsoluteSize.Y)) / getWordCount(move.Name))-1.15-- subtract 1 as safeguard. sometimes the last letter will get cut off by 1 pixel
                if child.TextSize < minTextSize.Value then
                    minTextSize.Value = child.TextSize
                    child.TextSize = minTextSize.Value
                else
                    child.TextSize = minTextSize.Value
                end
                prevSize = child.AbsoluteSize
            end
            
            local function sizeChanged()
                if not prevSize then
                    return
                end
                if prevSize.X < child.AbsoluteSize.X or prevSize.Y < child.AbsoluteSize.Y then
                    minTextSize.Value = 10000000000
                else
                    handleChildChanged()
                end
                prevSize = child.AbsoluteSize
            end
            workspace.CurrentCamera:GetPropertyChangedSignal("ViewportSize"):Connect(function()
                minTextSize.Value = 10000000
            end)
            minTextSize.Changed:Connect(handleChildChanged)
            child.TextScaled = false
            child:GetPropertyChangedSignal('AbsoluteSize'):Connect(sizeChanged)
            handleChildChanged()
        end
#

u could maybe do something similar with ur design idk

azure tendon
#

I managed to get it working

wicked echo
#

nice

azure tendon
#

I forgot to make it actually relative

wicked echo
#

💀