ppizarror / pygame-menu

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

Is there a way to make the widgets use all available vertical space? #400

Closed vnmabus closed 2 years ago

vnmabus commented 2 years ago

I have some menus where the size is fixed (e.g. they are as tall as the screen itself). For these cases, I want to be able to specify that the widgets should be separated enough to cover all available vertical space, but I don't know if there is an option for that. I already tried center_content, but this only centers the "block" with all the widgets, it does not add space between widgets.

In other words, if you know Latex, I would want the analog of using \vfill between the widgets and at the beginning and end.

I think I could implement this myself computing the available space and adding VMargin widgets, but I was wondering if there was an easier way.

ppizarror commented 2 years ago

Hi @vnmabus. I added a new widget VFill in #403. This widget is smart enough to adjust its height depending on the column position and the presence of other vfill widgets. The manager also accepts min_height to define the minimum height of this widget.

An example:

import pygame
import pygame_menu

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

theme = pygame_menu.themes.THEME_BLUE
theme.background_color = '#ddd'
theme.title_background_color = '#333'
theme.title_bar_style = pygame_menu.widgets.MENUBAR_STYLE_UNDERLINE_TITLE
theme.title_font_color = '#666'
theme.title_font_shadow = False

menu = pygame_menu.Menu('Welcome', 600, 400, theme=pygame_menu.themes.THEME_BLUE)

menu.add.button('Button 1')
menu.add.vertical_fill()
menu.add.button('Button 2')
menu.add.vertical_fill()
menu.add.button('Exit', pygame_menu.events.EXIT)

menu.mainloop(surface)

image

Let me know if this widget solves your issue =)