Skip to content

Menu

The main surface and container for UI elements. Connects the layout hierarchy to a specific window.

Specific kwargs

Argument Type Description
window Window | None the window where the menu is rendered.
size list | tuple | NvVector2 initial size of the menu.
style Style style for the menu(default is default_style).
alt bool swap borders and content colors(default is False).
layout LayoutType | None the main layout of the menu(default is None).

Methods

Name Kwargs Description
relx / rely / relm num: int | float scales values relative to the menu's dimensions.
rel mass: NvVector2 scales NvVector2 relative to the menu's dimensions.
convert_to_sdl2_texture surface: Surface | None = None converts surface to SDL2 texture(SDL backend only).
open_submenu menu: Menu, style: Style | None = None, *args opens a submenu and blocks the main menu update.
close_submenu None closes the currently opened submenu.
apply_style_to_layout style: Style applies a new style to the menu and its child layouts.
apply_style_patch_to_layout **patch: Unpack[StyleKwargs] applies style property changes to the menu and its child layouts.
set_coordinates x: int, y: int sets the menu coordinates.
set_coordinates_relative percent_x: int, percent_y: int sets coordinates relative to the window size in percentages.
draw None draws the menu and its layout.
update None updates the menu and its layout.
get_rect None returns a standard pygame.Rect object.
get_nvrect None returns the bounding rectangle (NvRect) of the menu.
kill None destroys the menu and its layout, freeing resources.

Getters

Name ReturnType Description
absolute_coordinates NvVector2 global position on the screen.
size NvVector2 width and height of the menu.
style Style current menu style.
layout LayoutType current active main layout.

Setters

Name Kwargs Description
absolute_coordinates coordinates: NvVector2 sets global position.
size size: NvVector2 sets width and height.
style style: Style overwrites current style.
layout layout: LayoutType sets new main layout.

Use case

from nevu_ui import *
import pygame

pygame.init()

window = Window((500, 500), title = "Menu example")

menu = Menu(window, (100%vw, 100%vh))

while True:
    window.begin_frame()
    window.update()
    menu.update()
    menu.draw()
    window.end_frame()
from nevu_ui import *
import pyray

window = Window((500, 500), title = "Menu example", backend = Backend.RayLib)

menu = Menu(window, (100%vw, 100%vh))

while True:
    window.begin_frame()
    window.update()
    menu.update()
    menu.draw()
    window.end_frame()

Created with GGen v1.1.0 for nevu_ui v0.7.5