About Menus
There are a few workarounds here as well. Commands that expect an image as parameter must first save the corresponding images in slots or they must be created with an assigned name.
For storing in slots there are the commands:
Integer ImageToSlot0(slot, agk_img_id as Integer, x as Float, y as Float, w as Float, h as Float)
Integer ImageToSlot1(slot as Integer, agk_img_id as Integer)
For the name assignment are the commands:
Integer ImageCreate(name as String, agk_img_id as Integer, x as float, y as float, w as float, h as float)
Integer ImageCreate(name as String, agk_img_id as Integer)
Function overview (Plugin - .DLL/.SO)
- MenubarBegin()
- MenubarEnd()
- Integer MenuBeginText(title as String, len as Integer, align nk_flags, width as Float, height as Float)
- Integer MenuBeginLabel(label as String, align as Integer, width as Float, height as Float)
- Integer MenuBeginImage(id as String, image_slot as Integer, width as Float, height as Float)
- Integer MenuBeginImage(id as String, image_name as String, width as Float, height as Float)
- Integer MenuBeginImageText(title as String, len as Integer, align as Integer, image_slot as Integer, width as Float, height as Float)
- Integer MenuBeginImageText(title as String, len as Integer, align as Integer, image_name as String, width as Float, height as Float)
- Integer MenuBeginImageLabel(title as String, align nk_flags, image_slot as Integer, width as Float, height as Float)
- Integer MenuBeginImageLabel(title as String, align nk_flags, image_name as String, width as Float, height as Float)
- Integer MenuBeginSymbol(id as String, sym as Integer, width as Float, height as Float)
- Integer MenuBeginSymbolText(title as String, len as Integer, align as Integer, sym as Integer, width as Float, height as Float)
- Integer MenuBeginSymbolLabel(title as String, align as Integer, sym as Integer, width as Float, height as Float)
- Integer MenuItemText(title as String, len as Integer, align as Integer)
- Integer MenuItemLabel(label as String, align as Integer)
- Integer MenuItemImageLabel(image_slot as Integer, label as String, align as Integer)
- Integer MenuItemImageLabel(image_name as String, label as String, align as Integer)
- Integer MenuItemImageText(image_slot as Integer, text as String, len as Integer, align as Integer)
- Integer MenuItemImageText(image_name as String, text as String, len as Integer, align as Integer)
- Integer MenuItemSymbolText(sym as Integer, text as String, len as Integer, align as Integer)
- Integer MenuItemSymbolLabel(sym as Integer, label as String, align as Integer)
- MenuClose()
- MenuEnd()
Parameter (Plugin)
- Title, label
Title of the menu item to be displayed.
- len
Length of the title in characters.
- align
Alignment of the text.
- width
Width of the panel.
- height
Height of the panel.
- id
String id of the item. Serves for identification (internal).
- image_slot
A previously created image slot.
- image_name
A previously created association to an image.
- sym
A Symbol from the symbol table.
Symbol constant
NK_SYMBOL_NONE
NK_SYMBOL_X
NK_SYMBOL_UNDERSCORE
NK_SYMBOL_CIRCLE_SOLID
NK_SYMBOL_CIRCLE_OUTLINE
NK_SYMBOL_RECT_SOLID
NK_SYMBOL_RECT_OUTLINE
NK_SYMBOL_TRIANGLE_UP
NK_SYMBOL_TRIANGLE_DOWN
NK_SYMBOL_TRIANGLE_LEFT
NK_SYMBOL_TRIANGLE_RIGHT
NK_SYMBOL_PLUS
NK_SYMBOL_MINUS
NK_SYMBOL_MAX
The commands
Menu...Text and
Menu...Label do not differ in their functionality. With the Label variant only the length of the title is removed. So it is also the preferred command for creating menus.
Previous topic (About Layouts & Groups) ———— Table of contents ———— Next topic (About Trees)
Example:
#option_explicit
#import_plugin Nuklear as nk
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Nuklear Window" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 0, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
#insert "../Nuklear.agc"
// basic nuklear initialization
nkInit()
show_menu as Integer = nk_true
overwrite as Integer = nk_false
usage as float = 768.25
max_mem as float = 1024
show_as_mb as integer = nk_true
global chart_values as float[13]
chart_range as float = 300
// begin main loop
do
// pass agk inputs to nuklear
nk.HandleInput()
// Get the mouse data to display in a chartwidget
GetMouseMoveData()
// open a window
if nk.WindowBegin("Window", 20, 50, 600, 540, NK_WINDOW_BORDER||NK_WINDOW_MOVABLE||NK_WINDOW_TITLE||NK_WINDOW_CLOSABLE||NK_WINDOW_NO_SCROLLBAR)
if show_menu
// Start of the menubar
nk.MenubarBegin()
// First menu to display common menu items
// The menu bar is also a panel that can contain all kinds of
// widgets. Therefore widgets must be inserted in a layout.
// We have 3 menu entries with a menu bar size of 25 px.
nk.LayoutRowBegin(NK_STATIC, 25, 3)
// The first menubar item is 45px width.
nk.LayoutRowPush(45)
// Start of the menubar item. MenuBeginLabel' opens a panel,
// in this case 120px width and 150px height. 'File' is the
// title of the item and 'NK_TEXT_CENTERED' is the alignment
// of the title.
if(nk.MenuBeginLabel("File", NK_TEXT_CENTERED, 120, 150))
// Since a panel has been opened, the widgets must be
// added to a layout.
nk.LayoutRowDynamic(25, 1)
// Now the individual menu items for 'File' follow.
// These are simple items. The last one with the
// function to leave the main loop to end the program.
nk.MenuItemLabel("New", NK_TEXT_LEFT)
nk.MenuItemLabel("Open", NK_TEXT_LEFT)
nk.MenuItemLabel("Save", NK_TEXT_LEFT)
nk.MenuItemLabel("Close", NK_TEXT_LEFT)
if nk.MenuItemLabel("Exit", NK_TEXT_LEFT) then exit
// End of the first menubar item.
nk.MenuEnd()
endif
// Now follows the second menubar item.
nk.LayoutRowPush(45)
if(nk.MenuBeginLabel("Edit", NK_TEXT_CENTERED, 150, 300))
nk.LayoutRowDynamic(25, 1)
nk.MenuItemLabel("Copy", NK_TEXT_LEFT)
nk.MenuItemLabel("Delete", NK_TEXT_LEFT)
nk.MenuItemLabel("Cut", NK_TEXT_LEFT)
nk.MenuItemLabel("Paste", NK_TEXT_LEFT)
// Insert a label as seperator.
nk.Label("~~~~~~~~~~~~~~~~~~~~~", NK_TEXT_CENTERED)
// Remember: The 'MenuBegin...' command opens a panel and
// the all items can be a widgets. Here you see how to
// insert a checkox, Progressbar, Slider and option widgets.
overwrite = nk.CheckboxLabel("Overwrite", overwrite)
nk.LayoutRowDynamic(25, 2)
nk.Progress(usage, max_mem, NK_FIXED)
if show_as_mb
nk.Label(str(usage,2)+" MB", NK_TEXT_LEFT)
else
nk.Label(str((usage/max_mem)*100,2)+" %", NK_TEXT_LEFT)
endif
nk.LayoutRowDynamic(25, 1)
max_mem = nk.SliderFloat(usage, max_mem, 2048, 64)
if nk.OptionLabel("Show as MegByte", show_as_mb) then show_as_mb = nk_true
if nk.OptionLabel("Show as Percent", 1 - show_as_mb) then show_as_mb = nk_false
// End of the first menubar item.
nk.MenuEnd()
endif
// The third menubar item. Here you can see a chart widget
// with live data. The procedure is the same as for the last
// menu item.
nk.LayoutRowPush(45)
if(nk.MenuBeginLabel("Data", NK_TEXT_CENTERED, 400, 300))
nk.LayoutRowDynamic(25, 1)
nk.Label("Move Mouse", NK_TEXT_CENTERED)
nk.LayoutRowDynamic(100,1)
nk.ChartBegin(NK_CHART_LINES, chart_values.length, 0, chart_range)
i as integer
for i=0 to chart_values.length
nk.ChartPush(chart_values[i])
next
nk.ChartEnd()
nk.LayoutRowBegin(NK_DYNAMIC, 25, 3)
nk.LayoutRowPush(0.1)
nk.Label("range:", NK_TEXT_LEFT)
nk.LayoutRowPush(0.8)
chart_range = nk.SliderFloat(100, chart_range, 700, 1.0)
nk.LayoutRowPush(0.1)
nk.Label(str(chart_range, 0), NK_TEXT_LEFT)
nk.LayoutRowDynamic(25, 1)
nk.MenuItemLabel("Save Data", NK_TEXT_LEFT)
nk.MenuEnd()
endif
nk.MenubarEnd()
endif
endif
nk.WindowEnd()
if nk.WindowIsClosed("Window") then exit
nkSync()
loop
// Create mouse movement data. It calculates the average mouse movement
// distance every 200ms and stores it in a global variable (chart_values).
function GetMouseMoveData()
global dist as float
global updt as integer
now as integer
x as float
y as float
x = nk.InputGetMouseDeltaX()
y = nk.InputGetMouseDeltaY()
dist = dist + Sqrt(x * x + y * y)
now = GetMilliseconds()
if now > updt
updt = now + 200
i as integer
for i=0 to chart_values.length-1
chart_values[i] = chart_values[i+1]
next i
chart_values[chart_values.length] = dist
dist = Sqrt(x * x + y * y)
endif
endfunction