ppizarror / pygame-menu

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

User warning for equal title font color and menu background color when the latter is set to (0, 0, 0) #473

Closed DKNorad closed 10 months ago

DKNorad commented 11 months ago

Environment information Describe your environment information, such as:

Describe the bug While using a menubar style that calls self._check_title_color(background_menu=True) I get the following error when my Theme background_color is black (0, 0, 0).

venv/lib/python3.11/site-packages/pygame_menu/widgets/widget/menubar.py:203: UserWarning: title font color (0, 0, 0) is equal to the menu background color (0, 0, 0, 255), consider editing your Theme
  warn(

To Reproduce

import pygame_menu
from pygame_menu import Theme

menu_theme = Theme(background_color=BLACK, title_font_color=WHITE, widget_padding=5,
                   title_bar_style=pygame_menu.widgets.MENUBAR_STYLE_NONE,
                   widget_selection_effect=pygame_menu.widgets.NoneSelection(),
                   fps=60, title_font=pygame.font.Font(pygame.font.get_default_font(), 150), 
                   widget_alignment=pygame_menu.locals.ALIGN_LEFT,
                   widget_margin=(10, 0), widget_font_color=WHITE, title_offset=(10, 70))

menu = pygame_menu.Menu('Title', 800, 600, theme=menu_theme)
menu.mainloop(window)

Expected behavior To not show the error.

Additional context I was trying to debug the problem. "_check_title_color()" gets called 3 times and this is the output from "self._font_color" with the code above.

(0, 0, 0)
(255, 255, 255, 255)  <<<<<<< title_font_color=WHITE
(255, 255, 255, 255)   <<<<<<< title_font_color=WHITE

I can't figure out why on the first call it uses the default value of (0, 0, 0) and why it goes through it 3 times.

andrew-karppinen commented 10 months ago

Yeah,

UserWarning: title font color (0, 0, 0) is equal to the menu background color (0, 0, 0, 255), consider editing your Theme
  warn(

This code gives me an user warning:

theme = pygame_menu.Theme(background_color=(0, 0, 0), title_background_color=(178, 29, 29),
                                    widget_font_color=(255, 255, 255), widget_padding=6,title_font_color = (255,255,255),
                                    title_font_size=52,widget_font_size=38,title_bar_style = pygame_menu.widgets.MENUBAR_STYLE_UNDERLINE) #create menu theme

Error occurs if title theme is "MENUBAR_STYLE_UNDERLINE", "MENUBAR_STYLE_UNDERLINE_TITLE" or "MENUBAR_STYLE_NONE "

DKNorad commented 10 months ago

I found where the problem is coming from. We are running self._menubar.set_menu(self) in menu.py:524 before we set the font variables with self._menubar.set_font() in menu.py:525. We end up running self._check_title_color() in menubar.py before we set the self._font_color in widget.py, and it takes the default value which is (0, 0, 0).