ppizarror / pygame-menu

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

Center menu items when scrollbar is shown #446

Closed asztalosdani closed 1 year ago

asztalosdani commented 1 year ago

Environment information Describe your environment information, such as:

Describe the bug I would like to center the menu items even when there is a scrollbar. (I added the red line in paint to visualize the center) image

To Reproduce

import pygame_menu
from pygame_menu.examples import create_example_window

surface = create_example_window('Example - Simple', (320, 240))

menu = pygame_menu.Menu(height=240, theme=pygame_menu.themes.THEME_BLUE, title='Main menu', width=320)

menu.add.button('Option1')
menu.add.button('Option2')
menu.add.button('Option3')
menu.add.button('Option4')
menu.add.button('Option5')
menu.add.button('Quit', pygame_menu.events.EXIT)

if __name__ == '__main__':
    menu.mainloop(surface)

Expected behavior Center the items, or at least give me an option to toggle this behaviour.

Additional context The reason is, I'm creating an application to be run on a Raspberry Pi on a 320x240 tft screen, with a few physical buttons below it, so you clearly see where is the center of the screen, and that the menu items are off-center. But even if you don't have a tiny screen, if you have a main menu with a few items, so without a scrollbar -> centered, then a submenu with more items so with a scrollbar -> off-center, and you switch between them, the jump is noticable.

ppizarror commented 1 year ago

I think theme should receive a parameter named center_ignore_scrollbar_thickness. The problem here is that when computing the position, if the menu overflows, then the thickness of the scrollbars is added. Hence, the widgets are centered concerning their scrollarea, but not regarding the window. This value must be False for backward-compatibility reasons.

asztalosdani commented 1 year ago

Yes, that should do it!

ppizarror commented 1 year ago

Fixed in #449. Let me know if this solves your issue 👯

asztalosdani commented 1 year ago

Yes, it works, thanks!

ppizarror commented 1 year ago

Version v4.3.7 uploaded to pip!