#Can I make a Label/RichTextLabel get smaller instead of expanding/warping?
1 messages · Page 1 of 1 (latest)
I had this exact same problem and was very frustrated by it. As far as I can tell you can't solve this without coding the behaviour yourself.
I will post mine in a bit, sorry, got busy
@thin tartan here's my code for doing it
public partial class FancyLabel : RichTextLabel
{
private float MaxHeight;
private bool Initialized;
private void Initialize()
{
ScrollActive = false;
BbcodeEnabled = true;
MaxHeight = Size.Y;
FitContent = true;
MouseFilter = MouseFilterEnum.Ignore;
}
public void SetRichText(string text, bool centered = true)
{
if (false == Initialized)
{
Initialized = true;
Initialize();
}
if (centered)
{
text = text.RichWrap("center");
}
Text = text;
UpdateFontSize();
}
private void UpdateFontSize()
{
var fontSize = GetThemeFontSize(ThemeConstants.FontSize);
while (fontSize > 1)
{
if ( Size.Y <= MaxHeight )
{
break;
}
fontSize--;
SetFontSize(fontSize);
}
}
public void SetFontSize(int size)
{
AddThemeFontSizeOverride(ThemeConstants.FontSize, size);
}
and I just use the SetRichText() to set the text of the label, instad of just assigning it to the Text field
it's in c#, hopefully it's clear enough to be translated into gdscript easily