#import_plugin Nuklear as nk

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "Nuklear Window" )
SetWindowSize( 640, 480, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 640, 480 ) // 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()

num_columns as integer = 4
ratio as float[3] = [0.15,0.35,0.35,0.15]
do
	// pass agk inputs to nuklear
    nk.HandleInput()

	// open a window
	if nk.WindowBegin("Window", 20, 50, 600, 240, NK_WINDOW_BORDER||NK_WINDOW_MOVABLE||NK_WINDOW_TITLE||NK_WINDOW_SCALABLE||NK_WINDOW_MINIMIZABLE||NK_WINDOW_CLOSABLE)
		// define the layout. row height of 20 with 1 widget of dynamic width.
		nk.LayoutRowDynamic(20,1)
		// put  a widget in the first row
		nk.Label("drawing button grid (F1 - switch through number of columns)", NK_TEXT_CENTERED)
		
		// all next widgets have the same size from the defined layout.
		// each row with one widget. so that with each widget the number 
		// of rows grows.
		nk.Label("DYNAMIC", NK_TEXT_LEFT)
		
		// The layout is changed. The line height remains at 20 pixels, 
		// with a variable number of widgets in the row.
		nk.LayoutRowDynamic(20, num_columns)			
		i as integer
		// put twenty buttons in the layout
		for i=0 to 11
			nk.ButtonLabel("Button "+str(i))
		next

		// the layout is changed again. as above, except that the buttons 
		// are arranged statically.
		nk.LayoutRowDynamic(20,1)
		nk.Label("STATIC", NK_TEXT_LEFT)
		nk.LayoutRowStatic(20, 110, num_columns)
		for i=0 to 11
			nk.ButtonLabel("Button "+str(i))
		next
		
		
		// now a demonstration for ratio layouts.
		nk.LayoutRowDynamic(20,1)
		nk.Label("drawing a ratio layout (F2 - shuffle ratio)", NK_TEXT_CENTERED)
		nkLayoutRow(NK_DYNAMIC, 20, ratio)
		for i=0 to 3
			nk.ButtonLabel("Button "+str(trunc(ratio[i]*100))+"%")
		next i
	endif
	nk.WindowEnd()
	
	if nk.WindowIsClosed("Window") then exit

	// F1 - switch through number of columns
	if GetRawKeyPressed(112)
		if num_columns >= 4 then num_columns = 1 else inc num_columns,1
	endif

	// F2 - shuffle ratio
	if GetRawKeyPressed(113)
		percent as integer = 100
		value as integer

		value = Random(10, 50)
		ratio[0] = value / 100.0
		dec percent, value
		
		value = Random(10, (percent-20))
		ratio[1] = value / 100.0
		dec percent, value
		
		value = Random(10, (percent-10))
		ratio[2] = value / 100.0
		dec percent, value
		
		ratio[3] = percent / 100.0
	endif
    nkSync()
loop
