Skip to content

Commit

Permalink
add dynamic dimension attributes to text box layout
Browse files Browse the repository at this point in the history
  • Loading branch information
MyreMylar committed Apr 16, 2023
1 parent 39f6199 commit 7e65f73
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pygame_gui/core/text/text_box_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7e65f73

Please sign in to comment.