How to auto-fit text in Godot without expanding the UI layout?

I’m using Godot 4.7 and want Label/Button text to automatically shrink within a fixed area, then grow back when space allows. It should work both in the editor and at runtime.

I made an @tool child component that measures text and adjusts the font size within a minimum/maximum range. However, long text still appears to expand the container layout.

My structure is:

HBoxContainer
└── PanelContainer
    └── Label
        └── TextAutoFit

I suspect the text increases the Label’s minimum size before my component measures Label.size, so it uses an already-expanded area.

How can I keep the layout size independent of text and reliably auto-fit the font? Is there an established approach or plugin that supports editor previews, runtime updates, and localization?

I need the full text visible, so clipping or ellipsis alone won’t meet the requirement.

I would recommend this addon:

Autosize Label - Godot Asset Store.

4.8 will add such a property as auto_font_size