- Home /
How would I make a tool-tip sized to text? (4.6 GUI)
I want to make a mouseover tool-tip a la World of Warcraft for items. Problem is, I don't know how much text a description will be until runtime when I load objects and the player starts mousing over things!
For this to work, it'd need a background (image, panel, whatever) and the text that goes on top of it. Resizing and positioning said background would be a breeze, once I know the text width/height.
Is this possible with the text box created from Ui > Text? Some alternative?
Is the ScrollRect an option? http://unity3d.com/learn/tutorials/modules/beginner/ui/ui-scroll-rect
Answer by gfoot · Feb 24, 2015 at 03:04 AM
Apply a Content Size Fitter and a Horizontal Layout Group to the parent panel, and set the Content Size Fitter component's settings both to "Preferred Size". This makes it resize (with optional padding) to fit the preferred size of whatever its contents are. You can use Layout Element nodes on the contents as well to influence that target size, but usually you don't want to.
A question. I was going for the same approach, but i noticed that if i assign an image to the parent panel though, the tooltip doesn't resize anymore (it only works with the white image of "no source image") Any idea on how to solve that? Cheers!
Answer by siaran · Feb 24, 2015 at 12:17 AM
Why don't you use string.Length to get the number of characters in your text, then derive your box size from that?