I have text element the initial height of which is 45. If the whole text does not fit in one line, then it creates a new line, this is what I need. but when I try to get a new height it stays 45. I need to get the height to change the image background behind the text to the size of this text element. How to get a new size of a text element after updating its content
Hi @Stishka,
Take a look at your ElementComponent and try checking the AutoFit options:
You should find that this will resize the text to the size of the element. You can adjust the minimum and maximum font sizes for the auto-fitting just below the line height setting:
I hope this is helpful
the last message has two lines but it still say me that it is 45 height. Well, how can i get number of created lines (with code)?
I found way to calculate it. I using .element.lines.length. Thanks
Try https://developer.playcanvas.com/en/api/pc.ElementComponent.html#calculatedHeight
What you may also find is that the height doesn’t change immediately after setting the text. This is because it does a ‘reflow’ once per frame in the Element System update.
So you need to wait a frame before getting the height. I can’t remember if you can get this in the postUpdate