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.

in Engine by (311 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.

by (9,760 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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.