How do you autosize a button to the contained TextBlock

Hello,
I was wondering how you can set a button to the width and height of the button’s textblock.
I have used adaptWidthToChildren = true but that would basically create a fullscreen button.
Here is a playground:
https://playground.babylonjs.com/#XEQEVQ

Any ideas?

Thanks a lot.

I played a bit with your PG and came to the following solution:

https://playground.babylonjs.com/#XEQEVQ#1

I used

ctx.measureText()

method to do that, but have to say that I am really not that into HTML and webtech :sweat_smile: so you may tweak the code for your needs! :relaxed:

Can’t find any other way to do it via the Babylon.GUI yet…maybe it would be nice if our TextBlock-Class provides a matching property for this stuff (like GetMeasure or something like that, I have found a _currentMeasures field in the source but was too stupid to use it) :thinking:

1 Like

thank you.
haha, well webtech is not my favourite as well to say the least :slight_smile: