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

Moving widgets vertically #230

Closed
AlcuZan opened this issue Dec 20, 2020 · 6 comments
Closed

Moving widgets vertically #230

AlcuZan opened this issue Dec 20, 2020 · 6 comments
Labels

Comments

@AlcuZan
Copy link

AlcuZan commented Dec 20, 2020

Firstly I want to say, I love this module. ppizarror has even helped me via mail, he is a great guy.
Problem:

  • I have a combination of buttons, a selector and an image
  • The menu is as big as the surface (1680x1060px)

The widgets appear in the center of the screen and I want to move them up slightly. That doesn't work.
Firstly, I choose a theme and make a copy of it: theme = pygame_menu.themes.THEME_DARK.copy()
Then I try to change the position of the widgets, using theme.widget_offset. This only works for the x axes, and only to the right side, because you can't enter negative values for the offset. Altering the second value of theme.widget_offset does nothing. It's supposed to move the widgets vertically, but that doesn't happen. Am I doing something wrong or is this bugged?

@ppizarror
Copy link
Owner

Can you provide a complete example to test this issue?

Maybe it can be an error ahaahah, At first glance I thought positions would be easy... but not when making a library

@AlcuZan
Copy link
Author

AlcuZan commented Dec 20, 2020

Sure thing mate. First of all, you made it so that no negative values are allowed for widget_offset. So that makes it impossible to move the widgets to the left side or to the bottom, right?

grafik

I'm taking your example simple.py here and will modify it a little bit to show the issue. Hope that's okay.

import os
import pygame
import pygame_menu

pygame.init()
os.environ['SDL_VIDEO_CENTERED'] = '1'
surface = pygame.display.set_mode((1000, 600))


def set_difficulty(selected, value):
    """
    Set the difficulty of the game.
    """
    print('Set difficulty to {} ({})'.format(selected[0], value))


def start_the_game():
    """
    Function that starts a game. This is raised by the menu button,
    here menu can be disabled, etc.
    """
    print('Do the job here !')

theme = pygame_menu.themes.THEME_DARK.copy()
theme.widget_offset = (0, 0)

menu = pygame_menu.Menu(height=600,
                        width=1000,
                        theme=theme,
                        title='Welcome')

menu.add_text_input('Name: ', default='John Doe')
menu.add_selector('Difficulty: ', [('Hard', 1), ('Easy', 2)], onchange=set_difficulty)
menu.add_button('Play', start_the_game)
menu.add_button('Quit', pygame_menu.events.EXIT)

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

The above code produces this:

grafik

Now when I try to move the widgets vertically by setting theme.widget_offset to (0, 300):

grafik

Looks exactly the same.

1 similar comment
@AlcuZan
Copy link
Author

AlcuZan commented Dec 22, 2020

Sure thing mate. First of all, you made it so that no negative values are allowed for widget_offset. So that makes it impossible to move the widgets to the left side or to the bottom, right?

grafik

I'm taking your example simple.py here and will modify it a little bit to show the issue. Hope that's okay.

import os
import pygame
import pygame_menu

pygame.init()
os.environ['SDL_VIDEO_CENTERED'] = '1'
surface = pygame.display.set_mode((1000, 600))


def set_difficulty(selected, value):
    """
    Set the difficulty of the game.
    """
    print('Set difficulty to {} ({})'.format(selected[0], value))


def start_the_game():
    """
    Function that starts a game. This is raised by the menu button,
    here menu can be disabled, etc.
    """
    print('Do the job here !')

theme = pygame_menu.themes.THEME_DARK.copy()
theme.widget_offset = (0, 0)

menu = pygame_menu.Menu(height=600,
                        width=1000,
                        theme=theme,
                        title='Welcome')

menu.add_text_input('Name: ', default='John Doe')
menu.add_selector('Difficulty: ', [('Hard', 1), ('Easy', 2)], onchange=set_difficulty)
menu.add_button('Play', start_the_game)
menu.add_button('Quit', pygame_menu.events.EXIT)

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

The above code produces this:

grafik

Now when I try to move the widgets vertically by setting theme.widget_offset to (0, 300):

grafik

Looks exactly the same.

@ppizarror
Copy link
Owner

Hi, I found that you're using center_content=True, then widget_offset vertical position is "overridden".

The following code works as intended:

import os
import pygame
import pygame_menu

pygame.init()
os.environ['SDL_VIDEO_CENTERED'] = '1'
surface = pygame.display.set_mode((1000, 600))


def set_difficulty(selected, value):
    """
    Set the difficulty of the game.
    """
    print('Set difficulty to {} ({})'.format(selected[0], value))


def start_the_game():
    """
    Function that starts a game. This is raised by the menu button,
    here menu can be disabled, etc.
    """
    print('Do the job here !')

theme = pygame_menu.themes.THEME_DARK.copy()
theme.widget_offset = (0, 300)

menu = pygame_menu.Menu(height=600,
                        width=1000,
                        theme=theme,
                        title='Welcome',
                        center_content=False)

menu.add_text_input('Name: ', default='John Doe')
menu.add_selector('Difficulty: ', [('Hard', 1), ('Easy', 2)], onchange=set_difficulty)
menu.add_button('Play', start_the_game)
menu.add_button('Quit', pygame_menu.events.EXIT)

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

For avoiding this issue, if vertical offset is different than zero, and center_content is not False it will raise a warning

@ppizarror
Copy link
Owner

From now on, this message is displayed using your example:

menu.py:253: UserWarning: menu is vertically centered (center_content=True), but widget offset (from theme) is different than zero (300px). Auto-centering has been disabled
  warnings.warn(msg)

@AlcuZan
Copy link
Author

AlcuZan commented Jan 2, 2021

Thanks, it works now! :)

@AlcuZan AlcuZan closed this as completed Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants