No auto-resize text option like in TMP for Unity

Godot Version

4.2.1

Question

I’ve been trying to implement a system similar to the auto-resize functionality which is present in TextMeshPro for Unity.

As far as I’m aware, it iterates the size of the text starting at a “max font size” var until the text either fits inside the boundaries of the textbox, or the “min font size” var is met.

I’m wondering why there isn’t an easy way to accomplish this in Godot? I’ve been trying all sorts of solutions but nothing I’ve found works to replicate this functionality. The major issue is that (as far as I’m aware) there’s no way to get the size of the text or to check if the text is clipped, having either of these would make it simple to create the functionality I need. The fact we have no way to access the clipped state of a label is honestly confusing since Godot obviously checks if the text is within the boundary of a label, but it doesn’t make those values public for us to use.

I feel like I must be missing something, but there are no solutions online and I already feel like I’m at a dead end after researching this and trying out solutions for a few days.

1 Like

yes there is a way, but it doesnt count the break line width
it basically will be a loop using while to compare the width size of the text that’s in the label and defined max width
so it will reduce the font size until the width size of the text is smaller or equal of defined max width

i dont have access to the auto resize text code right now, so i cant show it to you. will see tomorrow.
there’s someone who made it on godot 3 on a reddit post iirc, you will need to convert it to godot 4 to be usable.

if you want it to be able to resize to the longest text for break lines (\n) text, you will need to split the code with “\n” put it in an array and do check each text line who has the longest, then use that longest text line throw it into the main auto resize text function

1 Like

See discussion in this proposal:

There are some workarounds linked within.

1 Like

This question was asked before here Is there auto font size like in Unity

1 Like

@mrcdk script should do it just fine
but it doesnt handle multiple line break’s auto size well, since it still uses the total length of the whole text

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.