Skip to content

Declarative

Building first app with declarative way

First thing first, import nevu-ui and create a Manager subclass.

import nevu_ui as ui
import pygame

pygame.init()

class MyApp(ui.Manager):
After creating MyApp you need to override __init__ and create Window inside it: To create a Window you must specify size other arguments are not required, Window initializes screen with specified backend(default is pygame):
    def __init__(self):
        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, ui.fill_all, layout = ...)
You need to create any layout inside menu, and put widget inside layout, for example i picked Grid:
#inside menu creation
layout = ui.Grid(ui.fill_all, row=3, column=3, 
    content = {
        (2, 2): ui.Label("Nevu UI", (50%ui.vw, 33%ui.vh))
    })
Note: 50%ui.vw and 33%ui.vh represent 50% of the viewport width and 33% of the viewport height After Window and Menu are created lets pass them to the parent manager's __init__ method:
    super().__init__(window, menu)
Congratulations, you've created your first app! Now let`s run it.
app = MyApp()
app.run()

Full code

import nevu_ui as ui
import pygame

pygame.init()

class MyApp(ui.Manager):
    def __init__(self):
        window = ui.Window((800, 600), title="Nevu UI App") 
        menu = ui.Menu(window, ui.fill_all, 
            layout = ui.Grid(ui.fill_all, row=3, column=3, 
                content = {
                    (2, 2): ui.Label("Nevu UI", (50%ui.vw, 33%ui.vh))
                }))
        super().__init__(window, menu)

app = MyApp()
app.run()