Auto-height overflow – ShiVa Engine

Auto-height overflow

Here’s a handy little function which I have found useful when localising my HUDs; it can be painful when the text doesn’t quite fit and some of it disappears, so this function automatically tweaks the height of the text until it does fit. (Currently only for buttons, check boxes and labels, but easy to extend for other component types) – by psychicsoftware

--------------------------------------------------------------------------------
function MyMainAI.fixHudComponentTextOverflow ( sComp )
--------------------------------------------------------------------------------
    local hComp = hud.getComponent ( application.getCurrentUser ( ), sComp )
    if ( hComp ) then
        local kType = hud.getComponentType ( hComp )
        local nLines=0
        local nHgt=0
        local bChecking=true
        while ( bChecking ) do
            if ( kType==hud.kComponentTypeButton ) then
                nLines = hud.getButtonTextTotalLineCount ( hComp )
                nHgt = hud.getButtonTextHeight ( hComp )
            elseif ( kType==hud.kComponentTypeLabel ) then
                nLines = hud.getLabelTextTotalLineCount ( hComp )
                nHgt = hud.getLabelTextHeight ( hComp )
            elseif ( kType==hud.kComponentTypeCheck ) then
                nLines = hud.getCheckTextTotalLineCount ( hComp )
                nHgt = hud.getCheckTextHeight ( hComp )
            end
            if ( nLines*nHgt>100 ) then
                if ( kType==hud.kComponentTypeButton ) then
                    hud.setButtonTextHeight ( hComp, nHgt*0.95 )
                elseif ( kType==hud.kComponentTypeLabel ) then
                    hud.setLabelTextHeight ( hComp, nHgt*0.95 )
                elseif ( kType==hud.kComponentTypeCheck ) then
                    hud.setCheckTextHeight ( hComp, nHgt*0.95 )
                end
            else
                bChecking=false
            end
        end
    end
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------



Need more answers?

  • slackBanner