#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()

global boolean as string[1] = ["false","true"]
global collapse as integer = NK_MAXIMIZED
global window_open as integer = 1

do
	// pass agk inputs to nuklear
    nk.HandleInput()

	// check if the window should be displayed
	if window_open = 1
		// show our window
		if nk.WindowBegin("Window", 160, 50, 320, 240, NK_WINDOW_BORDER||NK_WINDOW_MOVABLE||NK_WINDOW_TITLE||NK_WINDOW_SCALABLE||NK_WINDOW_MINIMIZABLE||NK_WINDOW_CLOSABLE)
			window_bounds as nk_rect
			window_bounds = nkWindowGetBounds()
			
			nk.LayoutRowDynamic(20,1)
			nk.Label("window position:"+str(window_bounds.x)+","+str(window_bounds.y), NK_TEXT_LEFT)
			nk.Label("window size:"+str(window_bounds.w)+","+str(window_bounds.h), NK_TEXT_LEFT)
			nk.Label("window has focus:"+boolean[nk.WindowHasFocus()], NK_TEXT_LEFT)
			nk.Label("window is hovered:"+boolean[nk.WindowIsHovered()], NK_TEXT_LEFT)
			nk.Label("window is active:"+boolean[nk.WindowIsActive("Window")], NK_TEXT_LEFT)
		endif
		nk.WindowEnd()
	endif

	// get new collapse state
	if nk.WindowIsCollapsed("Window")
		collapse = NK_MINIMIZED
	else
		collapse = NK_MAXIMIZED
	endif

	// check if our window was closed
	window_open = nk.WindowIsClosed("Window") = 0
	
	// F1 - toggle the collape state
	if GetRawKeyPressed(112)
		collapse = 1 - collapse
		nk.WindowCollapse("Window", collapse)
	endif
	// F2 - bring back a closed window
	if GetRawKeyPressed(113) and window_open = 0 then window_open = 1

    nkSync()
loop
