Jump to content

Trying to make labeltext fit able.


IIYAMA

Recommended Posts

  • Moderators

Hey,

I am trying to make a label text fit able, but I am ending up at an infinity loop.

Anybody has a solution?

local maxLabelSizeTable = {40,40,40,40,40} 
local makeTextFitForGrid = function (element,index) 
    local text = guiGetText ( element ) 
    local size =  guiLabelGetTextExtent ( element ) 
    outputChatBox(size) 
    local maxSize = maxLabelSizeTable[index] 
    if size > maxSize then 
        repeat  
            guiSetText( element,string.sub(text,1,-2))  
            size =  guiLabelGetTextExtent ( element ) 
        until maxSize > size  
        local text = guiGetText ( element ) 
        guiSetText( element, text .. "..")  
    end 
     
end 

Link to comment

Because you have to update the variable "text" each time you change the gui text.

Try this:

local maxLabelSizeTable = {40,40,40,40,40} 
local makeTextFitForGrid = function (element,index) 
    local text 
    local size =  guiLabelGetTextExtent ( element ) 
    outputChatBox(size) 
    local maxSize = maxLabelSizeTable[index] 
    if size > maxSize then 
        repeat 
            text = guiGetText(element) 
            guiSetText( element,string.sub(text,1,-2)) 
            size =  guiLabelGetTextExtent ( element ) 
        until maxSize > size 
        text = guiGetText(element) 
        guiSetText( element, text .. "..") 
    end 
end 

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