I have a Label object which may contain longer or shorter pieces of text. I would like to shrink the font size of this label until it fits within its bounds (i.e. until Label#isElided returns false). Is there a good way to accomplish this? The stupid way to solve this problem would be to just keep shrinking the font in a loop and waiting for OnGeometryChanged to check the result, but that would take many frames to converge on the correct font size.
There’s also a MeasureTextSize method which returns the amount of space needed for text, but there’s not really an obvious mapping between this and a target font size.
Hi @dthurn ! FYI, we plan to add built-in support for “Auto-Size” in the future. It’s also briefly discussed in this thread .
In the meantime, it will be a bit hacky, but it’s something you could implement yourself using a mix of OnGeometryChangedEvent and MeasureTextSize. Once you detect the text no longer fits in the container, you could run a binary search using MeasureTextSize to find the new font size that fits the container.
This is a high-priority feature, and it’s been frequently requested by users. Unfortunately, as much as I would like to implement it shortly, I can’t commit to a specific date.