Is there any way to make Label text shrink on overrun?
Asked Answered
W

2

0

Coming from Unity, I was wondering if there was any equivalent (or way to achieve such) to the "Best Fit" option for Text Objects that I can apply to Label/RichTextLabel nodes? I've looked everywhere online, but as far as I can tell, it hasn't been fully brought up since this issue was closed for lacking a solution proposal.

Unfortunately I don't have a complete enough understanding of the engine to figure one out myself, so if you have any workarounds or know how to achieve this, I would be extremely grateful.

Wren answered 8/4, 2023 at 14:6 Comment(0)
C
0

In Godot 4, this can be implemented with a script: https://github.com/godotengine/godot-demo-projects/blob/0d02b2f90daf7eb14993e9008363402d75e023a0/3d/labels_and_texts/label_3d_layout.gd#L62-L68
(This is Label3D, but the same approach can be used with Label.)

In Godot 3.x, the same approach is possible but you must give the label its own font instance (so that you can change its size independently from others). The exact code will vary too.

Clabo answered 19/4, 2023 at 0:56 Comment(0)
W
0

Clabo Sorry I didn't reply sooner, I'm a bit confused as of how to implement this in my own project, or what any of it does. It seems to be a script for a health bar, and I can't find any references to Label3Ds that I could change to "Label" to reference the ones I want to apply this behaviour to in my project.

Thanks for your help, and apologies for my newbieness 😅

Edit: After downloading the project and testing it myself, I noticed that it relied on Label3D's font_size property, which a regular Label does not have. Also, I feel like there may be a mismatch between what your script and I am trying to achieve; my current UI layout resizes the text boxes, and I would like to resize the font size to match, whereas yours changes the text inside and resizes the font to fit the predefined boundaries. I am not planning on using the contents of a TextEdit in my script, so is there an alternative signal to listen to?

Wren answered 27/4, 2023 at 13:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.