From 9ce65f7004804443fd94281b371349e83bf3dfdb Mon Sep 17 00:00:00 2001 From: Tiger Jove Date: Fri, 20 Mar 2026 15:58:00 +0100 Subject: [PATCH] feat: testing layout system fix --- .../chat_view/auto_size_rich_text.gd | 9 ----- .../auto_size_richt_text_container.gd | 33 +++++++++++++++++++ ... => auto_size_richt_text_container.gd.uid} | 0 src/logic-scenes/chat_view/chat-view.gd | 18 ++-------- src/logic-scenes/chat_view/chat-view.tscn | 21 ++++++------ 5 files changed, 46 insertions(+), 35 deletions(-) delete mode 100644 src/logic-scenes/chat_view/auto_size_rich_text.gd create mode 100644 src/logic-scenes/chat_view/auto_size_richt_text_container.gd rename src/logic-scenes/chat_view/{auto_size_rich_text.gd.uid => auto_size_richt_text_container.gd.uid} (100%) diff --git a/src/logic-scenes/chat_view/auto_size_rich_text.gd b/src/logic-scenes/chat_view/auto_size_rich_text.gd deleted file mode 100644 index 2a2e40cb..00000000 --- a/src/logic-scenes/chat_view/auto_size_rich_text.gd +++ /dev/null @@ -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 diff --git a/src/logic-scenes/chat_view/auto_size_richt_text_container.gd b/src/logic-scenes/chat_view/auto_size_richt_text_container.gd new file mode 100644 index 00000000..ee1cf4b7 --- /dev/null +++ b/src/logic-scenes/chat_view/auto_size_richt_text_container.gd @@ -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 diff --git a/src/logic-scenes/chat_view/auto_size_rich_text.gd.uid b/src/logic-scenes/chat_view/auto_size_richt_text_container.gd.uid similarity index 100% rename from src/logic-scenes/chat_view/auto_size_rich_text.gd.uid rename to src/logic-scenes/chat_view/auto_size_richt_text_container.gd.uid diff --git a/src/logic-scenes/chat_view/chat-view.gd b/src/logic-scenes/chat_view/chat-view.gd index e88132c1..cfac05ce 100644 --- a/src/logic-scenes/chat_view/chat-view.gd +++ b/src/logic-scenes/chat_view/chat-view.gd @@ -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 diff --git a/src/logic-scenes/chat_view/chat-view.tscn b/src/logic-scenes/chat_view/chat-view.tscn index 09d1e2df..a3c424ca 100644 --- a/src/logic-scenes/chat_view/chat-view.tscn +++ b/src/logic-scenes/chat_view/chat-view.tscn @@ -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]