Get pixel size of font characters? (SOLVED)

Is there a function for measuring text before it is set to a label or GUI text node? It would be useful for me, as I am currently having trouble getting exact measurements for variable button sizes, menu sizes, and such. I wish to calculate for the amount of text given, and fit the size of my node to that after calculating for linebreaks and etc.

Currently I’ve accomplished this by trial and error. I know there is gui.get_text_metrics, but this sounds like a workaround for what I’m trying to accomplish.

I don’t know why you think gui.get_text_metrics is a workaround, that’s exactly what it’s for: getting the size of text. There’s also gui.get_text_metrics_from_node, you only give it the text node and it gives you the metrics. You shouldn’t have to calculate anything yourself, just use width and height from the metrics to set your button sizes (with some padding added presumably).

1 Like

I just reread the API. Thanks. I think I confused get_text_metrics_from_node with get_text_metrics.

1 Like