Skip to content

Commit

Permalink
More dynamic resizing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MyreMylar committed Apr 16, 2023
1 parent 7e65f73 commit b4c87ea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
21 changes: 15 additions & 6 deletions pygame_gui/core/drawable_shapes/drawable_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def __init__(self,

self.theming = theming_parameters
self.containing_rect = containing_rect.copy()
self.dynamic_width = True if self.containing_rect.width == -1 else False
self.dynamic_height = True if self.containing_rect.height == -1 else False
self.text_view_rect: Optional[pygame.Rect] = None

self.shadow_width = 0
Expand Down Expand Up @@ -207,7 +209,7 @@ def __init__(self,
self.only_text_changed = False

def _evaluate_contents_for_containing_rect(self):
if self.containing_rect.width == -1:
if self.dynamic_width:
# check to see if we have text and a font, this won't work with HTML
# text - throw a warning?
# What we really need to to is process the html text layout by this
Expand All @@ -230,7 +232,7 @@ def _evaluate_contents_for_containing_rect(self):
self.text_view_rect.width = text_width
self.text_box_layout.view_rect.width = self.text_view_rect.width
self.containing_rect.width = final_width
if self.containing_rect.height == -1:
if self.dynamic_height:
if self.text_box_layout is not None:
text_height = self.text_box_layout.layout_rect.height

Expand Down Expand Up @@ -490,10 +492,17 @@ def build_text_layout(self):
self.text_view_rect = self.containing_rect.copy()
self.text_view_rect.x = 0
self.text_view_rect.y = 0
if self.text_view_rect.width != -1:
self.text_view_rect.width -= ((total_text_buffer * 2) + (2 * horiz_padding))
if self.text_view_rect.height != -1:
self.text_view_rect.height -= ((total_text_buffer * 2) + (2 * vert_padding))
if self.dynamic_width:
self.text_view_rect.width = -1
else:
self.text_view_rect.width = max(0, self.text_view_rect.width -
((total_text_buffer * 2) + (2 * horiz_padding)))

if self.dynamic_height:
self.text_view_rect.height = -1
else:
self.text_view_rect.height = max(0, self.text_view_rect.height -
((total_text_buffer * 2) + (2 * vert_padding)))

text_actual_area_rect = self.text_view_rect.copy()
text_actual_area_rect.x = total_text_buffer + horiz_padding
Expand Down
6 changes: 4 additions & 2 deletions pygame_gui/core/text/text_box_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ def __init__(self,

self.expand_width = False
if self.layout_rect.width == -1:
self.dynamic_width = True
self.layout_rect.width = 0
self.expand_width = True
for rect in self.input_data_rect_queue:
self.layout_rect.width += rect.width

if self.view_rect.width == -1:
self.dynamic_width = True
else:
self.dynamic_width = False
if self.layout_rect.height == -1:
if self.view_rect.height == -1:
self.dynamic_height = True
else:
self.dynamic_height = False
Expand Down
12 changes: 6 additions & 6 deletions pygame_gui/core/text/text_line_chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def _handle_dimensions(self, font, max_dimensions, text):
text_width = self._text_render_width(text, font) + (2 * text_shadow_width)
text_height = text_rect.height
if max_dimensions is not None:
if max_dimensions[0] != -1:
if not (max_dimensions[0] == -1 or max_dimensions[1] == -1):
# we don't have dynamic maximum dimensions so use maximum dimensions for both
text_width = min(max_dimensions[0], text_width)
if max_dimensions[1] != -1:
text_height = min(max_dimensions[1], text_height)
return text_height, text_rect, text_width

Expand Down Expand Up @@ -567,9 +567,9 @@ def insert_text(self, input_text: str, index: int):
text_width = self._text_render_width(self.text, self.font)
text_height = text_rect.height
if self.max_dimensions is not None:
if self.max_dimensions[0] != -1:
if not (self.max_dimensions[0] == -1 or self.max_dimensions[1] == -1):
# we don't have dynamic maximum dimensions so use maximum dimensions for both
text_width = min(self.max_dimensions[0], text_width)
if self.max_dimensions[1] != -1:
text_height = min(self.max_dimensions[1], text_height)

self.size = (text_width, text_height) # noqa pylint: disable=attribute-defined-outside-init; pylint getting confused
Expand All @@ -592,9 +592,9 @@ def delete_letter_at_index(self, index):
text_width = self._text_render_width(self.text, self.font)
text_height = text_rect.height
if self.max_dimensions is not None:
if self.max_dimensions[0] != -1:
if not (self.max_dimensions[0] == -1 or self.max_dimensions[1] == -1):
# we don't have dynamic maximum dimensions so use maximum dimensions for both
text_width = min(self.max_dimensions[0], text_width)
if self.max_dimensions[1] != -1:
text_height = min(self.max_dimensions[1], text_height)

self.size = (text_width, text_height) # noqa pylint: disable=attribute-defined-outside-init; pylint getting confused
Expand Down

0 comments on commit b4c87ea

Please sign in to comment.