• Setting panel height relative to text height when using panel:SetWrap(true)
    1 replies, posted
Hello! I have been trying to figure this out but I haven't found any solution to this. I am basically trying to set the panels height relative to the texts height ( the "text" (string) has multiple lines ). For example: "I have this text right here | 1 and here is line 2 | 2 and here line 3 | 3 and so on" | 4 Now lets say that the pixel height for 1 line is 10 pixels. What I am trying to do is to get the strings height ( with all lines ) so that I can set the panels height to the strings height ( so that you can actually read the text ). Now I am not using the line breaker "symbol" ( \n ) since I am using the panel:SetWrap() function. Or should I create my own wrap function which will count the lines or something? What I have tried: local info = vgui.Create( "DLabel", f ) info:SetWidth( fw/2 ) -- set the width so that the wrap function actually work -- some context: the width is relative to the players resolution info:SetText( "This is a very looooooooooooooooooooong text" ) info:SetWrap( true ) -- local txtw, txth = info:GetTextSize() -- this returns 0 for some reason print( txth ) -- prints 0 info:SetHeight( txth ) As said on the wiki, there is a bug with Panel/GetTextSize returning 0. And I checked out the github ticket and the issue was posted in 2016, 3 years ago. And the only reply was just a unrelated suggestion ( or am I a bad reader? ) but my point is that the bug isn't fixed and I don't think that it will be fixed soon. Or that I am doing something wrong, which is highly probable ( and that's why I am here ) I also tried this: local info = vgui.Create( "DLabel", f ) info:SetWidth( fw/2 ) info:SetText( "This is a very looooooooooooooooooooong text" ) info:SetWrap( true ) -- using surface.GetTextSize instead local txth = select( 2, surface.GetTextSize(info:GetText()) ) -- trying to get the text from the panel -- but I guess panel:GetText() doesn't count in the line breakers? info:SetHeight( txth ) Now surface/GetTextSize works, kind of. The issue is that Panel/GetText isn't including what Panel/SetWrap is doing. So it only returns the height of one line. Now you could multiply this by, for example 2. But the you would just be guessing how many lines there are. Is there any function or method I could use to get how many lines there are? Or is there maybe a fix for the panel:GetTextSize() method? Make my own wrapping function thing? How could I do this? Please help
Did you try DLabel/SetAutoStretchVertical?
Sorry, you need to Log In to post a reply to this thread.