Skip to content

Commit 18e8d73

Browse files
authored
Merge pull request #582 from MyreMylar/selection-fixes
Selection fixes
2 parents 2b86cd5 + 91ce7bc commit 18e8d73

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

pygame_gui/core/text/html_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def _handle_line_break(self):
255255
antialiased=self.current_style['antialiased'],
256256
script=self.current_style['script'],
257257
direction=self.current_style['direction'])
258-
dimensions = (current_font.get_rect(' ').width,
258+
dimensions = (4,
259259
int(round(self.current_style['font_size'] *
260260
self.line_spacing)))
261261
chunk = self.create_styled_text_chunk('')

pygame_gui/core/text/line_break_layout_rect.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ def finalise(self,
3939
self.select_surf = Surface((self.selection_chunk_width, row_bg_height), flags=pygame.SRCALPHA)
4040
self.select_surf.fill(self.selection_colour)
4141
target_surface.blit(self.select_surf, self.topleft, special_flags=pygame.BLEND_PREMULTIPLIED)
42+
# should be cleared by row
4243

pygame_gui/core/text/text_box_layout.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def _add_row_to_layout(self, current_row: TextBoxLayoutRow, last_row=False):
186186
# otherwise we add infinite rows with no height
187187
# instead add a line break rect to an empty row.
188188
if len(current_row.items) == 0 and not last_row:
189-
current_row.add_item(LineBreakLayoutRect(dimensions=(2, self.last_row_height),
189+
current_row.add_item(LineBreakLayoutRect(dimensions=(4, self.last_row_height),
190190
font=current_row.fall_back_font))
191191
if current_row not in self.layout_rows:
192192
self.layout_rows.append(current_row)
@@ -903,6 +903,9 @@ def set_text_selection(self, start_index, end_index):
903903
if self.finalised_surface is not None:
904904
for row in rows_to_finalise:
905905
row.finalise(self.finalised_surface)
906+
for floating_rect in self.floating_rects:
907+
floating_rect.finalise(self.finalised_surface,
908+
self.view_rect, 0, 0, 0)
906909

907910
def _find_chunk_and_chunk_x(self, index: int):
908911
found_chunk = None

pygame_gui/core/text/text_box_layout_row.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def clear(self):
364364
"""
365365
if self.target_surface is not None and self.surf_row_dirty:
366366
slightly_wider_rect = pygame.Rect(self.x, self.y,
367-
self.layout.view_rect.width,
367+
self.width + self.cursor_draw_width,
368368
self.height)
369369
self.target_surface.fill(pygame.Color('#00000000'), slightly_wider_rect)
370370
self.surf_row_dirty = False

pygame_gui/core/text/text_line_chunk.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def finalise(self,
190190
if self.underlined:
191191
self.font.underline_adjustment = 0.5
192192

193-
surface = self._draw_text(chunk_draw_height, chunk_draw_width,
193+
surface = self._draw_text(chunk_draw_height, chunk_draw_width, text_shadow_width,
194194
chunk_x_origin, final_str_text, row_bg_height, row_chunk_origin)
195195

196196
target_surface = self._finalise_horizontal_scroll(target_area,
@@ -213,7 +213,7 @@ def _finalise_horizontal_scroll(self, target_area, text_shadow_width, x_scroll_o
213213
target_surface, surface):
214214
# sort out horizontal scrolling
215215
final_pos = (max(target_area.left, self.left - x_scroll_offset),
216-
self.top - self.origin_row_y_adjust + text_shadow_width)
216+
self.top - self.origin_row_y_adjust)
217217
distance_to_lhs_overlap = self.left - target_area.left
218218
lhs_overlap = max(0, x_scroll_offset - distance_to_lhs_overlap)
219219
remaining_rhs_space = target_area.width - (final_pos[0] - target_area.left)
@@ -264,11 +264,12 @@ def _handle_bg_selection_and_bg_drawing(self, size) -> pygame.Surface:
264264

265265
return surface
266266

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

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

302303
return text_surface
303304

304-
def _draw_text(self, chunk_draw_height, chunk_draw_width, chunk_x_origin,
305+
def _draw_text(self, chunk_draw_height, chunk_draw_width, text_shadow_width, chunk_x_origin,
305306
final_str_text, row_bg_height, row_chunk_origin):
306307

307-
text_surface = self._handle_text_selection_and_text_drawing(final_str_text, chunk_draw_width, chunk_draw_height,
308-
chunk_x_origin, row_chunk_origin)
308+
text_surface = self._handle_text_selection_and_text_drawing(final_str_text, chunk_draw_width, text_shadow_width,
309+
chunk_draw_height, chunk_x_origin, row_chunk_origin)
309310

310311
surface = self._handle_bg_selection_and_bg_drawing((chunk_draw_width, row_bg_height))
311312
# center the text in the line
@@ -319,7 +320,7 @@ def _draw_text(self, chunk_draw_height, chunk_draw_width, chunk_x_origin,
319320
text_rect.centery = surface.get_rect().centery
320321
# apply any shadow effects
321322
self._apply_shadow_effect(surface, text_rect, final_str_text,
322-
text_surface, (chunk_x_origin, row_chunk_origin))
323+
text_surface, (chunk_x_origin, row_chunk_origin + text_shadow_width))
323324
surface.blit(text_surface, text_rect, special_flags=BLEND_PREMULTIPLIED)
324325
return surface
325326

0 commit comments

Comments
 (0)