Skip to content

Imperative

Building first app with imperative way

First thing first, import nevu-ui and create a window. To create a Window you must specify size other arguments are not required, Window initializes screen with specified backend(default is pygame):

import nevu_ui as ui
import pygame
pygame.init()

window = ui.Window((800, 600), title="Nevu UI App")
The next step is to create a Menu, you'll need to put window and size as it's arguments:
menu = ui.Menu(window, (800, 600))
After Menu and Window are created, you need to create any layout, for example i picked Grid:
grid = ui.Grid((800, 600), row=3, column=3)
With Grid layout done, you can add something inside it via add_item:
grid.add_item(ui.Label("Nevu UI", (400, 200)), 2, 2)
note: you can add ANY widget / layout inside layout. After you done with adding items to layout, you need to connect layout and menu:
menu.layout = grid
Congratulations, you've created your first app! Now let`s run it. Here is code of the main loop:
while True:
    window.begin_frame()
    window.update()
    menu.update()
    menu.draw()
    window.end_frame()

Full code:

import nevu_ui as ui
import pygame

pygame.init()

window = ui.Window((800, 600), title="Nevu UI App")

menu = ui.Menu(window, (800, 600))

grid = ui.Grid((800, 600), row=3, column=3)

grid.add_item(ui.Label("Nevu UI", (400, 200)), 2, 2)

menu.layout = grid

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