#import_plugin Nuklear as nk

// show all errors
SetErrorMode(2)

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

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

// first images for the styles are loaded and set. 
nk.StyleMakeImage("button_normal", LoadImage("button_n.png"))
nk.StyleMakeImage("button_disabled", LoadImage("button_d.png"))

// now each of these style images is assigned to an item. As the entire 
// image is assigned to the item, the position of the section is set to 
// zero (0) and the width and height to minus one (-1) to indicate the 
// full width and height of the image.
nk.StyleMakeItem("item_btn_n"	,"button_normal"		,0,0,-1,-1)
nk.StyleMakeItem("item_btn_d"	,"button_disabled"		,0,0,-1,-1)

// weitere farbitems werden erstellt.
nk.StyleMakeItem("item_black"	,MakeColor(0,0,0))
nk.StyleMakeItem("item_white"	,MakeColor(255,255,255))
nk.StyleMakeItem("item_cyan"	,MakeColor(0,255,255))
nk.StyleMakeItem("item_red"		,MakeColor(255,0,0))

// here the styles are created. in the xml tags the properties of the 
// widgets are assigned to the newly created items.
// another way to set a style permanently is to change the widget properties 
// in context directly. This is done with the command StyleSetContextProperty. 
// This would look like this - 
// nk.StyleSetContextProperty("button", "normal", "item_btn_n")
nk.StyleMake("default_button", "<button normal='item_btn_n' hover='item_btn_n' active='item_btn_n' border='3' text_normal='item_black' text_hover='item_white' text_active='item_cyan'/>")
nk.StyleMake("disabled_button", "<button normal='item_btn_d' hover='item_btn_d' active='item_btn_d' text_normal='item_red' text_hover='item_red' text_active='item_red' />")

mode as Integer = 1

// for a temporary setting of the style i use here StylePush which stays 
// until StylePop is called. If several styles are pushed onto the stack, 
// the same amount of StylePop commands must be called.
// if you want a permanent change of the style, it is useful to use 
// StyleSetContext.
nk.StylePush("default_button")

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

	if nk.WindowBegin("Manipulate Context Style Part 2", 30, 50, 1220, 240, NK_WINDOW_BORDER||NK_WINDOW_MOVABLE||NK_WINDOW_TITLE)
		// layout for three buttons.
		nk.LayoutRowStatic(40, 260, 3)
		
		// set buttons to default style.
		if nk.ButtonLabel("Button Default") And mode = 1
			nk.StylePop()
			mode = 0
		endif
		
		// no matter which style is currently active this button uses 
		// its own style.
		nk.ButtonLabelStyled("disabled_button", "Button Inaktive")
		
		// set buttons to user style
		if nk.ButtonSymbolLabel(NK_SYMBOL_TRIANGLE_UP, "Button Style", NK_TEXT_CENTERED) And mode = 0
			nk.StylePush("default_button")
			mode = 1
		endif
		
	endif
	nk.WindowEnd()
	
    nkSync()
loop

// for clean end we must pop our style if needed.
if mode = 1 then nk.StylePop()
