ppizarror / pygame-menu

A menu for pygame. Simple, and easy to use
https://pygame-menu.readthedocs.io/
Other
544 stars 141 forks source link

Widget selection effect size not taken into account when determining widget size #405

Closed vnmabus closed 2 years ago

vnmabus commented 2 years ago

Environment information Describe your environment information, such as:

Describe the bug The size of the widget selection effect is not taken into account when computing the size of the widgets with menu.get_size(widget=True). Thus, adjusting the menu size to the widgets is more difficult than necessary.

To Reproduce Execute the following code:

import pygame
import pygame_menu

pygame.init()
surface = pygame.display.set_mode((600, 400))

def start_the_game():
    # Do the job here !
    pass

theme = pygame_menu.themes.THEME_BLUE.copy()
theme.title = False
theme.scrollarea_position = pygame_menu.locals.SCROLLAREA_POSITION_NONE
theme.widget_selection_effect = pygame_menu.widgets.LeftArrowSelection(
    arrow_right_margin=50,
)

menu = pygame_menu.Menu(
    'Welcome',
    100,
    100,
    theme=theme,
)

menu.add.button('Play', start_the_game)
menu.add.button('Quit', pygame_menu.events.EXIT)

size = menu.get_size(widget=True)
menu.resize(*size)

menu.mainloop(surface)

The above code tries to adjust the size of the menu to the size of the widgets. Instead, the generated menu looks like this:

Captura de pantalla de 2022-05-01 16-18-11

Expected behavior The size of the widget selection effect should be taken into account by menu.get_size(widget=True), and thus no widget should be truncated.

ppizarror commented 2 years ago

Hi, I think this has been fixed in new #406. Now the given example shows:

image

vnmabus commented 2 years ago

I can confirm that PR #406 solves my original problem.

ppizarror commented 2 years ago

Nice. Merged! I'll create a new version asap