feat: testing layout system fix

This commit is contained in:
tiger tiger tiger 2026-03-20 15:58:00 +01:00
parent 65dfda2a8e
commit 9ce65f7004
5 changed files with 46 additions and 35 deletions

View File

@ -1,9 +0,0 @@
@tool
class_name AutoSizeRichTextLabel
extends RichTextLabel
func _process(_delta: float) -> void:
if get_combined_minimum_size().y <= get_minimum_size().y:
autowrap_mode = TextServer.AUTOWRAP_OFF
else:
autowrap_mode = TextServer.AUTOWRAP_WORD_SMART

View File

@ -0,0 +1,33 @@
## chat_bubble.gd — attach to your bubble container (e.g. PanelContainer)
@tool
extends Container
@export var max_bubble_width: float = 512.0
@onready var label: RichTextLabel = $RichTextLabel
func _ready():
set_text(label.text)
func set_text(text: String) -> void:
label.text = text
# 1. Disable wrap, measure natural width
label.autowrap_mode = TextServer.AUTOWRAP_OFF
label.fit_content = true
label.custom_minimum_size.x = 0
# Force layout so get_content_width() is valid
label.queue_redraw()
await get_tree().process_frame
var natural_width := label.get_content_width()
if natural_width <= max_bubble_width:
# Short text = natural size
label.custom_minimum_size.x = 0
else:
# Long text — clamp and wrap
label.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
label.custom_minimum_size.x = max_bubble_width
label.size.x = max_bubble_width

View File

@ -10,21 +10,7 @@ func _ready() -> void:
rebuild()
func rebuild():
for child in v_box.get_children():
child.free()
var text_server: = TextServerManager.get_primary_interface()
#var text_server: = TextServerManager.get_primary_interface()
for message in messages:
var shaped_tex: RID = text_server.create_shaped_text(TextServer.DIRECTION_AUTO, TextServer.ORIENTATION_HORIZONTAL)
text_server.shaped_text_add_string(shaped_tex, message.text, [theme.default_font.get_rid()], theme.default_base_scale)
text_server.shaped_text_fit_to_width(shaped_tex, size.x)
var label: = RichTextLabel.new()
label.custom_minimum_size = text_server.shaped_text_get_size(shaped_tex) + Vector2( 16, 16 )
label.text = message.text
label.size_flags_horizontal = Control.SIZE_SHRINK_END if message.is_own_message else Control.SIZE_SHRINK_BEGIN
v_box.add_child(label)
pass

View File

@ -11,7 +11,7 @@
[ext_resource type="StyleBox" uid="uid://dj1fuvcy0sw7k" path="res://logic-scenes/chat_view/style-chat-bubble.tres" id="9_vvup7"]
[ext_resource type="LabelSettings" uid="uid://mh8uu4rlqmv5" path="res://logic-scenes/chat_view/label-timestamp.tres" id="9_xckgu"]
[ext_resource type="StyleBox" uid="uid://dd4xc216ul21m" path="res://logic-scenes/chat_view/style-chat-bubble-self.tres" id="11_qbcw0"]
[ext_resource type="Script" uid="uid://dlbwvie007wfx" path="res://logic-scenes/chat_view/auto_size_rich_text.gd" id="12_qgt32"]
[ext_resource type="Script" uid="uid://dlbwvie007wfx" path="res://logic-scenes/chat_view/auto_size_richt_text_container.gd" id="12_qgt32"]
[sub_resource type="Resource" id="Resource_iwd5k"]
script = ExtResource("5_xckgu")
@ -123,13 +123,14 @@ theme_override_constants/margin_left = 5
theme_override_constants/margin_top = 5
theme_override_constants/margin_right = 5
theme_override_constants/margin_bottom = 5
script = ExtResource("12_qgt32")
[node name="Panel" type="Panel" parent="AppLayout/ChatContainer/VBoxContainer/Message-Other/VBoxContainer/MarginContainer" unique_id=2013893702]
layout_mode = 2
theme_override_styles/panel = ExtResource("9_vvup7")
[node name="RichTextLabel" type="RichTextLabel" parent="AppLayout/ChatContainer/VBoxContainer/Message-Other/VBoxContainer/MarginContainer" unique_id=1968975325]
custom_minimum_size = Vector2(500, 0)
[node name="RichTextLabel" type="RichTextLabel" parent="AppLayout/ChatContainer/VBoxContainer/Message-Other/VBoxContainer/MarginContainer" unique_id=2013097116]
custom_minimum_size = Vector2(512, 0)
layout_mode = 2
size_flags_horizontal = 3
theme_type_variation = &"message-other"
@ -144,7 +145,6 @@ fit_content = true
scroll_active = false
vertical_alignment = 1
justification_flags = 3
script = ExtResource("12_qgt32")
metadata/_custom_type_script = "uid://dlbwvie007wfx"
[node name="TimeStamp" type="Label" parent="AppLayout/ChatContainer/VBoxContainer/Message-Other/VBoxContainer" unique_id=1782456747]
@ -184,9 +184,9 @@ theme_override_constants/margin_left = 5
theme_override_constants/margin_top = 5
theme_override_constants/margin_right = 5
theme_override_constants/margin_bottom = 5
script = ExtResource("12_qgt32")
[node name="RichTextLabel" type="RichTextLabel" parent="AppLayout/ChatContainer/VBoxContainer/Message-Self/VBoxContainer/Bubble/MarginContainer" unique_id=101911137]
custom_minimum_size = Vector2(500, 0)
[node name="RichTextLabel" type="RichTextLabel" parent="AppLayout/ChatContainer/VBoxContainer/Message-Self/VBoxContainer/Bubble/MarginContainer" unique_id=1320329524]
layout_mode = 2
size_flags_horizontal = 3
theme_type_variation = &"message-other"
@ -197,9 +197,9 @@ ob der Bums irgendwann umbricht.
"
fit_content = true
scroll_active = false
autowrap_mode = 0
vertical_alignment = 1
justification_flags = 99
script = ExtResource("12_qgt32")
metadata/_custom_type_script = "uid://dlbwvie007wfx"
[node name="TimeStamp" type="Label" parent="AppLayout/ChatContainer/VBoxContainer/Message-Self/VBoxContainer" unique_id=433463928]
@ -242,19 +242,20 @@ theme_override_constants/margin_left = 5
theme_override_constants/margin_top = 5
theme_override_constants/margin_right = 5
theme_override_constants/margin_bottom = 5
script = ExtResource("12_qgt32")
[node name="RichTextLabel" type="RichTextLabel" parent="AppLayout/ChatContainer/VBoxContainer/Message-Self-Short/VBoxContainer/Bubble/MarginContainer" unique_id=1089345802]
[node name="RichTextLabel" type="RichTextLabel" parent="AppLayout/ChatContainer/VBoxContainer/Message-Self-Short/VBoxContainer/Bubble/MarginContainer" unique_id=425927748]
layout_mode = 2
size_flags_horizontal = 3
theme_type_variation = &"message-other"
bbcode_enabled = true
text = "Kasse Dich Furz!
"
Mein li
32"
fit_content = true
scroll_active = false
autowrap_mode = 0
vertical_alignment = 1
script = ExtResource("12_qgt32")
metadata/_custom_type_script = "uid://dlbwvie007wfx"
[node name="TimeStamp" type="Label" parent="AppLayout/ChatContainer/VBoxContainer/Message-Self-Short/VBoxContainer" unique_id=1787589161]