0 votes

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

asked May 20, 2016 in Engine by wombatTurkey (298 points)

1 Answer

+1 vote

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):

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

answered May 20, 2016 by volzhs (9,489 points)

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

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

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

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.