Search code examples
fontslibgdxwidthtextarealines

Libgdx gui TextArea, how set number of lines to enclose multiline text String?


TextArea seem to require me to set a fixed number of lines to show my text on. However, how can I know how many lines I should set, when my TextArea width is sized differently on different types of phones? A sensible TextArea component would incorporate a function that can automatically set the number of lines required due to the number of characters, the width of the TextArea and the size of the font used.

In short: How can I know the number of lines for my fixed-size String?


Solution

  • Use the Label object. From the docs:

    A text label, with optional word wrapping.

    Which sounds like what you need. Note that Label is part of the Scene2D framework.