@tool extends PanelContainer
func _ready():
var label: Label = $Label
label.set_text("Some long text to fill the space and see some results...")
label.custom_minimum_size.x = 100
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
size.x = 200
size.y = 0 # this line doesn't work as expected
What I want:
I know it may be an expected behaviour, but in my case I just can’t make it work the right way. Even so manually resizing (in the editor) works fine.
I tried using different anchors and content alignments but nothing helped…
@tool
extends PanelContainer
@onready var label: Label = $Label
func _ready() -> void:
# set the label minimum width to 200px
label.custom_minimum_size.x = 200
# set autowrap
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
# set the size flags to begin to avoid the label being positioned incorrectly when changing the size
label.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN
label.size_flags_vertical = Control.SIZE_SHRINK_BEGIN
# When the label gets resized, change the size of this panel container to the minimum size of the label
label.resized.connect(func():
size = label.get_minimum_size()
)