Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NED, Tilemap Editor and NGUI Theme Editor were written in n7 using the ngui library. I just added the "widgets" and "containers" that I needed to this library as I created the editors. It may be hard to use if you've never worked with other gui libraries like IUP, Swing or WPF. But the principle is that you use containers to arrange widgets in different ways, you never position anything using exact coordinates. The library responds to window size changes by rearranging and resizing the containers and widgets. You can find the n7 source code of ngui in the N7/lib folder.

Here's a first example that creates some menus and labels.

' NGUI - Menus
' ------------


' This library is really large, so including it increases the compile time quite a bit.
include "ngui.n7"

' These will be explained later.
visible fruitLabel, gameLabel

' Create a resizable window.
set window "NGUI - Menus", 640, 480, false, 0
set redraw off

' Ngui uses containers to arrange widgets in different ways. The containers are widgets too.
' Every window needs a root widget, and it's usually a container. Here I create a vbox (vertical
' box), that aranges its children vertically. This will be the root widget of the window.

' A menubar contains one or more menus. A menu has a title, like "File", and a bunch of children,
' like "Open", "Save" and "Save as".
'  Create a menubar and add it to windowRoot.
menuBar = MenuBar()

' Create a menu. The parameter is a function that will be called every time the user selects
' something in the menu. The function FruitMenuCallback is defined later in this program.
fruitMenu = Menu(FruitMenuCallback)
' Add some items to fruitMenu. The second parameter can be used to display something to the right
' of a menu item, usually a keyboard shortcut such as "Ctrl+N", but let's just skip that.
fruitMenu.Add("Banana", unset)
fruitMenu.Add("Apple", unset)
fruitMenu.Add("Pear", unset)
' Add fruitMenu to menuBar, the first parameter is the menu title.
menuBar.Add("Fruits", fruitMenu)

' Create another menu with another callback function.
gameMenu = Menu(GameMenuCallback)
gameMenu.Add("Crap's Adventure", unset)
gameMenu.Add("Bulb Boy", unset)
gameMenu.Add("Farmer Man", unset)
gameMenu.Add("Robowack", unset)
menuBar.Add("Games", gameMenu)

' Create another vbox and add it to the root.
' Make this vbox center its children.
' Add some text widgets to the vbox
vbox.Add(Header("Menus are super fun!", SIZE_AUTO, SIZE_AUTO))
vbox.Add(Label("Select stuff in the menus and things will happen", SIZE_AUTO, SIZE_AUTO))
' Add a filler, just empty space, of height 16.
vbox.Add(Filler(SIZE_AUTO, 16))
' Add two more labels, that will be modified from the menu callback functions.
fruitLabel = Label("No fruit selected", SIZE_AUTO, SIZE_AUTO)
gameLabel = Label("No game selected", SIZE_AUTO, SIZE_AUTO)

' Enter main loop with windowRoot as root widget. From here on all action goes through the callback
' functions.

' Callback function for the fruit menu.
function FruitMenuCallback(menu, index)
    select index
        case 0  fruitLabel.SetText("I know how to spell banananananana but not when to quit")
        case 1  fruitLabel.SetText("APPLE!!!")
        case 2  fruitLabel.SetText("I don't remember what the third fruit was, sorry ...")
        default  fruitLabel.SetText("Undefined fruit encountered")

' Callback function for the game menu.
function GameMenuCallback(menu, index)
    select index
        case 0, 1  gameLabel.SetText("You selected a platform game")
        case 2  gameLabel.SetText("You selected a pacman clone")
        case 3  gameLabel.SetText("You selected a first person shooter")

Attached Files
.n7   menus.n7 (Size: 3.31 KB / Downloads: 7)

Messages In This Thread
NGUI - by Marcus - 11-19-2022, 07:01 AM
RE: NGUI - by Marcus - 11-19-2022, 08:27 AM
RE: NGUI - by Marcus - 11-19-2022, 11:09 AM
RE: NGUI - by Marcus - 11-19-2022, 01:52 PM
RE: NGUI - by johnno1956 - 11-20-2022, 03:48 AM
RE: NGUI - by Marcus - 11-26-2022, 08:24 AM

Forum Jump:

Users browsing this thread: 1 Guest(s)