Godot Version
v4.3.stable.official [77dcf97d8]
Question
When I put my cursor over items in my inventory, it looks like this:
The BBCode works, but there’s these gaps in the text, and the sizing has been super hard to properly scale dynamically. I want to get rid of those spaces and ensure it still works, so I can make my item tooltips pop (like if they’re rare or modified by the player in future).
My function for the tooltip is the following:
func _make_custom_tooltip(for_text: String) -> Control:
var label := RichTextLabel.new()
label.bbcode_enabled = true
label.fit_content = true
label.autowrap_mode = TextServer.AUTOWRAP_WORD
label.scroll_active = false
# Load and apply the custom bitmap font
var custom_font := preload("res://Fonts/Fontsheets/gameFontBorderless_4x.png")
label.add_theme_font_override("normal_font", custom_font)
# Set the tooltip text
label.text = "[left]" + for_text + "[/left]"
var plain_text = label.get_parsed_text()
var scale_factor = 2.0
label.custom_minimum_size.x = clamp(plain_text.length() * 7 * scale_factor + 5, 50, 150 * 6 * scale_factor)
label.custom_minimum_size.y = scale_factor * 15
label.scale = Vector2(scale_factor, scale_factor)
print("LABEL TEXT: ", label.text, "\nLABEL PARSED TEXT: ", plain_text)
return label
I am using a custom bitmap font.
This is the output:
LABEL TEXT: [left][color=hotpink]QuickTake[/color] handle[/left]
LABEL PARSED TEXT: QuickTake handle
And the for_text
being passed to it, in this case, is the following:
[color=hotpink]QuickTake[/color] handle
which is stored in a custom “item” .tres
file.