Text height change

I have a text component who’s text changes at runtime. When the number of lines in the text changes, is there a way to determine the render height of the text.

Is there an event raised when the text height changes?

I’d like to know the height, in order to set the height of the content in a scroll view, so the scrollbar scales appropriately or disappears.

There is no text height change event. The only way a text changes a height is if you change it manually. Then you can fire a related event, if needed.

Maybe it would be enough to just hide the scrollbar? There is a visibility setting for both bars:

Here’s a published project with two scrollable text boxes.
Convert Godot Sprite Sheet to Texture Packer - PLAYCANVAS

Save the following XML to a file.

<TextureAtlas imagePath="sheet.png">
	<SubTexture name="blue_button00.png" x="0" y="94" width="190" height="49"/>
	<SubTexture name="blue_button01.png" x="190" y="49" width="190" height="45"/>
	<SubTexture name="blue_button02.png" x="190" y="0" width="190" height="49"/>
	<SubTexture name="blue_button03.png" x="0" y="49" width="190" height="45"/>
	<SubTexture name="blue_button04.png" x="0" y="0" width="190" height="49"/>
	<SubTexture name="blue_button05.png" x="0" y="192" width="190" height="45"/>
	<SubTexture name="blue_button06.png" x="288" y="194" width="49" height="49"/>
	<SubTexture name="blue_button07.png" x="239" y="194" width="49" height="49"/>
	<SubTexture name="blue_button08.png" x="190" y="194" width="49" height="45"/>
	<SubTexture name="blue_button09.png" x="339" y="94" width="49" height="49"/>
	<SubTexture name="blue_button10.png" x="290" y="94" width="49" height="45"/>
	<SubTexture name="blue_button11.png" x="337" y="184" width="49" height="49"/>
	<SubTexture name="blue_button12.png" x="290" y="139" width="49" height="45"/>
	<SubTexture name="blue_button13.png" x="0" y="143" width="190" height="49"/>

Use Choose File button to select this file. Click Convert button to generate JSON.

Notice without knowing the render height of the JSON, the scroll bar is not set correctly and just defaults to the value set in the editor.

Is there a way to access the mesh or geometry of the text element? If yes, it should be possible to get a bounding box to calculate the size.

There is a lineHeight and fontSize on the element component.

Is it one text element per line? Or one element with everything? During the parse, you could calculate the number of lines in the resulting JSON, multiply it by the lineheight and update the contents height.

One element for everything. For now, I guess I’ll count the lines and do the calculation myself.

Is it possible to update the engine to expose the render height? It would be super helpful for this use case.

Hmm, well, text element has a calculatedHeight property, which is the final height of the text element, e.g. considering multiple lines. I can’t remember when it gets updated, but maybe it can be used in your case.

Nice! Looks like its updated after the frame is rendered. Its correct inside requestAnimationFrame. I’ll just go with that.