Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash Fix - focusing text box adds/removes scrollbar #634

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pygame_gui/elements/ui_text_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,8 @@ def unfocus(self):
"""
super().unfocus()
if self.placeholder_text is not None:
self.rebuild()
self.should_trigger_full_rebuild = True
self.full_rebuild_countdown = 0.0

def focus(self):
"""
Expand All @@ -1492,7 +1493,8 @@ def focus(self):
super().focus()
self.cursor_has_moved_recently = True
if self.placeholder_text is not None:
self.rebuild()
self.should_trigger_full_rebuild = True
self.full_rebuild_countdown = 0.0

def _process_edit_pos_move_key(self, event: Event) -> bool:
"""
Expand Down
8 changes: 7 additions & 1 deletion pygame_gui/elements/ui_text_entry_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def __init__(self,

self.cursor_on = False

self.should_redraw_from_text_block = False

def get_text(self) -> str:
"""
Gets the text in the entry box element.
Expand All @@ -100,7 +102,7 @@ def unfocus(self):
self.cursor_on = False
self.text_box_layout.turn_off_cursor()
self.cursor_has_moved_recently = False
self.redraw_from_text_block()
self.should_redraw_from_text_block = True

def focus(self):
"""
Expand Down Expand Up @@ -147,6 +149,10 @@ def update(self, time_delta: float):
else:
self.cursor_blink_delay_after_moving_acc += time_delta

if self.should_redraw_from_text_block:
self.should_redraw_from_text_block = False
self.redraw_from_text_block()

def _handle_cursor_visibility(self):
self.cursor_blink_delay_after_moving_acc = 0.0
self.cursor_on = True
Expand Down
2 changes: 2 additions & 0 deletions tests/test_elements/test_ui_text_entry_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -1793,8 +1793,10 @@ def test_placeholder_text(self, _init_pygame, default_ui_manager,
assert text_box.text_box_layout.plain_text == "Enter text here..."

text_box.focus()
text_box.update(0.1)
assert text_box.text_box_layout.plain_text == ""
text_box.unfocus()
text_box.update(0.1)
assert text_box.text_box_layout.plain_text == "Enter text here..."


Expand Down
Loading