From 7e65f738901899ce8d76069e32b4ad18f3dad0c8 Mon Sep 17 00:00:00 2001 From: Dan Lawrence Date: Sun, 16 Apr 2023 19:24:29 +0100 Subject: [PATCH] add dynamic dimension attributes to text box layout --- pygame_gui/core/text/text_box_layout.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pygame_gui/core/text/text_box_layout.py b/pygame_gui/core/text/text_box_layout.py index 01958afd..9afec5ab 100644 --- a/pygame_gui/core/text/text_box_layout.py +++ b/pygame_gui/core/text/text_box_layout.py @@ -50,10 +50,17 @@ 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 + else: + self.dynamic_width = False + if self.layout_rect.height == -1: + self.dynamic_height = True + else: + self.dynamic_height = False self.layout_rect_queue = None self.finalised_surface = None @@ -142,6 +149,10 @@ def _process_layout_queue(self, input_queue, current_row): current_row = self._handle_regular_rect(current_row, text_layout_rect, input_queue) # make sure we add the last row to the layout self._add_row_to_layout(current_row, last_row=True) + if self.dynamic_width: + self.view_rect.width = self.layout_rect.width + if self.dynamic_height: + self.view_rect.height = self.layout_rect.height def _add_row_to_layout(self, current_row: TextBoxLayoutRow, last_row=False): # handle an empty row being added to layout