Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overflow #459

Merged
merged 3 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygame_menu/baseimage.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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