Label Font Auto Sizer - Godot 3
by lescandez
Godot Label Font Auto Sizer
A Godot tool that adds new Label/RichTextLabels nodes with autosizing capabilities; meaning, the text will try to fit inside the rect by making itself smaller.
Installation • How To Use • Localization • Support • License
Disclaimer: Text with different font sizes when not intended usually look bad, so I'd advise using this addon pretty much as a last resort. Before using this addon you should probably try adding more space for your text, using abbreviated words, or adding a scrol bar.
Installation
- If you're using Godot 4.0 or 4.1 read the last paragraph here. This addon works with Godot 4.2 onwards (or 3.5 onwards if you're on Godot 3).
- Download the latest release for your Godot engine version and drop the contents inside the root folder of your project or download and import the addon from the Asset Library.
- Go to
Project
->Project Settings
->Plugins
and enable LabelFontAutoSizer.
How to use
- Create an
AutoSize
Label
orRichTextLabel
: from theCreate New Node
menu directly. Just search forAutoSize
and you will find the new versions under the normalLabel
andRichTextLabel
nodes respectively (pick the one without the script file name in the parenthesis). - Set your font sizes. You can set a
min_size
andmax_size
. Doesn't matter what Theme (or Theme Overrides) or Label Settings you're using, the font size will be set by the max and min sizes. - You're set! Now the font will be resized every time it's necessary.
If you want to trigger a size check on a label at any given time, you can do so with my_label._check_line_count()
, although there shouldn’t be a reason for it.
If you're doing some testing/developing, if you are changing the text from withit one of the label classes themselves, do it like self.set_text(value)
or self.text = value
, othersise it doesn't trigger a size check. In a real scenario you wouldn't be changing the text from within the class itself though.
Usage differences in Godot 3
- The tool works pretty much the same. The one difference is that in Godot 3, if you don’t use any font other than the default one, you'll get an error message asking to use a
DynamicFont
, becauseBitMapFont
cannot be resized. After you set aDynamicFont
you can use the label normally and the text will resize correctly.
Localization
This was the reason I made the tool. Sometimes after translating text, you just can't make the rect any larger and some languages generally take more space than others (e.g. french), so this tool can help in those cases.
To help with those issues, assuming you already know how the localisation system works in Godot, I added a simple class that you can use after changing the locale of the game.
- After you change your locale, for example to Spanish, by using
TranslationServer.set_locale("es")
, you can callLabelFontAutoSizeManager.locale_chaged()
and this will trigger a size check on every active label.
This way it doesn’t matter wether you update the texts directly using my_label.text = tr(message)
or rely on the auto translation of the Label
node itself (only in Godot 4), you'll be covered.
Support
You wish to support me? Feel free to follow me on any of the public links on my profile!
License
Download
Support
If you need help or have questions about this plugin, please contact the author.
Contact Author