Search Unity

Is it possible to wrap text around an image?

Discussion in 'UGUI & TextMesh Pro' started by emrys90, Nov 30, 2020.

  1. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    755
    So I have a rectangular area that I would like to put text in, but each corner of the rectangle has an image where I would like text to flow around it. So basically I am looking for a way for the text to get narrower at the top/bottom than it is in the middle. Is something like this possible?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Support for text flowing around images / shapes is not currently available. This is something that I have been wanting to support for a while but simply haven't had time to implement.

    In the meantime, you should be able to use the Linked text mode to achieve the results you seek. See example "16 - Linked text overflow mode example" included in the TMP Examples and Extras.

    For the use case you describe, you would use 3 text objects that are linked using Overflow Linked mode. The source text would be set on the first top text object and would flow into the other two text objects as seen in the image below.

    upload_2020-11-30_14-28-10.png
     
    ujz likes this.
  3. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    755
    Thanks for the reply! I had tried doing that, but it doesn't seem to work well with centering text and auto sizing. It seems to only center within the first text object and will auto size within there, and only once it can no longer do that would it flow over to the others.

    What I would like to have happen is that it stays centered in the middle text object when it is not overflowing and auto sizes to be an appropriate size between the 3 areas of text.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Auto size will definitely be an issue as it only considers the first text object / bounds.

    In terms of text alignment, you have to set it on each linked text objects but otherwise it should work as expected.
     
  5. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    755
    Any suggestions on how to go about handling auto sizing for it? It's an important case for us as its a VR game, so we need the text to typically be as large as possible, but with the ability to get smaller for longer pieces of text.
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Until I can get around to making Auto Size work with Linked text mode, you might be able to implement your own solution which is to manually set the text size on all linked text objects to the max point size and then checking if the "isTextTruncated" property. If it is use a binary search to test a new smaller point size and keep going until you find the optimum point size.

    This is essentially how auto size works for a single text object.
     
  7. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    755
    Okay thanks!
     
  8. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    755
    So I setup 3 vertical text boxes with vertical center alignment
    upload_2020-11-30_17-25-36.png

    It's not working as I expect though. I would like it to be in the center one as that would be the overall center, but its in the top one until it overflows. Am I missing something?
     
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Oh! Centered vertically ... That is definitely not working as expected. I need to think about this one.
     
  10. emrys90

    emrys90

    Joined:
    Oct 14, 2013
    Posts:
    755
    @Stephan_B
    upload_2020-12-7_17-53-41.png

    In some cases, depending on the auto scaled font size, there ends up with a gap between the linked text objects. Any ideas how I could work around this? I'm starting to think that I really need a way for it to auto flow around the two bottom corners as the linked objects doesn't fully fit my needs. Is there a way I could wind up doing that? If so, could you point me in the direction of how to accomplish that?
     
  11. Phaaze1

    Phaaze1

    Joined:
    Jun 26, 2013
    Posts:
    15
    Any update on making text flow properly using middle vertical alignment? I'm having the same issue where I need text to flow around an image but would like it centered vertically. There is currently no way to get a consistent line spacing between the 2 linked textboxes.
     
  12. igoraleftinovich

    igoraleftinovich

    Joined:
    Feb 11, 2017
    Posts:
    17
    Is it possible to use a linked text overflow mode in UI Elements or may be there is another way to wrap text around shapes in UI Elements?