Is it possible to add bbcode / images inside button text?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By wombatTurkey
:warning: Old Version Published before Godot 3 was released.

Title pretty much says it all! :slight_smile: I was curious if this was possible. For example, parsing bbcode inside button text, or inside the draw_string method.

:bust_in_silhouette: Reply From: volzhs

Button control does draw text.
If you want to show bbcode inside button,
you can do this way.

make a Button has RichTextLabel

- Button
    - RichTextLabel

override set_text of Button

extends Button

func _ready():
	set_text("[u]asdf[/u] [img]res://icon.png[/img]")

func set_text(text):
	get_node("RichTextLabel").set_bbcode(text)

This works only with script, not work with Text field on inspector of Button.

Thanks! I added get_node("RichTextLabel").set_use_bbcode(true) as well.

Hmm, this does work! I thought the text was going to scale with the button though, but it creates a scrollbar. I guess I have to set the position dynamically based upon text size? If so, this still works fine, thank you @volzhs!

Edit: Hmm, I wonder if I can set the childs with/height to match the parents

wombatTurkey | 2016-05-20 21:06

Looks like this works for the scaling issue, awesome :smiley:

get_node("RichTextLabel").set_size(Vector2(get_size().width, get_size().height))

wombatTurkey | 2016-05-20 21:09

You can solve size issue by setting anchors and margins.
see this http://docs.godotengine.org/en/latest/tutorials/2d/size_and_anchors.html

volzhs | 2016-05-21 04:34