Skip to content

Commit

Permalink
Merge pull request #459 from ppizarror/fix-overflow
Browse files Browse the repository at this point in the history
Fix overflow
  • Loading branch information
ppizarror committed Mar 25, 2023
2 parents 291cdb1 + 49022b2 commit 6eeb8e7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pygame_menu/baseimage.py
Expand Up @@ -424,7 +424,7 @@ def get_at(
self,
pos: Tuple2NumberType,
ignore_alpha: bool = False
) -> Union[Tuple3IntType, Tuple4IntType]:
) -> Union[Tuple3IntType, Tuple4IntType, 'pygame.Color']:
"""
Get the color from a certain position in image on x-axis and y-axis (x, y).
Expand Down
10 changes: 7 additions & 3 deletions pygame_menu/menu.py
Expand Up @@ -1617,20 +1617,24 @@ def _build_widget_surface(self) -> None:
# Get scrollbars size
sx, sy = self._get_scrollbar_thickness()

# Check if there is an overflow
overflow_x = max_x - (self._width - sy) > 1
overflow_y = max_y - (self._height - sx - menubar_height) > 1

# Remove the thick of the scrollbar to avoid displaying a horizontal one
# If overflow on both axis
if max_x > self._width - sy and max_y > self._height - sx - menubar_height:
if overflow_x and overflow_y:
width, height = max_x, max_y
if not self._mouse_visible:
self._mouse_visible = True

# If horizontal overflow
elif max_x > self._width - sy:
elif overflow_x:
width, height = max_x, self._height - menubar_height - sx
self._mouse_visible = self._mouse_visible_default

# If vertical overflow
elif max_y > self._height - sx - menubar_height:
elif overflow_y:
width, height = self._width - sy, max_y
if not self._mouse_visible:
self._mouse_visible = True
Expand Down
2 changes: 1 addition & 1 deletion pygame_menu/version.py
Expand Up @@ -32,6 +32,6 @@ def __str__(self) -> str:
patch = property(lambda self: self[2])


vernum = Version(4, 3, 9)
vernum = Version(4, 4, 0)
ver = str(vernum)
rev = ''
1 change: 1 addition & 0 deletions test/_utils.py
Expand Up @@ -21,6 +21,7 @@
'reset_widgets_over',
'sleep',
'surface',
'test_reset_surface',

# Class utils
'BaseTest',
Expand Down
4 changes: 2 additions & 2 deletions test/test_widget_none.py
Expand Up @@ -261,15 +261,15 @@ def test_vfill(self) -> None:
vf2.hide()
vfill_total_after = vf1.get_height() + vf3.get_height()
self.assertEqual(vf1.get_height(), vf3.get_height() + 1)
self.assertEqual(vfill_total, vfill_total_after - 1)
self.assertLessEqual(abs(vfill_total - vfill_total_after), 1)
vf2.show()
self.assertEqual(vfill_total, vf1.get_height() + vf2.get_height() + vf3.get_height())

# Hiding a button should also affect vfills
vf1_height_prev = vf1.get_height()
b1_height = math.ceil(b1.get_height() / 3)
b1.hide()
self.assertEqual(vf1.get_height(), vf1_height_prev + b1_height)
self.assertLessEqual(abs(vf1.get_height() - (vf1_height_prev + b1_height)), 1)
b1.show()
self.assertEqual(vf1.get_height(), vf1_height_prev)

Expand Down

0 comments on commit 6eeb8e7

Please sign in to comment.