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

Selection fixes #582

Merged
merged 2 commits into from
Apr 14, 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
2 changes: 1 addition & 1 deletion pygame_gui/core/text/html_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def _handle_line_break(self):
antialiased=self.current_style['antialiased'],
script=self.current_style['script'],
direction=self.current_style['direction'])
dimensions = (current_font.get_rect(' ').width,
dimensions = (4,
int(round(self.current_style['font_size'] *
self.line_spacing)))
chunk = self.create_styled_text_chunk('')
Expand Down
1 change: 1 addition & 0 deletions pygame_gui/core/text/line_break_layout_rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ def finalise(self,
self.select_surf = Surface((self.selection_chunk_width, row_bg_height), flags=pygame.SRCALPHA)
self.select_surf.fill(self.selection_colour)
target_surface.blit(self.select_surf, self.topleft, special_flags=pygame.BLEND_PREMULTIPLIED)
# should be cleared by row

5 changes: 4 additions & 1 deletion pygame_gui/core/text/text_box_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
# otherwise we add infinite rows with no height
# instead add a line break rect to an empty row.
if len(current_row.items) == 0 and not last_row:
current_row.add_item(LineBreakLayoutRect(dimensions=(2, self.last_row_height),
current_row.add_item(LineBreakLayoutRect(dimensions=(4, self.last_row_height),
font=current_row.fall_back_font))
if current_row not in self.layout_rows:
self.layout_rows.append(current_row)
Expand Down Expand Up @@ -903,6 +903,9 @@
if self.finalised_surface is not None:
for row in rows_to_finalise:
row.finalise(self.finalised_surface)
for floating_rect in self.floating_rects:
floating_rect.finalise(self.finalised_surface,

Check warning on line 907 in pygame_gui/core/text/text_box_layout.py

View check run for this annotation

Codecov / codecov/patch

pygame_gui/core/text/text_box_layout.py#L907

Added line #L907 was not covered by tests
self.view_rect, 0, 0, 0)

def _find_chunk_and_chunk_x(self, index: int):
found_chunk = None
Expand Down
2 changes: 1 addition & 1 deletion pygame_gui/core/text/text_box_layout_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def clear(self):
"""
if self.target_surface is not None and self.surf_row_dirty:
slightly_wider_rect = pygame.Rect(self.x, self.y,
self.layout.view_rect.width,
self.width + self.cursor_draw_width,
self.height)
self.target_surface.fill(pygame.Color('#00000000'), slightly_wider_rect)
self.surf_row_dirty = False
Expand Down
19 changes: 10 additions & 9 deletions pygame_gui/core/text/text_line_chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def finalise(self,
if self.underlined:
self.font.underline_adjustment = 0.5

surface = self._draw_text(chunk_draw_height, chunk_draw_width,
surface = self._draw_text(chunk_draw_height, chunk_draw_width, text_shadow_width,
chunk_x_origin, final_str_text, row_bg_height, row_chunk_origin)

target_surface = self._finalise_horizontal_scroll(target_area,
Expand All @@ -213,7 +213,7 @@ def _finalise_horizontal_scroll(self, target_area, text_shadow_width, x_scroll_o
target_surface, surface):
# sort out horizontal scrolling
final_pos = (max(target_area.left, self.left - x_scroll_offset),
self.top - self.origin_row_y_adjust + text_shadow_width)
self.top - self.origin_row_y_adjust)
distance_to_lhs_overlap = self.left - target_area.left
lhs_overlap = max(0, x_scroll_offset - distance_to_lhs_overlap)
remaining_rhs_space = target_area.width - (final_pos[0] - target_area.left)
Expand Down Expand Up @@ -264,11 +264,12 @@ def _handle_bg_selection_and_bg_drawing(self, size) -> pygame.Surface:

return surface

def _handle_text_selection_and_text_drawing(self, final_str_text, chunk_draw_width, chunk_draw_height,
chunk_x_origin, row_chunk_origin) -> pygame.Surface:
def _handle_text_selection_and_text_drawing(self, final_str_text, chunk_draw_width, text_shadow_width,
chunk_draw_height, chunk_x_origin, row_chunk_origin) -> pygame.Surface:
text_surface: pygame.Surface = self.font.render_premul_to(final_str_text, Color('#FFFFFFFF'),
surf_size=(chunk_draw_width, chunk_draw_height),
surf_position=(chunk_x_origin, row_chunk_origin))
surf_position=(chunk_x_origin,
row_chunk_origin + text_shadow_width))

if (self.selection_rect is not None
and (self.selection_rect.width != 0 or self.selection_rect.height != 0)
Expand Down Expand Up @@ -301,11 +302,11 @@ def _handle_text_selection_and_text_drawing(self, final_str_text, chunk_draw_wid

return text_surface

def _draw_text(self, chunk_draw_height, chunk_draw_width, chunk_x_origin,
def _draw_text(self, chunk_draw_height, chunk_draw_width, text_shadow_width, chunk_x_origin,
final_str_text, row_bg_height, row_chunk_origin):

text_surface = self._handle_text_selection_and_text_drawing(final_str_text, chunk_draw_width, chunk_draw_height,
chunk_x_origin, row_chunk_origin)
text_surface = self._handle_text_selection_and_text_drawing(final_str_text, chunk_draw_width, text_shadow_width,
chunk_draw_height, chunk_x_origin, row_chunk_origin)

surface = self._handle_bg_selection_and_bg_drawing((chunk_draw_width, row_bg_height))
# center the text in the line
Expand All @@ -319,7 +320,7 @@ def _draw_text(self, chunk_draw_height, chunk_draw_width, chunk_x_origin,
text_rect.centery = surface.get_rect().centery
# apply any shadow effects
self._apply_shadow_effect(surface, text_rect, final_str_text,
text_surface, (chunk_x_origin, row_chunk_origin))
text_surface, (chunk_x_origin, row_chunk_origin + text_shadow_width))
surface.blit(text_surface, text_rect, special_flags=BLEND_PREMULTIPLIED)
return surface

Expand Down
Loading