Jump to content

[Custom]setImageSizeLabel


CapY

Recommended Posts

I have been breaking my head on this custom function.

The image doesn't fills desired text lenght properly, why is that ?

  
function setImageSizeLabel(image, label) 
   if not isElement(image) or not isElement(label) then return end 
   local w,h = guiLabelGetTextExtent(label)+2,guiLabelGetFontHeight(label)+2 
   guiSetSize(image, w, h, false) 
   guiSetSize(label, w, h, false) 
   guiLabelSetHorizontalAlign(label, "center") 
   guiLabelSetVericalAlign(label, "center") 
end 

Edited by Guest
Link to comment

Try this:

  
function setImageSizeLabel(image, label) 
    if not isElement(image) or not isElement(label) then  
        return false 
    end 
     
    local labelExtent, fontHeight = guiLabelGetTextExtent(label), guiLabelGetFontHeight(label) 
    local labelWidth, labelHeight = guiGetSize(label) 
    if labelExtent > labelWidth then 
        labelWidth = labelExtent 
    end 
    if fontHeight > labelHeight then 
        labelHeight = fontHeight 
    end 
     
    guiSetSize(image, labelWidth, labelHeight) 
    guiSetSize(image, labelWidth, labelHeight) 
    guiLabelSetHorizontalAlign(label, "center") 
    guiLabelSetVericalAlign(label, "center") 
end 
  

Link to comment
gui[6] = {} 
gui[6]["image"] = guiCreateStaticImage ( sw/2 - 240.5, top/2 ,windowWidth, windowHeight, "images/tutorial.png", false ) 
gui[6]["label"] = guiCreateLabel ( 8,3,460,88,"",false, gui[6]["image"] ) 
  
function setImageSizeLabel(image, label) 
    if not isElement(image) or not isElement(label) then 
        return false 
    end 
    
    local labelExtent, fontHeight = guiLabelGetTextExtent(label), guiLabelGetFontHeight(label) 
    local labelWidth, labelHeight = guiGetSize(label) 
    if labelExtent > labelWidth then 
        labelWidth = labelExtent 
    end 
    if fontHeight > labelHeight then 
        labelHeight = fontHeight 
    end 
    
    guiSetSize(image, labelWidth, labelHeight) 
    guiSetSize(image, labelWidth, labelHeight) 
    guiLabelSetHorizontalAlign(label, "center") 
    guiLabelSetVericalAlign(label, "center") 
end 
  
addEventHandler ( "onClientPlayerImageResize", player, function ( ) 
 for k, v in ipairs (gui) do 
    guiSetSize( v["image"], labelWidth, labelHeight) 
    end 
end 
) 
  
  
  
addEventHandler("onClientGuide", player, 
    function () 
            guiSetVisible ( gui[6]["image"], true ) 
             
            if (Animation.createAndPlay ( gui[6]["image"], Animation.presets.guiFadeIn ( 750  ) ) ) then 
                guiSetText ( gui[6]["label"], getTextFromID ( "text:general-intro" ).."\n            "..name ) 
                setImageSizeLabel(gui[6], gui[6]) 
                setTimer ( guiSetVisible, 750, 1, gui[6]["image"], true ) 
                setTimer( move, 5000, 1) 
                triggerEvent ( "onClientPlayerImageResize", player ) 
                showCursor ( false ) 
        end  
    end 
) 

Look's like a mess right now, still cannot get it working.

...and i have a feeling i'm not using it right.

Link to comment

Ignore post above.

My question is :

Why are you using

    guiSetSize(image, labelWidth, labelHeight) 
    guiSetSize(image, labelWidth, labelHeight) 

two times ?

EDIT : Nvm, getting it fixed.

EDIT2: I improved your code, now it works like a charm, thanks.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...