Skip to content

Commit

Permalink
Merge pull request #445 from MyreMylar/fix-center-anchor-dynamic-sizing
Browse files Browse the repository at this point in the history
fix dynamic sizing recalculations.
  • Loading branch information
MyreMylar authored Apr 16, 2023
2 parents d574502 + 6561b47 commit 2ecf673
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pygame_gui/elements/ui_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,16 +776,16 @@ def _calc_dynamic_size(self):
if self.dynamic_width or self.dynamic_height:
self.set_dimensions(self.image.get_size())

# if we have anchored the left side of our button to the right of it's container then
# if we have anchored the left side of our button to the right of its container then
# changing the width is going to mess up the horiz position as well.
new_left = self.relative_rect.left
new_top = self.relative_rect.top
if self.anchors['left'] == 'right' and self.dynamic_width:
if 'left' in self.anchors and self.anchors['left'] == 'right' and self.dynamic_width:
left_offset = self.dynamic_dimensions_orig_top_left[0]
new_left = left_offset - self.relative_rect.width
# if we have anchored the top side of our button to the bottom of it's container then
# changing the height is going to mess up the vert position as well.
if self.anchors['top'] == 'bottom' and self.dynamic_height:
if 'top' in self.anchors and self.anchors['top'] == 'bottom' and self.dynamic_height:
top_offset = self.dynamic_dimensions_orig_top_left[1]
new_top = top_offset - self.relative_rect.height

Expand Down
4 changes: 2 additions & 2 deletions pygame_gui/elements/ui_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ def _calc_dynamic_size(self):
# changing the width is going to mess up the horiz position as well.
new_left = self.relative_rect.left
new_top = self.relative_rect.top
if self.anchors['left'] == 'right' and self.dynamic_width:
if 'left' in self.anchors and self.anchors['left'] == 'right' and self.dynamic_width:
left_offset = self.dynamic_dimensions_orig_top_left[0]
new_left = left_offset - self.relative_rect.width
# if we have anchored the top side of our button to the bottom of it's container then
# changing the height is going to mess up the vert position as well.
if self.anchors['top'] == 'bottom' and self.dynamic_height:
if 'top' in self.anchors and self.anchors['top'] == 'bottom' and self.dynamic_height:
top_offset = self.dynamic_dimensions_orig_top_left[1]
new_top = top_offset - self.relative_rect.height

Expand Down

0 comments on commit 2ecf673

Please sign in to comment.