I’m just looking into the possibility of doing some “even” line breaking, to try and get eg. 2 lines of center-aligned text to be word wrapped such that each line would be of similar length, rather than the second line just having a few orphaned words. eg
This is some center aligned text that I want broken into two
lines more evenly.
This is some center aligned text that I want
broken into two lines more evenly.
I was using line spacing N and paragraph spacing M to add extra spacing between “paragraphs”, but can’t seem to find a way to insert a line break, instead of a paragraph break. \n seems to insert a paragraph break, and
seems to also insert a paragraph break.
I’m wondering if there’s any tag/character that will tell TMP to just break a line as if it’d word wrapped, with the per-line spacing, instead of inserting the full paragraph spacing.
If not, a workaround could be to pre-parse the text and double even \n, and just live with “paragraph spacing” being a blank line?
(or even better - does TMP have any hooks that could help with breaking lines more evenly?)
Thanks so much for the quick reply @Stephen_B! \v seems to work great.
Yeah I think I expected
to break the line without starting a new paragraph since that’s how HTML treats it, but not sure if that’s the universally expected behaviour (and I’d never heard of vertical tab!).
I’ve been looking through the .textInfo line infos and comparing lengths, but the character indexes within TextInfo all seem to all be based on the parsed text string, not the original text string, and I can’t seem to find a “source map” that could be used to go from final index to original index. Since our text often contains sprite tags etc. I’m not sure if it’d actually be possible to know where to insert a \v to force a break in the original text without knowing where in the original text the line info actually ended. Know this is a bit of an unsupported use case but did you happen to have any ideas on how to approach something like that?
The content of the textInfo gets populated when the text object is rendered. As such, if you need to change the text before it is rendered, you may have to use the ForceMeshUpdate() function to get the textInfo populated where you could then query its content to know how to modify the text to achieve your balanced layout.
The lineInfo contains the index of the first and last character of a given line. This index is the index of the character in the characterInfo.
The characterInfo contains a index to the given character in the source string along with stringLength which for instance would be 2 if the character was made up of surrogate pairs or longer when using the sprite tag.
With the above information, you should be able to navigate through the content of the textInfo to know exactly where to insert a potential \v to break the text.
Also keep in mind that all arrays contained in the textInfo are allocated in blocks where as such you cannot rely on the length of those arrays when iterating over their content. Instead use the textInfo.characterCount or similar properties.
Lastly and again, keep in mind that the textInfo gets updated / populated when the text gets processed or forced to update by using ForceMeshUpdate().