Question

I would like to know the line number in EditField while I am typing some text in this component.

Was it helpful?

Solution

  1. Get the width of the edit field. (int returned) (e.g. 320 px)

  2. Get the font width of your current text. Font class have getAdvance() method that accepts the string parameter (int returned) (e.g. 650 px)

  3. if string width > edit field width you can divide string width and edit width and on the other step get the modulo of it. (here you will get 2 as division and 10 will be yr modulo. That means you have filled two lines + in third line you are having characters that can be fit into 10 px.

I hope it will solve your problem, but be careful if you use any long words, the module had never been tested with long words but I fear about result's accuracy with long words.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top