Search Unity

TextMesh Pro Wrap character instead of word

Discussion in 'UGUI & TextMesh Pro' started by Reeley, Aug 28, 2019.

  1. Reeley

    Reeley

    Joined:
    Feb 23, 2017
    Posts:
    45
    When wrapping TextMesh will never break up words. Is there a way to prevent this. So words will be break up when they have to wrap.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    When word wrapping is no longer possible, it should break up words.

    Do you have an example of some text I could try to reproduce this behavior?
     
  3. Reeley

    Reeley

    Joined:
    Feb 23, 2017
    Posts:
    45
    Sorry maybe my explanation is not the best here :/

    "When word wrapping is no longer possible, it should break up words." -> This does work correctly.

    What i want is that it breaks up words when there is enough space available. So that a line is always filled to the end.

    Take a look at this example:
    Im trying to achieve text 2 (it should break up the word demonstrate)
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The easiest way to achieve that is to use Soft Hyphenation and to inject similar to how it is done in the TMP Examples & Extras example scene called Soft Hyphenation.

    This would enable you to add Soft Hyphen to provide a hint at where it is valid to break up a word.
     
    Last edited: Aug 30, 2019
  5. Reeley

    Reeley

    Joined:
    Feb 23, 2017
    Posts:
    45
    if i understand correctly you have to insert "\u00AD" to show where it may break. Unfortunately my text is not predefined so i cant do that. Also i dont want a dash inserted and not use justified alignment.

    I guess there is no way to do this with TextMesh, although i think this is such a simple thing.
    Threre should be a option for this.
    Just fill the whole line with characters and wrap if no more character fits in the line.
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The Hyphen is the normal typographic way of handling breaking up words.

    Breaking up words when word wrapping is possible isn't supported in any application like Microsoft Word, Email and Texting apps. That is also because breaking words when you could word wrap is wrong and looks strange visually where I think most people would thing the text layout has a bug.

    Having said that, I am not opposed to figuring out some way to allow you to do this.

    Can you provide more insight on why you want this type of word wrapping?
     
  7. Reeley

    Reeley

    Joined:
    Feb 23, 2017
    Posts:
    45
    Basically im creating a little console. And i dont really care for correct hyphens. But i would like to fill all the available space, to have as much information shown as possible. Now this is not a dealbraker i can also just create a console with word breaking, but i have to say im a little bit surprised that such a simple thing is not possible with TextMesh.
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    It simply has never been requested by any user since the release of TMP back in 2014. I suspect this never came up again because it breaks text layout conventions.

    Like I said before, I am not opposed to looking into adding this type of functionality. This would likely be a new Overflow mode called Character Wrapping.

    P.S. Another user requested the opposite which is when Word Wrapping is no longer possible as a result of the width of the text container being too narrow, to never break up words and to have those words overflow. This would also be a new Overflow mode which I am not sure what to call yet. Overflow Mode = WordOverflow?
     
  9. Reeley

    Reeley

    Joined:
    Feb 23, 2017
    Posts:
    45
    Interesting that no one ever requested this.

    Adding those two as a new overflow mode seems like a good idea! I would love to see that.
     
  10. Android272

    Android272

    Joined:
    Oct 14, 2016
    Posts:
    22
    Thanks @Reeley for the "\u00AD" I did not know soft hyphens were a thing or that text mesh pro could auto hyphenate text this way. I am creating a interactive fiction game which is like reading a book, the one place it is acceptable to hyphenate words as it looks better for the page to be full of text as apposed to being justified like a word document.

    Now I need to figure out how to loop through all of my text and add these soft hyphens to words were applicable. Thanks for the tread.
     
  11. pjj_gpu

    pjj_gpu

    Joined:
    Dec 7, 2015
    Posts:
    3
    My app handles filenames. There is an option to show the file's path:
    e.g. "C:/Users/FirstName LastName/etc/etc/verylongetc/filename"
    'word wrap' breaks as
    "C:/Users/FirstName
    LastName/etc/etc/verylongetc/filename"

    I slightly prefer formatted
    "C:/Users/FirstName LastName/etc/etc/verylongetc
    /filename"

    or in the case of extremely long
    "C:/Users/FirstName LastName/etc/etc
    /extremelylongpath/filename"

    So I break it myself by inserting an '\n' before a '/'
    Don't know if it is too much of an edge case to allow the break character to be selectable - defaulting to ' ' space of course.
    Possibly with a 'none' option, where it would pack as many character on a line as possible before wrapping at max.
    Although the only other case I could think that might use that feature was displaying CSV data, wrapping at ',' ?
     
    alakoring likes this.
  12. tomtefar

    tomtefar

    Joined:
    Mar 19, 2015
    Posts:
    6
    Big thanks for the soft hyphenation thing! I have one issue though, when I use soft hyphenation the text prefers breaking on soft hypneation before breaking on spaces. Can this behaviour be altered in some way?

    E.g.

    The Meander\u00ADmire


    breaks into

    The Meander-
    mire


    but I want it to break into

    The
    Meandermire


    first and then

    The
    Meander-
    mire


    as the text box gets smaller and smaller.
     
  13. Alien1997

    Alien1997

    Joined:
    Jul 8, 2017
    Posts:
    3
    Hi, I use <space=0.3em><zwsp> tag to replace space. It's useful for me
    upload_2022-6-1_20-49-28.png
     
    Last edited: Jun 1, 2022
  14. Alien1997

    Alien1997

    Joined:
    Jul 8, 2017
    Posts:
    3
    Hi,breaking up words is more better for Chinese,example like this
    upload_2022-6-1_21-2-43.png
     
  15. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Please note that you can also use the <nobr> and </nobr> markup tags to further control text layout.
     
    breylinlee likes this.
  16. alakoring

    alakoring

    Joined:
    Mar 11, 2018
    Posts:
    27
    I’m also trying to show paths, and it would be really nice if it would break on / or \ characters.
     
  17. alakoring

    alakoring

    Joined:
    Mar 11, 2018
    Posts:
    27
    I ended up using ZWSP. This seems to be working on both Mac and Windows.

    Code (CSharp):
    1. // Now that we have a reasonable truncation, allow breaking after separators
    2. output = output.Replace(slash, slash + "\u200B");