Skip to content

Commit 9b5a232

Browse files
authored
Merge pull request #634 from MyreMylar/fix-crash-when-scrolling-placeholder-text
Crash Fix - focusing text box adds/removes scrollbar
2 parents c25d04e + 13c0739 commit 9b5a232

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

pygame_gui/elements/ui_text_box.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,8 @@ def unfocus(self):
14831483
"""
14841484
super().unfocus()
14851485
if self.placeholder_text is not None:
1486-
self.rebuild()
1486+
self.should_trigger_full_rebuild = True
1487+
self.full_rebuild_countdown = 0.0
14871488

14881489
def focus(self):
14891490
"""
@@ -1492,7 +1493,8 @@ def focus(self):
14921493
super().focus()
14931494
self.cursor_has_moved_recently = True
14941495
if self.placeholder_text is not None:
1495-
self.rebuild()
1496+
self.should_trigger_full_rebuild = True
1497+
self.full_rebuild_countdown = 0.0
14961498

14971499
def _process_edit_pos_move_key(self, event: Event) -> bool:
14981500
"""

pygame_gui/elements/ui_text_entry_box.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def __init__(self,
7777

7878
self.cursor_on = False
7979

80+
self.should_redraw_from_text_block = False
81+
8082
def get_text(self) -> str:
8183
"""
8284
Gets the text in the entry box element.
@@ -100,7 +102,7 @@ def unfocus(self):
100102
self.cursor_on = False
101103
self.text_box_layout.turn_off_cursor()
102104
self.cursor_has_moved_recently = False
103-
self.redraw_from_text_block()
105+
self.should_redraw_from_text_block = True
104106

105107
def focus(self):
106108
"""
@@ -147,6 +149,10 @@ def update(self, time_delta: float):
147149
else:
148150
self.cursor_blink_delay_after_moving_acc += time_delta
149151

152+
if self.should_redraw_from_text_block:
153+
self.should_redraw_from_text_block = False
154+
self.redraw_from_text_block()
155+
150156
def _handle_cursor_visibility(self):
151157
self.cursor_blink_delay_after_moving_acc = 0.0
152158
self.cursor_on = True

tests/test_elements/test_ui_text_entry_box.py

+2
Original file line numberDiff line numberDiff line change
@@ -1793,8 +1793,10 @@ def test_placeholder_text(self, _init_pygame, default_ui_manager,
17931793
assert text_box.text_box_layout.plain_text == "Enter text here..."
17941794

17951795
text_box.focus()
1796+
text_box.update(0.1)
17961797
assert text_box.text_box_layout.plain_text == ""
17971798
text_box.unfocus()
1799+
text_box.update(0.1)
17981800
assert text_box.text_box_layout.plain_text == "Enter text here..."
17991801

18001802

0 commit comments

Comments
 (0)