Search Unity

TextMesh Pro TextMesh Pro - Paging suggestions

Discussion in 'UGUI & TextMesh Pro' started by Trisibo, Feb 6, 2019.

  1. Trisibo

    Trisibo

    Joined:
    Nov 1, 2010
    Posts:
    245
    For a game I'm working on, I have recently made a system to display long TMPro text as pages in a small box, like some sort of dialog. TMP's "Page" wrapping option is nice, but rather limited, since (correct me if I'm wrong) it only breaks after words, and we wanted the breaks to happen only at the end of sentences. I think it would be nice to extend TMP's paging algorithm to be a bit more flexible, these are some suggestions considering the things that I had to take into account for our particular needs, plus other on the fly ideas:

    • Be able to specify the characters on which breaks are allowed to happen. In our case, we used the dot to break on full sentences, taking care of breaking after several of them appear (e.g, after "...").
    • Add a tag (or some other means) to indicate that a break cannot occur at some position. For example, in our case there was text with dots that didn't indicate an end of sentence (like enumerations, "1.", "2.", ...); to avoid breaking on them, I just reused the "nobr" tag to not make the code more complex (though the editable text is a bit ugly...), since TMP just discards it ("1.<nobr></nobr>"), but something nicer would be... well, nicer.
    • In our case, there are some instances in which the text in a page may be too long to fit the container and no paging is possible (no end of sentence). My solution was to just enable TMP's autosize feature, so in those instances the text just shrinks. The problem with TMP's built-in paging is that autosizing happens first, so even when paging is possible at the largest size, the text still shrinks, so that would require a fix (maybe also an option to select whether the resizing goes first or last?).
    • Being able to specify the maximum number of lines for each page would also be nice.
    • Maybe a secondary set of characters where breaks can happen when a page has too much text? For example, text can break on ".", but if a page is too long and only has one sentence, it's allowed to break on ",".
    • Options to avoid widow and orphan lines would be amazing.
    • Sing me a lullaby every night, and bring me breakfast to bed every morning.
     
    polytropoi likes this.