Skip to content

Latest commit

 

History

History
192 lines (139 loc) · 8.53 KB

themes.rst

File metadata and controls

192 lines (139 loc) · 8.53 KB

pygame_menu.themes

Creating themes

:pypygame-menu offers many parameters to control the visual aspect of the menu. For an easier usage, all of them are gathered in a specific object called a theme. It is used to customize the menu window itself and all its widgets.

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

Note

The theme parameters can be overwritten locally when adding a widget to the menu. See the overwritable ones in the add_... methods <Adding widgets>

Default themes

Several predefined themes are proposed by :pypygame-menu.

Theme name Example
:pypygame_menu.themes.THEME_DEFAULT

image

:pypygame_menu.themes.THEME_BLUE

image

:pypygame_menu.themes.THEME_DARK

image

:pypygame_menu.themes.THEME_GREEN

image

:pypygame_menu.themes.THEME_ORANGE

image

:pypygame_menu.themes.THEME_SOLARIZED

image

Create a theme

If none of the proposed theme fit to the needs, the :pyTheme give the opportunity to create custom themes.

mytheme = Theme(background_color=(0, 0, 0, 0), # transparent background
                title_shadow=True,
                title_background_color=(4, 47, 126),
                ...)

menu = Menu(..., theme=mytheme)

Of course it is also possible to start from a predefined theme by copying it first.

mytheme = pygame_menu.themes.THEME_ORANGE.copy()
mytheme.title_background_color=(0, 0, 0)

menu = Menu(..., theme=mytheme)

Background Color/Images

Theme background can be both a color or an image. All colors can be defined using a tuple or an list of 3 or 4 numbers between 0 and 255. The format of numers are:

color_opaque = (R,G,B)
color_transparent = (R,G,B,A)

A alpha channels goes from 0 to 255. 0 is transparent, 255 is opaque. For using images as a background color, class :pypygame_menu.baseimage.BaseImage must be used.

Images needs a Path (file location on disk), a drawing mode, and an optional offset.

myimage = pygame_menu.baseimage.BaseImage(
    image_path=pygame_menu.baseimage.IMAGE_EXAMPLE_GRAY_LINES,
    drawing_mode=pygame_menu.baseimage.IMAGE_MODE_REPEAT_XY,
    offset=(0,0)
)
mytheme.background_color = myimage
Image drawing modes Description
:pypygame_menu.baseimage.IMAGE_MODE_CENTER Centers the image in the surface
:pypygame_menu.baseimage.IMAGE_MODE_FILL Fill the image on the surface
:pypygame_menu.baseimage.IMAGE_MODE_REPEAT_X Repeat the image on x axis
:pypygame_menu.baseimage.IMAGE_MODE_REPEAT_XY Repeat the image on x and y axis
:pypygame_menu.baseimage.IMAGE_MODE_REPEAT_Y Repeat the image on y axis
:pypygame_menu.baseimage.IMAGE_MODE_SIMPLE Write the image on top-left location

Currently, :pyTheme class only supports images for :pybackground_color and :pywidget_background_color. Also, only IMAGE_MODE_FILL drawing mode is valid for :pywidget_background_color.

Menubar style

The visual style of the menubar is managed using the theme parameter title_bar_style which can take the following values:

Menubar style Example
:pypygame_menu.widgets.MENUBAR_STYLE_ADAPTIVE

image

:pypygame_menu.widgets.MENUBAR_STYLE_SIMPLE

image

:pypygame_menu.widgets.MENUBAR_STYLE_TITLE_ONLY

image

:pypygame_menu.widgets.MENUBAR_STYLE_TITLE_ONLY_DIAGONAL

image

:pypygame_menu.widgets.MENUBAR_STYLE_NONE

image

:pypygame_menu.widgets.MENUBAR_STYLE_UNDERLINE

image

:pypygame_menu.widgets.MENUBAR_STYLE_UNDERLINE_TITLE

image

Widget selection effect

A selection effect is a drawing class used to define the way to highlight the focused widget. An instance of the selection effect class is defined in the :pyTheme.widget_selection_effect parameter of a theme. See example on how to add a selection effect in Create a selection effect chapter.

The available selection effects are:

Class Selection effect
:pypygame_menu.widgets.HighlightSelection Rectangular highlight
:pypygame_menu.widgets.LeftArrowSelection Left arrow on the widget
:pypygame_menu.widgets.NoneSelection No selection
:pypygame_menu.widgets.RightArrowSelection Right arrow on the widget

The selection color is defined in :pyTheme.widget_selection_color.

Fonts

This library also has some fonts to use. To load a font, run this code:

import pygame_menu

font = pygame_menu.font.FONT_NAME
my_theme = Theme(widget_font=font, ...)
Available fonts Preview
:pypygame_menu.font.FONT_8BIT

image

:pypygame_menu.font.FONT_BEBAS

image

:pypygame_menu.font.FONT_COMIC_NEUE

image

:pypygame_menu.font.FONT_FRANCHISE

image

:pypygame_menu.font.FONT_HELVETICA

image

:pypygame_menu.font.FONT_MUNRO

image

:pypygame_menu.font.FONT_NEVIS

image

:pypygame_menu.font.FONT_OPEN_SANS

image

:pypygame_menu.font.FONT_OPEN_SANS_BOLD

image

:pypygame_menu.font.FONT_OPEN_SANS_ITALIC

image

:pypygame_menu.font.FONT_OPEN_SANS_LIGHT

image

:pypygame_menu.font.FONT_PT_SERIF

image

System fonts can also be used. The available system fonts can be listed using the following command in a python shell:

import pygame
print(pygame.font.get_fonts())

Theme API

Theme