Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | TobiLa |
Hi, I am trying to create a NinePatchRect background for my TextLabel. Both of them should be centered on the screen
My problem is I can’t manage to make sure it’s always larger than my text.
My current approach is like this:
TreeStructure:
-
CenterContainer
-
NinePatchRect: Background
- Label: Text
Code:
export(String) var text setget set_text
func set_text(newText):
if has_node("Background/Text") and newText:
var textNode = get_node("Background/Text")
if textNode:
textNode.text = newText
call_deferred("_adaptLabelSize", textNode)
text = newText
func _adaptLabelSize(textNode):
var newminSize = textNode.rect_size.x + textNode.margin_left * 2
rect_min_size.x = newminSize
func _ready():
set_text(text)
My idea was to make the size of the background adapt each time the text gets changed. The problem is, that if I set textNode.text, the size of the textLabel isn’t changed when I use it to determine newMinSize, even if I call it deferred.
What can I do?