Prevented AutoSizeLabel from using container dimensions directly, which previously caused distorted, non‑uniform scaling and failed when the reference text size was zero

This commit is contained in:
Adrien Ufferte
2025-08-14 15:37:53 +02:00
parent a5f38da8fc
commit 492cec8e1d
+5 -5
View File
@@ -1,12 +1,10 @@
@tool
extends Container
@export_multiline var ref_size_text: String = ""
var ref_size: Vector2
@onready var label: Label = $Label
func _notification(what: int) -> void:
if what == NOTIFICATION_SORT_CHILDREN:
_rescale()
@@ -20,6 +18,8 @@ func _ready() -> void:
func _rescale() -> void:
label.pivot_offset = label.size / 2
var min_size: float = minf(ref_size.x, ref_size.y)
label.scale = size / min_size
label.position = size / 2 - label.pivot_offset
if ref_size.x == 0 or ref_size.y == 0:
return
var scale_factor: float = minf(size.x / ref_size.x, size.y / ref_size.y)
label.scale = Vector2.ONE * scale_factor
label.position = size / 2 - label.pivot_offset * label.scale