TextBlock resize to fit fixed width

I’m trying to make little piece of code for auto-resize fontSize, until text with not fit textblock width, like this:

while (this.text_coins_value.lines[0].width > 70) {
this.coins_value.fontSize -= 2 // yes, some addition work with “px” here
}

How can i force update calculation of this.coins_value.lines[0].width inside this loop?
_markAsDirty() Is not working, update still happen in next render loop.
Sooo…any way to force redraw or force recalculate string with?

Hey and welcome!

I could perhaps expose a textBlock.measureText(text) API?

measureText exposed in canvas2D API. Not in TextBlock.
And doing this way is a more deep hack.
I want stay on babylon level.
Soo… how i can force update all calculation in TextBlock? Or maybe some basic Container api for this?

No I meant expose the way Textblock evaluate each line width. So after adding the API for you you could do:

do {
this.coins_value.fontSize -= 2 // yes, some addition work with “px” here

}
while (this.coins_value.measureText(this.text_coins_value.lines[0]) > 70) {