I have lines of text in my GUI that can potentially consist of several properties (colors, clickability, etc). I can get a line of text to look nice within certain limits, but I’m hitting an odd problem with the word-wrapping. It wraps inside each text component, but I only want to wrap it at the GUILayout Horizontal level. For example:
I would like the word-wrap to treat this all as a single line that can wrap:
Instead it does something like this:
If I turn wordwrap on at the level of each of these text elements, I get this result. If I turn it off and try to turn it on for the higher level elements (ie, a full horizontal line of text) it doesn’t wrap at all and just clips at the end of the available space.
Is there any way to control the wrapping like this?
Ok, with a bit of thinking and some messy coding, I managed to get it to work pretty nicely. I sadly had to abandon GUILayout to do it, but it works.
I basically implemented my own layout routines. I split the text wherever it should wordwrap (ie, spaces) and created a class with a list of GUI elements, one for each word. Each element can have its own color, font, etc. It needs a tiny bit of tweaking for positioning, but it seems to be pretty good already. It positions everything based on the element sizes (style.CalcSize) and would theoretically work with any sequence of GUI elements. Here’s a sample for ye.
Wide:
A bit smaller:
And squeeeeshed:
I’d still like to know if there’s an easier way to do this with GUILayout. If not, I’ll try to get the code cleaned up a bit and post it for anyone else that may need something similar.