Skip to content

Grid

Grid

A rigid grid. Elements are positioned by cell coordinates.

Specific kwargs

Argument Type Description
content {(int | float, int | float): NevuObject} initial content.
row / y int | float number of rows.
column / x int | float number of columns.

Methods

Name Kwargs Description
add_item item: NevuObject, x: int | float, y: int | float adds item into specified cell, starting from 1.
add_items content: dict adds multiple items from the specified dictionary.
get_row x: int | float returns a list of all items in the specified row.
get_column y: int | float returns a list of all items in the specified column.
kill_item_by_pos x: int | float, y: int | float removes and destroys the item at the specified cell.
get_item_grid item: NevuObject returns the cell coordinates (NvVector2) of the item inside the grid.
get_item x: int | float, y: int | float returns the item at the specified coordinates, or None.

Grid is a subclass of: LayoutType

Use case

from nevu_ui import *
import pygame

pygame.init()

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

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

layout = Grid((100%vw, 100%vh), x = 3,  y = 3, content = {
    (2, 2): Label("Text", (250, 100))
})

menu.layout = layout
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 = "Grid example", backend = Backend.RayLib)

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

layout = Grid((100%vw, 100%vh), x = 3,  y = 3, content = {
    (2, 2): Label("Text", (250, 100))
})

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

Created with GGen v1.3.0 for nevu_ui v0.8.2