Skip to content

Commit 280265b

Browse files
Make Text Box wrap when it get's to big. (#780)
1 parent 6ef6134 commit 280265b

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

addons/dialogic/Editor/Events/Parts/Text/EventPart_TextEditor.gd

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extends "res://addons/dialogic/Editor/Events/Parts/EventPart.gd"
66
## node references
77
onready var text_editor = $TextEdit
88

9+
var timeline_area = null
910

1011
# used to connect the signals
1112
func _ready():
@@ -20,6 +21,10 @@ func _ready():
2021
text_editor.set('custom_colors/function_color', get_color("font_color", "Editor"))
2122
text_editor.set('custom_colors/member_variable_color', get_color("font_color", "Editor"))
2223
text_editor.set('custom_colors/symbol_color', get_color("font_color", "Editor"))
24+
25+
timeline_area = find_parent('TimelineArea')
26+
timeline_area.connect('resized', self, '_set_new_min_size')
27+
_set_new_min_size()
2328

2429

2530
# called by the event block
@@ -82,21 +87,31 @@ func _set_new_min_size():
8287
# Getting new sizes
8388
var extra_vertical = 1.1
8489

85-
if text_editor.get_line_count() > 1:
86-
extra_vertical = 1.22
87-
8890

8991

90-
text_editor.rect_min_size.y = get_font("normal_font").get_height() * ((text_editor.get_line_count() + 1) * extra_vertical)
9192

9293
# Getting the longest string and making that the width of the dialog bubble
94+
# also check how many lines wrap (and how often)
95+
var count_wrapped_lines = 0
9396
var longest_string = ''
9497
for l in text_editor.text.split('\n'):
9598
if l.length() > longest_string.length():
9699
longest_string = l
100+
if get_font("normal_font").get_string_size(l).x > get_max_x_size():
101+
count_wrapped_lines += get_font("normal_font").get_string_size(l).x/(get_max_x_size())
102+
103+
# set the height
104+
if text_editor.get_line_count() > 1:
105+
extra_vertical = 1.22
106+
text_editor.rect_min_size.y = get_font("normal_font").get_height() * ((text_editor.get_line_count() + 1 + count_wrapped_lines) * extra_vertical)
97107

108+
# set the width
98109
text_editor.rect_min_size.x = get_font("normal_font").get_string_size(longest_string).x + 50
110+
if text_editor.rect_min_size.x > get_max_x_size():
111+
text_editor.rect_min_size.x = get_max_x_size()
99112

113+
func get_max_x_size():
114+
return timeline_area.rect_size.x - (text_editor.rect_global_position.x - timeline_area.rect_global_position.x) - 50
100115

101116
func _on_TextEditor_focus_entered() -> void:
102117
if (Input.is_mouse_button_pressed(BUTTON_LEFT)):

addons/dialogic/Editor/Events/Parts/Text/TextEditor.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ custom_colors/number_color = Color( 0, 0, 0, 1 )
3737
custom_styles/focus = SubResource( 3 )
3838
custom_styles/normal = ExtResource( 2 )
3939
syntax_highlighting = true
40+
show_line_numbers = true
4041
smooth_scrolling = true
4142
wrap_enabled = true
4243

0 commit comments

Comments
 (0)