diff --git a/pygame_gui/core/drawable_shapes/drawable_shape.py b/pygame_gui/core/drawable_shapes/drawable_shape.py index 2a9b1472..4bdc17f9 100644 --- a/pygame_gui/core/drawable_shapes/drawable_shape.py +++ b/pygame_gui/core/drawable_shapes/drawable_shape.py @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/pygame_gui/core/text/text_box_layout.py b/pygame_gui/core/text/text_box_layout.py index 9afec5ab..877bfa52 100644 --- a/pygame_gui/core/text/text_box_layout.py +++ b/pygame_gui/core/text/text_box_layout.py @@ -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 diff --git a/pygame_gui/core/text/text_line_chunk.py b/pygame_gui/core/text/text_line_chunk.py index 108ba440..3de8f0c2 100644 --- a/pygame_gui/core/text/text_line_chunk.py +++ b/pygame_gui/core/text/text_line_chunk.py @@ -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 @@ -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 @@ -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