Skip to content

Commit 1ecf27f

Browse files
committed
FixedSizeLabel: Resize container to label
This is a workaround for an upstream bug: godotengine/godot#100626 Connect the label size changed signal to a handler, that calls reset_size() in the PanelContainer Also, change the minimum size of the PanelContainer to the current size, and shrink center both the MarginContainer and the Label nodes. The offsets in the diff have changed automatically because of this. Fixes #608
1 parent 01c9cb4 commit 1ecf27f

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

scenes/game_elements/props/fixed_size_label/components/fixed_size_label.gd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,10 @@ func _exit_tree() -> void:
5858

5959
if label_container:
6060
label_container.queue_free()
61+
62+
63+
func _on_label_resized() -> void:
64+
if not is_node_ready():
65+
return
66+
# TODO: Workaround for https://github.com/godotengine/godot/issues/100626
67+
label_container.reset_size()

scenes/game_elements/props/fixed_size_label/fixed_size_label.tscn

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ label_text = "Talk"
1414
[node name="LabelContainer" type="PanelContainer" parent="."]
1515
unique_name_in_owner = true
1616
texture_filter = 2
17-
layout_mode = 2
18-
offset_left = -50.0
19-
offset_top = -32.5
20-
offset_right = 50.0
21-
offset_bottom = 32.5
22-
grow_horizontal = 2
23-
grow_vertical = 2
17+
custom_minimum_size = Vector2(68, 46)
18+
layout_mode = 0
19+
offset_left = -34.0
20+
offset_top = -23.0
21+
offset_right = 34.0
22+
offset_bottom = 23.0
2423
size_flags_horizontal = 4
2524
size_flags_vertical = 4
2625
theme = ExtResource("1_ah0mj")
2726
theme_type_variation = &"FixedSizeLabelContainer"
2827

2928
[node name="MarginContainer" type="MarginContainer" parent="LabelContainer"]
3029
layout_mode = 2
30+
size_flags_horizontal = 4
31+
size_flags_vertical = 4
3132
theme_override_constants/margin_left = 10
3233
theme_override_constants/margin_top = 5
3334
theme_override_constants/margin_right = 10
@@ -36,8 +37,10 @@ theme_override_constants/margin_bottom = 5
3637
[node name="Label" type="Label" parent="LabelContainer/MarginContainer"]
3738
unique_name_in_owner = true
3839
layout_mode = 2
39-
size_flags_vertical = 1
40+
size_flags_horizontal = 4
4041
theme_type_variation = &"FixedSizeLabel"
4142
text = "Talk"
4243
horizontal_alignment = 1
4344
vertical_alignment = 1
45+
46+
[connection signal="resized" from="LabelContainer/MarginContainer/Label" to="." method="_on_label_resized"]

0 commit comments

Comments
 (0)