// widget colors
#constant NK_COLOR_TEXT						= 0
#constant NK_COLOR_WINDOW					= 1
#constant NK_COLOR_HEADER					= 2
#constant NK_COLOR_BORDER					= 3
#constant NK_COLOR_BUTTON					= 4
#constant NK_COLOR_BUTTON_HOVER				= 5
#constant NK_COLOR_BUTTON_ACTIVE			= 6
#constant NK_COLOR_TOGGLE					= 7
#constant NK_COLOR_TOGGLE_HOVER				= 8
#constant NK_COLOR_TOGGLE_CURSOR			= 9
#constant NK_COLOR_SELECT					= 10
#constant NK_COLOR_SELECT_ACTIVE			= 11
#constant NK_COLOR_SLIDER					= 12
#constant NK_COLOR_SLIDER_CURSOR			= 13
#constant NK_COLOR_SLIDER_CURSOR_HOVER		= 14
#constant NK_COLOR_SLIDER_CURSOR_ACTIVE		= 15
#constant NK_COLOR_PROPERTY					= 16
#constant NK_COLOR_EDIT						= 17
#constant NK_COLOR_EDIT_CURSOR				= 18
#constant NK_COLOR_COMBO					= 19
#constant NK_COLOR_CHART					= 20
#constant NK_COLOR_CHART_COLOR				= 21
#constant NK_COLOR_CHART_COLOR_HIGHLIGHT	= 22
#constant NK_COLOR_SCROLLBAR				= 23
#constant NK_COLOR_SCROLLBAR_CURSOR			= 24
#constant NK_COLOR_SCROLLBAR_CURSOR_HOVER	= 25
#constant NK_COLOR_SCROLLBAR_CURSOR_ACTIVE	= 26
#constant NK_COLOR_TAB_HEADER				= 27
#constant NK_COLOR_COUNT					= 27

// window flags
#constant	NK_WINDOW_BORDER			= 0x000001
#constant	NK_WINDOW_MOVABLE           = 0x000002
#constant	NK_WINDOW_SCALABLE          = 0x000004
#constant	NK_WINDOW_CLOSABLE          = 0x000008
#constant	NK_WINDOW_MINIMIZABLE       = 0x000010
#constant	NK_WINDOW_NO_SCROLLBAR      = 0x000020
#constant	NK_WINDOW_TITLE             = 0x000040
#constant	NK_WINDOW_SCROLL_AUTO_HIDE  = 0x000080
#constant	NK_WINDOW_BACKGROUND        = 0x000100
#constant	NK_WINDOW_SCALE_LEFT        = 0x000200
#constant	NK_WINDOW_NO_INPUT          = 0x000400
#constant	NK_WINDOW_PRIVATE       	= 0x000800
#constant	NK_WINDOW_DYNAMIC      	 	= 0x000800		// NK_WINDOW_PRIVATE
#constant	NK_WINDOW_ROM           	= 0x001000
#constant	NK_WINDOW_NOT_INTERACTIVE 	= 0x001400		// NK_WINDOW_ROM||NK_WINDOW_NO_INPUT
#constant	NK_WINDOW_HIDDEN        	= 0x002000
#constant	NK_WINDOW_CLOSED        	= 0x004000
#constant	NK_WINDOW_MINIMIZED     	= 0x008000
#constant	NK_WINDOW_REMOVE_ROM    	= 0x010000

// layout format
#constant	NK_DYNAMIC			        = 0
#constant	NK_STATIC          			= 1

// buttons
#constant	NK_BUTTON_LEFT				= 0
#constant	NK_BUTTON_MIDDLE			= 1
#constant	NK_BUTTON_RIGHT				= 2
#constant	NK_BUTTON_DOUBLE			= 3
#constant	NK_BUTTON_MAX				= 4

// collapse states
#constant	NK_MINIMIZED				= 0
#constant	NK_MAXIMIZED				= 1

// show states
#constant	NK_HIDDEN					= 0
#constant	NK_SHOWN					= 1

// bool
#constant	NK_FALSE					= 0
#constant	NK_TRUE						= 1

// symbol types
#constant	NK_SYMBOL_NONE				= 0
#constant	NK_SYMBOL_X					= 1
#constant	NK_SYMBOL_UNDERSCORE		= 2
#constant	NK_SYMBOL_CIRCLE_SOLID		= 3
#constant	NK_SYMBOL_CIRCLE_OUTLINE	= 4
#constant	NK_SYMBOL_RECT_SOLID		= 5
#constant	NK_SYMBOL_RECT_OUTLINE		= 6
#constant	NK_SYMBOL_TRIANGLE_UP	 	= 7
#constant	NK_SYMBOL_TRIANGLE_DOWN		= 8
#constant	NK_SYMBOL_TRIANGLE_LEFT		= 9
#constant	NK_SYMBOL_TRIANGLE_RIGHT	= 10
#constant	NK_SYMBOL_PLUS				= 11
#constant	NK_SYMBOL_MINUS				= 12
#constant	NK_SYMBOL_MAX				= 13

// cursor styles
#constant	NK_CURSOR_ARROW 						= 0
#constant	NK_CURSOR_TEXT 							= 1
#constant	NK_CURSOR_MOVE 							= 2
#constant	NK_CURSOR_RESIZE_VERTICAL 				= 3
#constant	NK_CURSOR_RESIZE_HORIZONTAL 			= 4
#constant	NK_CURSOR_RESIZE_TOP_LEFT_DOWN_RIGHT 	= 5
#constant	NK_CURSOR_RESIZE_TOP_RIGHT_DOWN_LEFT 	= 6

// text alignment
#constant	NK_TEXT_ALIGN_LEFT        	= 0x01
#constant	NK_TEXT_ALIGN_CENTERED    	= 0x02
#constant	NK_TEXT_ALIGN_RIGHT       	= 0x04
#constant	NK_TEXT_ALIGN_TOP         	= 0x08
#constant	NK_TEXT_ALIGN_MIDDLE      	= 0x10
#constant	NK_TEXT_ALIGN_BOTTOM      	= 0x20
#constant	NK_TEXT_LEFT        		= 0x11		// NK_TEXT_ALIGN_MIDDLE||NK_TEXT_ALIGN_LEFT
#constant	NK_TEXT_CENTERED    		= 0x12		// NK_TEXT_ALIGN_MIDDLE||NK_TEXT_ALIGN_CENTERED
#constant	NK_TEXT_RIGHT       		= 0x14		// NK_TEXT_ALIGN_MIDDLE||NK_TEXT_ALIGN_RIGHT

// modify
#constant	NK_FIXED 					= 0
#constant	NK_MODIFIABLE 				= 1

// tree type
#constant	NK_TREE_NODE				0
#constant	NK_TREE_TAB					1

// chart type
#constant	NK_CHART_LINES				= 0
#constant	NK_CHART_COLUMN				= 1
#constant	NK_CHART_MAX				= 2

// button behavior
#constant	NK_BUTTON_DEFAULT			= 0
#constant	NK_BUTTON_REPEATER			= 1

// popup type
#constant	NK_POPUP_STATIC				= 0
#constant	NK_POPUP_DYNAMIC			= 1

// color format
#constant	NK_RGB						= 0
#constant	NK_RGBA						= 1

// chart event
#constant	NK_CHART_HOVERING 			= 0x01
#constant	NK_CHART_CLICKED 			= 0x02

// edit filter
#constant	NK_FILTER_DEFAULT			= 0
#constant	NK_FILTER_ASCII				= 1
#constant	NK_FILTER_FLOAT				= 2
#constant	NK_FILTER_DECIMAL			= 3
#constant	NK_FILTER_HEX				= 4
#constant	NK_FILTER_OCT				= 5
#constant	NK_FILTER_BINARY			= 6

// edit flags
#constant	NK_EDIT_DEFAULT                 = 0x0000
#constant	NK_EDIT_READ_ONLY               = 0x0001
#constant	NK_EDIT_AUTO_SELECT             = 0x0002
#constant	NK_EDIT_SIG_ENTER               = 0x0004
#constant	NK_EDIT_ALLOW_TAB               = 0x0008
#constant	NK_EDIT_NO_CURSOR               = 0x0010
#constant	NK_EDIT_SELECTABLE              = 0x0020
#constant	NK_EDIT_CLIPBOARD               = 0x0040
#constant	NK_EDIT_CTRL_ENTER_NEWLINE      = 0x0080
#constant	NK_EDIT_NO_HORIZONTAL_SCROLL    = 0x0100
#constant	NK_EDIT_ALWAYS_INSERT_MODE      = 0x0200
#constant	NK_EDIT_MULTILINE               = 0x0400
#constant	NK_EDIT_GOTO_END_ON_ACTIVATE    = 0x0800

// edit types
#constant	NK_EDIT_SIMPLE  				= 0x0200
#constant	NK_EDIT_FIELD   				= 0x0260
#constant	NK_EDIT_BOX     				= 0x0668
#constant	NK_EDIT_EDITOR  				= 0x0468

// edit events
#constant	NK_EDIT_ACTIVE      			= 0x01	/* edit widget is currently being modified */
#constant	NK_EDIT_INACTIVE    			= 0x02	/* edit widget is not active and is not being modified */
#constant	NK_EDIT_ACTIVATED   			= 0x04 	/* edit widget went from state inactive to state active */
#constant	NK_EDIT_DEACTIVATED 			= 0x08 	/* edit widget went from state active to state inactive */
#constant	NK_EDIT_COMMITED    			= 0x10 	/* edit widget has received an enter and lost focus */

#constant	NK_KEY_NONE						= 0
#constant	NK_KEY_SHIFT					= 1
#constant	NK_KEY_CTRL						= 2
#constant	NK_KEY_DEL						= 3
#constant	NK_KEY_ENTER					= 4
#constant	NK_KEY_TAB						= 5
#constant	NK_KEY_BACKSPACE				= 6
#constant	NK_KEY_COPY						= 7
#constant	NK_KEY_CUT						= 8
#constant	NK_KEY_PASTE					= 9
#constant	NK_KEY_UP						= 10
#constant	NK_KEY_DOWN						= 11
#constant	NK_KEY_LEFT						= 12
#constant	NK_KEY_RIGHT					= 13
    /* Shortcuts: text field */
#constant	NK_KEY_TEXT_INSERT_MODE			= 14
#constant	NK_KEY_TEXT_REPLACE_MODE		= 15
#constant	NK_KEY_TEXT_RESET_MODE			= 16
#constant	NK_KEY_TEXT_LINE_START			= 17
#constant	NK_KEY_TEXT_LINE_END			= 18
#constant	NK_KEY_TEXT_START				= 19
#constant	NK_KEY_TEXT_END					= 20
#constant	NK_KEY_TEXT_UNDO				= 21
#constant	NK_KEY_TEXT_REDO				= 22
#constant	NK_KEY_TEXT_SELECT_ALL			= 23
#constant	NK_KEY_TEXT_WORD_LEFT			= 24
#constant	NK_KEY_TEXT_WORD_RIGHT			= 25
    /* Shortcuts: scrollbar */
#constant	NK_KEY_SCROLL_START				= 26
#constant	NK_KEY_SCROLL_END				= 27
#constant	NK_KEY_SCROLL_DOWN				= 28
#constant	NK_KEY_SCROLL_UP				= 29
#constant	NK_KEY_MAX						= 30
// widget layout states
#constant	NK_WIDGET_INVALID				= 0		/* The widget cannot be seen and is completely out of view */
#constant	NK_WIDGET_VALID					= 1		/* The widget is completely inside the window and can be updated and drawn */
#constant	NK_WIDGET_ROM					= 2		/* The widget is partially visible and cannot be updated */
// widget item types
#constant NK_ITEMTYPE_COLOR					= 0
#constant NK_ITEMTYPE_IMAGE					= 1
#constant NK_ITEMTYPE_PATCH9				= 2
// widget property types
#constant NK_PROPERTYTYPE_UNKNOWN			= 0
#constant NK_PROPERTYTYPE_ITEM				= 1
#constant NK_PROPERTYTYPE_VEC2				= 2
#constant NK_PROPERTYTYPE_FLOAT				= 3
#constant NK_PROPERTYTYPE_INTEGER			= 4

//widget types
#constant NK_WIDGETTYPE_UNKNOWN			= 0
#constant NK_WIDGETTYPE_FONT			= 1
#constant NK_WIDGETTYPE_CURSORS			= 2
#constant NK_WIDGETTYPE_TEXT			= 3
#constant NK_WIDGETTYPE_BUTTON			= 4
#constant NK_WIDGETTYPE_CONTEXT_BUTTON	= 5
#constant NK_WIDGETTYPE_MENU_BUTTON		= 6
#constant NK_WIDGETTYPE_CHECKBOX		= 7
#constant NK_WIDGETTYPE_OPTION			= 8
#constant NK_WIDGETTYPE_TOGGLE			= 7
#constant NK_WIDGETTYPE_SELECTABLE		= 9
#constant NK_WIDGETTYPE_SLIDER			= 10
#constant NK_WIDGETTYPE_PROGRESS		= 11
#constant NK_WIDGETTYPE_PROPERTY		= 12
#constant NK_WIDGETTYPE_EDIT			= 13
#constant NK_WIDGETTYPE_CHART			= 14
#constant NK_WIDGETTYPE_SCROLLV			= 15
#constant NK_WIDGETTYPE_SCROLLH			= 16
#constant NK_WIDGETTYPE_SCROLLBAR		= 15
#constant NK_WIDGETTYPE_TAB				= 17
#constant NK_WIDGETTYPE_COMBO			= 18
#constant NK_WIDGETTYPE_WINDOW			= 19
#constant NK_WIDGETTYPE_WINDOW_HEADER	= 20
#constant NK_WIDGETTYPE_COUNT			= 20

#constant NK_GLYPHRANGE_DEFAULT		= 0
#constant NK_GLYPHRANGE_CHINESE		= 1
#constant NK_GLYPHRANGE_CYRILLIC		= 2
#constant NK_GLYPHRANGE_KOREAN		= 3
#constant NK_GLYPHRANGE_JAPANESE		= 4
#constant NK_GLYPHRANGE_GREEK			= 5

type nk_vec2
	x as float
	y as float
endtype
function nk_vec2(x as float, y as float)
	result as nk_vec2
	result.x = x
	result.y = y
endfunction result
function nkVec2FromMemblock(out ref as nk_vec2, memID as integer, offset as integer)
    out.x = GetMemblockFloat(memID,  offset): inc offset,4
    out.y = GetMemblockFloat(memID,  offset): inc offset,4
endfunction offset
function nkVec2ToMemblock(vec2 ref as nk_vec2, memID as integer, offset as integer)
    SetMemblockFloat(memID,  offset, vec2.x): inc offset,4
    SetMemblockFloat(memID,  offset, vec2.y): inc offset,4
endfunction offset

type nk_color
	r as integer
	g as integer
	b as integer
	a as integer
endtype
function nkColorFromMemblock(out ref as nk_color, memID as integer, offset as integer)
	out.r = GetMemblockByte(memID, offset): Inc offset,1
	out.g = GetMemblockByte(memID, offset): Inc offset,1
	out.b = GetMemblockByte(memID, offset): Inc offset,1
	out.a = GetMemblockByte(memID, offset): Inc offset,1
endfunction offset
function nkColorToMemblock(color ref as nk_color, memID as integer, offset as integer)
	SetMemblockByte(memID, offset, color.r): Inc offset,1
	SetMemblockByte(memID, offset, color.g): Inc offset,1
	SetMemblockByte(memID, offset, color.b): Inc offset,1
	SetMemblockByte(memID, offset, color.a): Inc offset,1
endfunction offset
function nkRGB(r as integer, g as integer, b as integer)
	result as nk_color
	result.r = r
	result.g = g
	result.b = b
	result.a = 255
endfunction result
function nkRGBA(r as integer, g as integer, b as integer, a as integer)
	result as nk_color
	result.r = r
	result.g = g
	result.b = b
	result.a = a
endfunction result

type nk_colorf
	r as float
	g as float
	b as float
	a as float
endtype
function nkRGBf(r as float, g as float, b as float)
	result as nk_colorf
	result.r = r
	result.g = g
	result.b = b
	result.a = 255
endfunction result
function nkRGBAf(r as float, g as float, b as float, a as float)
	result as nk_colorf
	result.r = r
	result.g = g
	result.b = b
	result.a = a
endfunction result

type nk_image
	img_id as integer
	w as integer
	h as integer
	region as integer[3]
endtype
function nkImageFromMemblock(out ref as nk_image, memID as integer, offset as integer)
	//~ if nk_ctx.arch64
		//~ out.img_id = GetMemblockInt(memID, offset+4): Inc offset,nk_ctx.skip_id
	//~ else
		out.img_id = GetMemblockInt(memID, offset): Inc offset,nk_ctx.skip_id
	//~ endif
	out.w = GetMemblockShort(memID, offset): Inc offset,2
	out.h = GetMemblockShort(memID, offset): Inc offset,2
	out.region[0] = GetMemblockShort(memID, offset): Inc offset,2
	out.region[1] = GetMemblockShort(memID, offset): Inc offset,2
	out.region[2] = GetMemblockShort(memID, offset): Inc offset,2
	out.region[3] = GetMemblockShort(memID, offset): Inc offset,2
endfunction offset
function nkImageToMemblock(image ref as nk_image, memID as integer, offset as integer)
	//~ if nk_ctx.arch64
		//~ SetMemblockInt(memID, offset+4, image.img_id): Inc offset,nk_ctx.skip_id
	//~ else
		SetMemblockInt(memID, offset, image.img_id): Inc offset,nk_ctx.skip_id
	//~ endif
	SetMemblockShort(memID, offset, image.w): Inc offset,2
	SetMemblockShort(memID, offset, image.h): Inc offset,2
	SetMemblockShort(memID, offset, image.region[0]): Inc offset,2
	SetMemblockShort(memID, offset, image.region[1]): Inc offset,2
	SetMemblockShort(memID, offset, image.region[2]): Inc offset,2
	SetMemblockShort(memID, offset, image.region[3]): Inc offset,2
endfunction offset
function nkImageFromPatch9(patch9 as nk_patch9)
	result as nk_image
	result.img_id = patch9.img_id
	result.w = patch9.w
	result.h = patch9.h
	result.region = patch9.region
endfunction result

type nk_patch9
	img_id as integer
	w as integer
	h as integer
	region as integer[3]
	border as float[3]
endtype
function nkPatch9FromMemblock(out ref as nk_patch9, memID as integer, offset as integer)
	//~ if nk_ctx.arch64
		//~ out.img_id = GetMemblockInt(memID, offset+4): Inc offset,nk_ctx.skip_id
	//~ else
		out.img_id = GetMemblockInt(memID, offset): Inc offset,nk_ctx.skip_id
	//~ endif
	out.w = GetMemblockShort(memID, offset): Inc offset,2
	out.h = GetMemblockShort(memID, offset): Inc offset,2
	out.region[0] = GetMemblockShort(memID, offset): Inc offset,2
	out.region[1] = GetMemblockShort(memID, offset): Inc offset,2
	out.region[2] = GetMemblockShort(memID, offset): Inc offset,2
	out.region[3] = GetMemblockShort(memID, offset): Inc offset,2
	out.border[0] = GetMemblockFloat(memID, offset): Inc offset,4
	out.border[1] = GetMemblockFloat(memID, offset): Inc offset,4
	out.border[2] = GetMemblockFloat(memID, offset): Inc offset,4
	out.border[3] = GetMemblockFloat(memID, offset): Inc offset,4
endfunction offset
function nkPatch9ToMemblock(patch9 ref as nk_patch9, memID as integer, offset as integer)
	//~ if nk_ctx.arch64
		//~ SetMemblockInt(memID, offset+4, patch9.img_id): Inc offset,nk_ctx.skip_id
	//~ else
		SetMemblockInt(memID, offset, patch9.img_id): Inc offset,nk_ctx.skip_id
	//~ endif
	SetMemblockShort(memID, offset, patch9.w): Inc offset,2
	SetMemblockShort(memID, offset, patch9.h): Inc offset,2
	SetMemblockShort(memID, offset, patch9.region[0]): Inc offset,2
	SetMemblockShort(memID, offset, patch9.region[1]): Inc offset,2
	SetMemblockShort(memID, offset, patch9.region[2]): Inc offset,2
	SetMemblockShort(memID, offset, patch9.region[3]): Inc offset,2
	SetMemblockFloat(memID, offset, patch9.border[0]): Inc offset,4
	SetMemblockFloat(memID, offset, patch9.border[1]): Inc offset,4
	SetMemblockFloat(memID, offset, patch9.border[2]): Inc offset,4
	SetMemblockFloat(memID, offset, patch9.border[3]): Inc offset,4
endfunction offset

type nk_style_item
	typ as integer
	color as nk_color
	image as nk_image
	patch9 as nk_patch9
endtype
function nk_style_item()
	result as nk_style_item
endfunction result
function nkItemFromMemblock(out ref as nk_style_item, memID as integer, offset as integer)
	out.typ = GetMemblockInt(memID, offset)
	select out.typ
		case NK_ITEMTYPE_COLOR: nkColorFromMemblock(out.color, memID, offset+nk_ctx.skip_id)	:	endcase
		case NK_ITEMTYPE_IMAGE: nkImageFromMemblock(out.image, memID, offset+nk_ctx.skip_id)	:	endcase
		case NK_ITEMTYPE_PATCH9: nkPatch9FromMemblock(out.patch9, memID, offset+nk_ctx.skip_id):	endcase
	endselect
	Inc offset,nk_ctx.item_size
endfunction offset
function nkItemToMemblock(item ref as nk_style_item, memID as integer, offset as integer)
	SetMemblockInt(memID,  offset, item.typ)
	select item.typ
		case NK_ITEMTYPE_COLOR: nkColorToMemblock(item.color, memID, offset+nk_ctx.skip_id)	:	endcase
		case NK_ITEMTYPE_IMAGE: nkImageToMemblock(item.image, memID, offset+nk_ctx.skip_id)	:	endcase
		case NK_ITEMTYPE_PATCH9: nkPatch9ToMemblock(item.patch9, memID, offset+nk_ctx.skip_id):	endcase
	endselect
	Inc offset,nk_ctx.item_size
endfunction offset

type nk_rect
	x as float
	y as float
	w as float
	h as float
endtype
function nk_rect(x as float, y as float, w as float, h as float)
	result as nk_rect
	result.x = x
	result.y = y
	result.w = w
	result.h = h
endfunction result
function nkRectFromMemblock(out ref as nk_rect, memID as integer, offset as integer)
	out.x = GetMemblockFloat(memID, offset): Inc offset,4
	out.y = GetMemblockFloat(memID, offset): Inc offset,4
	out.w = GetMemblockFloat(memID, offset): Inc offset,4
	out.h = GetMemblockFloat(memID, offset): Inc offset,4
endfunction offset
function nkRectToMemblock(rect ref as nk_rect, memID as integer, offset as integer)
	SetMemblockFloat(memID, offset, rect.x): Inc offset,4
	SetMemblockFloat(memID, offset, rect.y): Inc offset,4
	SetMemblockFloat(memID, offset, rect.w): Inc offset,4
	SetMemblockFloat(memID, offset, rect.h): Inc offset,4
endfunction offset






/* ---------------------------------------------------------------------
	Style Text
*/
type nk_style_text
    color as nk_color
    padding as nk_vec2
endtype
function nk_style_text(memID as integer)
	result as nk_style_text
	nkStyleSetTextFromMemblock(result, memID, 0)
endfunction result
function nkStyleSetTextFromMemblock(out ref as nk_style_text, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

    offset = nkColorFromMemblock(out.color, memID, offset)
    offset = nkVec2FromMemblock(out.padding, memID, offset)
endfunction offset
function nkStyleSetTextToMemblock(widget as nk_style_text, memID as integer, offset as integer)
    if GetMemblockExists(memID) = 0 then exitfunction offset

    offset = nkColorToMemblock(widget.color, memID, offset)
    offset = nkVec2ToMemblock(widget.padding, memID, offset)
endfunction offset
/* -------------------------------------------------------------------*/



/* ---------------------------------------------------------------------
	Style Button
*/
type nk_style_button
    /* background */
    normal as nk_style_item
    hover as nk_style_item
    active as nk_style_item
    border_color as nk_color   // color

    /* text */
    text_background as nk_color    // color
    text_normal as nk_color        // color
    text_hover as nk_color         // color
    text_active as nk_color        // color
    text_alignment as integer     // flag

    /* properties */
    border as float
    rounding as float
    padding as nk_vec2
    image_padding as nk_vec2
    touch_padding as nk_vec2
endtype
function nk_style_button(memID as integer)
	result as nk_style_button
	nkStyleSetButtonFromMemblock(result, memID, 0)
endfunction result
function nkStyleSetButtonFromMemblock(out ref as nk_style_button, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemFromMemblock(out.normal, memID, offset)
	offset = nkItemFromMemblock(out.hover, memID, offset)
	offset = nkItemFromMemblock(out.active, memID, offset)
	offset = nkColorFromMemblock(out.border_color, memID, offset)

	offset = nkColorFromMemblock(out.text_background, memID, offset)
	offset = nkColorFromMemblock(out.text_normal, memID, offset)
	offset = nkColorFromMemblock(out.text_hover, memID, offset)
	offset = nkColorFromMemblock(out.text_active, memID, offset)
    out.text_alignment = GetMemblockInt(memID,  offset): Inc offset,4

    out.border = GetMemblockFloat(memID,  offset): Inc offset,4
    out.rounding = GetMemblockFloat(memID,  offset): Inc offset,4
    offset = nkVec2FromMemblock(out.padding, memID, offset)
    offset = nkVec2FromMemblock(out.image_padding, memID, offset)
    offset = nkVec2FromMemblock(out.touch_padding, memID, offset)

    // skip user data
    Inc offset,(3*nk_ctx.skip_id)
endfunction offset
function nkStyleSetButtonToMemblock(button ref as nk_style_button, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemToMemblock(button.normal, memID, offset)
	offset = nkItemToMemblock(button.hover, memID, offset)
	offset = nkItemToMemblock(button.active, memID, offset)
	offset = nkColorToMemblock(button.border_color, memID, offset)

	offset = nkColorToMemblock(button.text_background, memID, offset)
	offset = nkColorToMemblock(button.text_normal, memID, offset)
	offset = nkColorToMemblock(button.text_hover, memID, offset)
	offset = nkColorToMemblock(button.text_active, memID, offset)
    SetMemblockInt(memID,  offset, button.text_alignment): Inc offset,4

    SetMemblockFloat(memID,  offset, button.border): Inc offset,4
    SetMemblockFloat(memID,  offset, button.rounding): Inc offset,4
    offset = nkVec2ToMemblock(button.padding, memID, offset)
    offset = nkVec2ToMemblock(button.image_padding, memID, offset)
    offset = nkVec2ToMemblock(button.touch_padding, memID, offset)

    // skip user data
    Inc offset,(3*nk_ctx.skip_id)
endfunction offset
function nkButtonImage(img ref as nk_image)
	result as integer
	nkImageToMemblock(img, nk_mem_interface,0)
	result = nk.ButtonMemblockImage(nk_mem_interface)
endfunction result
/* ------------------------------------------------------------------ */



/* ---------------------------------------------------------------------
	toggle
*/
type nk_style_toggle
    /* background */
    normal as  nk_style_item
    hover as  nk_style_item
    active as  nk_style_item
    border_color as  nk_color

    /* cursor */
    cursor_normal as  nk_style_item
    cursor_hover as  nk_style_item

    /* text */
    text_normal as  nk_color
    text_hover as  nk_color
    text_active as  nk_color
    text_background as nk_color
    text_alignment as integer

    /* properties */
    padding as  nk_vec2
    touch_padding as  nk_vec2
    spacing as float
    border as float
endtype
function nk_style_toggle(memID as integer)
	result as nk_style_toggle
	nkStyleSetToggleFromMemblock(result, memID, 0)
endfunction result
function nkStyleSetToggleFromMemblock(out ref as nk_style_toggle, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemFromMemblock(out.normal, memID, offset)
	offset = nkItemFromMemblock(out.hover, memID, offset)
	offset = nkItemFromMemblock(out.active, memID, offset)
	offset = nkColorFromMemblock(out.border_color, memID, offset)

	if nk_ctx.arch64 then Inc offset,4
    offset = nkItemFromMemblock(out.cursor_normal, memID, offset)
	offset = nkItemFromMemblock(out.cursor_hover, memID, offset)

	offset = nkColorFromMemblock(out.text_normal, memID, offset)
	offset = nkColorFromMemblock(out.text_hover, memID, offset)
	offset = nkColorFromMemblock(out.text_active, memID, offset)
    offset = nkColorFromMemblock(out.text_background, memID, offset)
    out.text_alignment = GetMemblockInt(memID,  offset): Inc offset,4

    offset = nkVec2FromMemblock(out.padding, memID, offset)
    offset = nkVec2FromMemblock(out.touch_padding, memID, offset)

    out.spacing = GetMemblockFloat(memID,  offset): Inc offset,4
    out.border = GetMemblockFloat(memID,  offset): Inc offset,4

    // skip user data
    Inc offset,3*nk_ctx.skip_id
endfunction offset
function nkStyleSetToggleToMemblock(toggle ref as nk_style_toggle, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemToMemblock(toggle.normal, memID, offset)
	offset = nkItemToMemblock(toggle.hover, memID, offset)
	offset = nkItemToMemblock(toggle.active, memID, offset)
	offset = nkColorToMemblock(toggle.border_color, memID, offset)

	if nk_ctx.arch64 then Inc offset,4
    offset = nkItemToMemblock(toggle.cursor_normal, memID, offset)
	offset = nkItemToMemblock(toggle.cursor_hover, memID, offset)

	offset = nkColorToMemblock(toggle.text_normal, memID, offset)
	offset = nkColorToMemblock(toggle.text_hover, memID, offset)
	offset = nkColorToMemblock(toggle.text_active, memID, offset)
    offset = nkColorToMemblock(toggle.text_background, memID, offset)
    SetMemblockInt(memID,  offset, toggle.text_alignment): Inc offset,4

    offset = nkVec2ToMemblock(toggle.padding, memID, offset)
    offset = nkVec2ToMemblock(toggle.touch_padding, memID, offset)

    SetMemblockFloat(memID,  offset, toggle.spacing): Inc offset,4
    SetMemblockFloat(memID,  offset, toggle.border): Inc offset,4

	// msg as string
	// msg = "typ:"+str(Style.ctx.checkbox.cursor_normal.typ)+LF
	// msg = msg+"w,h:"+str(Style.ctx.checkbox.cursor_normal.patch9.w)+","+str(Style.ctx.checkbox.cursor_normal.patch9.h)+LF
	// msg = msg+"region:"+str(Style.ctx.checkbox.cursor_normal.patch9.region[0])+"-"+str(Style.ctx.checkbox.cursor_normal.patch9.region[1])+"-"+str(Style.ctx.checkbox.cursor_normal.patch9.region[2])+"-"+str(Style.ctx.checkbox.cursor_normal.patch9.region[3])
	// msg = msg+"border:"+str(Style.ctx.checkbox.cursor_normal.patch9.border[0])+"-"+str(Style.ctx.checkbox.cursor_normal.patch9.border[1])+"-"+str(Style.ctx.checkbox.cursor_normal.patch9.border[2])+"-"+str(Style.ctx.checkbox.cursor_normal.patch9.border[3])
	// Message(msg)

    // skip user data
    Inc offset,3*nk_ctx.skip_id
endfunction offset
/* ------------------------------------------------------------------ */


/* ---------------------------------------------------------------------
	selectable
*/
type nk_style_selectable
    /* background (inactive) */
    normal as nk_style_item
    hover as  nk_style_item
    pressed as  nk_style_item

    /* background (active) */
    normal_active as  nk_style_item
    hover_active as  nk_style_item
    pressed_active as nk_style_item

    /* text color (inactive) */
    text_normal as  nk_color
    text_hover as  nk_color
    text_pressed as  nk_color

    /* text color (active) */
    text_normal_active as nk_color
    text_hover_active as nk_color
    text_pressed_active as nk_color
    text_background as nk_color
    text_alignment as integer

    /* properties */
    rounding as float
    padding as nk_vec2
    touch_padding as nk_vec2
    image_padding as nk_vec2
endtype
function nk_style_selectable(memID as integer)
	result as nk_style_selectable
	nkStyleSetSelectableFromMemblock(result, memID, 0)
endfunction result
function nkStyleSetSelectableFromMemblock(out ref as nk_style_selectable, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset
	offset = nkItemFromMemblock(out.normal, memID, offset)
	offset = nkItemFromMemblock(out.hover, memID, offset)
	offset = nkItemFromMemblock(out.pressed, memID, offset)

    offset = nkItemFromMemblock(out.normal_active, memID, offset)
	offset = nkItemFromMemblock(out.hover_active, memID, offset)
	offset = nkItemFromMemblock(out.pressed_active, memID, offset)

    offset = nkColorFromMemblock(out.text_normal, memID, offset)
	offset = nkColorFromMemblock(out.text_hover, memID, offset)
	offset = nkColorFromMemblock(out.text_pressed, memID, offset)

    offset = nkColorFromMemblock(out.text_normal_active, memID, offset)
	offset = nkColorFromMemblock(out.text_hover_active, memID, offset)
	offset = nkColorFromMemblock(out.text_pressed_active, memID, offset)
    offset = nkColorFromMemblock(out.text_background, memID, offset)
    out.text_alignment = GetMemblockInt(memID,  offset): Inc offset,4

    out.rounding = GetMemblockFloat(memID,  offset): Inc offset,4
    offset = nkVec2FromMemblock(out.padding, memID, offset)
    offset = nkVec2FromMemblock(out.touch_padding, memID, offset)
    offset = nkVec2FromMemblock(out.image_padding, memID, offset)

    // skip user data
    Inc offset,3*nk_ctx.skip_id
	if nk_ctx.arch64 then Inc offset,4
endfunction offset
function nkStyleSetSelectableToMemblock(selectable ref as nk_style_selectable, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemToMemblock(selectable.normal, memID, offset)
	offset = nkItemToMemblock(selectable.hover, memID, offset)
	offset = nkItemToMemblock(selectable.pressed, memID, offset)

    offset = nkItemToMemblock(selectable.normal_active, memID, offset)
	offset = nkItemToMemblock(selectable.hover_active, memID, offset)
	offset = nkItemToMemblock(selectable.pressed_active, memID, offset)

    offset = nkColorToMemblock(selectable.text_normal, memID, offset)
	offset = nkColorToMemblock(selectable.text_hover, memID, offset)
	offset = nkColorToMemblock(selectable.text_pressed, memID, offset)

    offset = nkColorToMemblock(selectable.text_normal_active, memID, offset)
	offset = nkColorToMemblock(selectable.text_hover_active, memID, offset)
	offset = nkColorToMemblock(selectable.text_pressed_active, memID, offset)
    offset = nkColorToMemblock(selectable.text_background, memID, offset)
    SetMemblockInt(memID,  offset, selectable.text_alignment): Inc offset,4

    SetMemblockFloat(memID,  offset, selectable.rounding): Inc offset,4
    offset = nkVec2ToMemblock(selectable.padding, memID, offset)
    offset = nkVec2ToMemblock(selectable.touch_padding, memID, offset)
    offset = nkVec2ToMemblock(selectable.image_padding, memID, offset)

   // skip user data
    Inc offset,3*nk_ctx.skip_id
	if nk_ctx.arch64 then Inc offset,4
endfunction offset
/* ------------------------------------------------------------------ */



/* ---------------------------------------------------------------------
	progress
*/
type nk_style_progress
    /* background */
    normal as nk_style_item
    hover as nk_style_item
    active as nk_style_item
    border_color as nk_color

    /* cursor */
    cursor_normal as nk_style_item
    cursor_hover as nk_style_item
    cursor_active as nk_style_item
    cursor_border_color as nk_color

    /* properties */
    rounding as float
    border as float
    cursor_border as float
    cursor_rounding as float
    padding as nk_vec2
endtype
function nk_style_progress(memID as integer)
	result as nk_style_progress
	nkStyleSetProgressFromMemblock(result, memID, 0)
endfunction result
function nkStyleSetProgressFromMemblock(out ref as nk_style_progress, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemFromMemblock(out.normal, memID, offset)
	offset = nkItemFromMemblock(out.hover, memID, offset)
	offset = nkItemFromMemblock(out.active, memID, offset)
	offset = nkColorFromMemblock(out.border_color, memID, offset)
	if nk_ctx.arch64 then Inc offset,4

	offset = nkItemFromMemblock(out.cursor_normal, memID, offset)
	offset = nkItemFromMemblock(out.cursor_hover, memID, offset)
	offset = nkItemFromMemblock(out.cursor_active, memID, offset)
    offset = nkColorFromMemblock(out.cursor_border_color, memID, offset)

    out.rounding = GetMemblockFloat(memID,  offset): Inc offset,4
    out.border = GetMemblockFloat(memID,  offset): Inc offset,4
    out.cursor_border = GetMemblockFloat(memID,  offset): Inc offset,4
    out.cursor_rounding = GetMemblockFloat(memID,  offset): Inc offset,4
    offset = nkVec2FromMemblock(out.padding, memID, offset)

    // skip user data
    Inc offset,3*nk_ctx.skip_id
endfunction offset
function nkStyleSetProgressToMemblock(progress ref as nk_style_progress, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

    offset = nkItemToMemblock(progress.normal, memID, offset)
	offset = nkItemToMemblock(progress.hover, memID, offset)
	offset = nkItemToMemblock(progress.active, memID, offset)
	offset = nkColorToMemblock(progress.border_color, memID, offset)
	if nk_ctx.arch64 then Inc offset,4

	offset = nkItemToMemblock(progress.cursor_normal, memID, offset)
	offset = nkItemToMemblock(progress.cursor_hover, memID, offset)
	offset = nkItemToMemblock(progress.cursor_active, memID, offset)
    offset = nkColorToMemblock(progress.cursor_border_color, memID, offset)

    SetMemblockFloat(memID,  offset, progress.rounding): Inc offset,4
    SetMemblockFloat(memID,  offset, progress.border): Inc offset,4
    SetMemblockFloat(memID,  offset, progress.cursor_border): Inc offset,4
    SetMemblockFloat(memID,  offset, progress.cursor_rounding): Inc offset,4
    offset = nkVec2ToMemblock(progress.padding, memID, offset)

    // skip user data
    Inc offset,3*nk_ctx.skip_id
	if nk_ctx.arch64 then Inc offset,4
endfunction offset
/* ------------------------------------------------------------------ */


/* ---------------------------------------------------------------------
	chart
*/
type nk_style_chart
    /* colors */
    background as nk_style_item
    border_color as nk_color
    selected_color as nk_color
    color as nk_color

    /* properties */
    border as float
    rounding as float
    padding as nk_vec2
endtype
function nk_style_chart(memID as integer)
	result as nk_style_chart
	nkStyleSetChartFromMemblock(result, memID, 0)
endfunction result
function nkStyleSetChartFromMemblock(out ref as nk_style_chart, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemFromMemblock(out.background, memID, offset)
    offset = nkColorFromMemblock(out.border_color, memID, offset)
	offset = nkColorFromMemblock(out.selected_color, memID, offset)
    offset = nkColorFromMemblock(out.color, memID, offset)

    out.border = GetMemblockFloat(memID,  offset): Inc offset,4
    out.rounding = GetMemblockFloat(memID,  offset): Inc offset,4
    offset = nkVec2FromMemblock(out.padding, memID, offset)
	if nk_ctx.arch64 then Inc offset,4
endfunction offset
function nkStyleSetChartToMemblock(chart ref as nk_style_chart, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

    offset = nkItemToMemblock(chart.background, memID, offset)
    offset = nkColorToMemblock(chart.border_color, memID, offset)
	offset = nkColorToMemblock(chart.selected_color, memID, offset)
    offset = nkColorToMemblock(chart.color, memID, offset)

    SetMemblockFloat(memID,  offset, chart.border): Inc offset,4
    SetMemblockFloat(memID,  offset, chart.rounding): Inc offset,4
    offset = nkVec2ToMemblock(chart.padding, memID, offset)
	if nk_ctx.arch64 then Inc offset,4
endfunction offset
/* ------------------------------------------------------------------ */



/* ---------------------------------------------------------------------
	combo
*/
type nk_style_combo
    /* background */
    normal as nk_style_item
    hover as nk_style_item
    active as nk_style_item
    border_color as nk_color

    /* label */
    label_normal as nk_color
    label_hover as nk_color
    label_active as nk_color

    /* symbol */
    symbol_normal as nk_color
    symbol_hover as nk_color
    symbol_active as nk_color

    /* button */
    button as nk_style_button
    sym_normal as integer
    sym_hover as integer
    sym_active as integer

    /* properties */
    border as float
    rounding as float
    content_padding as nk_vec2
    button_padding as nk_vec2
    spacing as nk_vec2
endtype
function nk_style_combo(memID as integer)
	result as nk_style_combo
	nkStyleSetComboFromMemblock(result, memID, 0)
endfunction result
function nkStyleSetComboFromMemblock(out ref as nk_style_combo, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemFromMemblock(out.normal, memID, offset)
	offset = nkItemFromMemblock(out.hover, memID, offset)
	offset = nkItemFromMemblock(out.active, memID, offset)
	offset = nkColorFromMemblock(out.border_color, memID, offset)

	offset = nkColorFromMemblock(out.label_normal, memID, offset)
	offset = nkColorFromMemblock(out.label_hover, memID, offset)
	offset = nkColorFromMemblock(out.label_active, memID, offset)

	offset = nkColorFromMemblock(out.symbol_normal, memID, offset)
	offset = nkColorFromMemblock(out.symbol_hover, memID, offset)
	offset = nkColorFromMemblock(out.symbol_active, memID, offset)

	if nk_ctx.arch64 then Inc offset,4
    offset = nkStyleSetButtonFromMemblock(out.button, memID, offset)
    out.sym_normal = GetMemblockInt(memID,  offset): Inc offset,4
    out.sym_hover = GetMemblockInt(memID,  offset): Inc offset,4
    out.sym_active = GetMemblockInt(memID,  offset): Inc offset,4

    out.border = GetMemblockFloat(memID,  offset): Inc offset,4
    out.rounding = GetMemblockFloat(memID,  offset): Inc offset,4
    offset = nkVec2FromMemblock(out.content_padding, memID, offset)
    offset = nkVec2FromMemblock(out.button_padding, memID, offset)
    offset = nkVec2FromMemblock(out.spacing, memID, offset)
	if nk_ctx.arch64 then Inc offset,4
endfunction offset
function nkStyleSetComboToMemblock(combo ref as nk_style_combo, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

    offset = nkItemToMemblock(combo.normal, memID, offset)
	offset = nkItemToMemblock(combo.hover, memID, offset)
	offset = nkItemToMemblock(combo.active, memID, offset)
	offset = nkColorToMemblock(combo.border_color, memID, offset)

	offset = nkColorToMemblock(combo.label_normal, memID, offset)
	offset = nkColorToMemblock(combo.label_hover, memID, offset)
	offset = nkColorToMemblock(combo.label_active, memID, offset)

	offset = nkColorToMemblock(combo.symbol_normal, memID, offset)
	offset = nkColorToMemblock(combo.symbol_hover, memID, offset)
	offset = nkColorToMemblock(combo.symbol_active, memID, offset)

	if nk_ctx.arch64 then Inc offset,4
    offset = nkStyleSetButtonToMemblock(combo.button, memID, offset)
    SetMemblockInt(memID,  offset, combo.sym_normal): Inc offset,4
    SetMemblockInt(memID,  offset, combo.sym_hover): Inc offset,4
    SetMemblockInt(memID,  offset, combo.sym_active): Inc offset,4

    SetMemblockFloat(memID,  offset, combo.border): Inc offset,4
    SetMemblockFloat(memID,  offset, combo.rounding): Inc offset,4
    offset = nkVec2ToMemblock(combo.content_padding, memID, offset)
    offset = nkVec2ToMemblock(combo.button_padding, memID, offset)
    offset = nkVec2ToMemblock(combo.spacing, memID, offset)
	if nk_ctx.arch64 then Inc offset,4
endfunction offset

function nkComboArray(array ref as string[], sel as integer, item_height as integer, panel_width as integer, panel_height as integer)
	if nk.ComboBeginLabel(array[sel], panel_width, panel_height)
		nk.LayoutRowDynamic(item_height,1)
		i as integer
		for i=0 to array.length
			if nk.ComboItemLabel(array[i], NK_TEXT_LEFT) then sel = i
		next
		nk.ComboEnd()
	endif
endfunction sel
/* ------------------------------------------------------------------ */



/* ---------------------------------------------------------------------
	slider
*/
type nk_style_slider
    /* background */
    normal as nk_style_item
    hover as nk_style_item
    active as nk_style_item
    border_color as nk_color

    /* background bar */
    bar_normal as nk_color
    bar_hover as nk_color
    bar_active as nk_color
    bar_filled as nk_color

    /* cursor */
    cursor_normal as nk_style_item
    cursor_hover as nk_style_item
    cursor_active as nk_style_item

    /* properties */
    border as float
    rounding as float
    bar_height as float
    padding as nk_vec2
    spacing as nk_vec2
    cursor_size as nk_vec2

    /* optional buttons */
    show_buttons as integer
    inc_button as nk_style_button
    dec_button as nk_style_button
    inc_symbol as integer
    dec_symbol as integer
endtype
function nk_style_slider(memID as integer)
	result as nk_style_slider
	nkStyleSetSliderFromMemblock(result, memID, 0)
endfunction result
function nkStyleSetSliderFromMemblock(out ref as nk_style_slider, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemFromMemblock(out.normal, memID, offset)
	offset = nkItemFromMemblock(out.hover, memID, offset)
	offset = nkItemFromMemblock(out.active, memID, offset)
	offset = nkColorFromMemblock(out.border_color, memID, offset)

	offset = nkColorFromMemblock(out.bar_normal, memID, offset)
	offset = nkColorFromMemblock(out.bar_hover, memID, offset)
    offset = nkColorFromMemblock(out.bar_active, memID, offset)
    offset = nkColorFromMemblock(out.bar_filled, memID, offset)

	if nk_ctx.arch64 then Inc offset,4
    offset = nkItemFromMemblock(out.cursor_normal, memID, offset)
	offset = nkItemFromMemblock(out.cursor_hover, memID, offset)
	offset = nkItemFromMemblock(out.cursor_active, memID, offset)

    out.border = GetMemblockFloat(memID,  offset): Inc offset,4
    out.rounding = GetMemblockFloat(memID,  offset): Inc offset,4
    out.bar_height = GetMemblockFloat(memID,  offset): Inc offset,4
    offset = nkVec2FromMemblock(out.padding, memID, offset)
    offset = nkVec2FromMemblock(out.spacing, memID, offset)
    offset = nkVec2FromMemblock(out.cursor_size, memID, offset)

    out.show_buttons = GetMemblockInt(memID,  offset): Inc offset,4
    offset = nkStyleSetButtonFromMemblock(out.inc_button, memID, offset)
    offset = nkStyleSetButtonFromMemblock(out.dec_button, memID, offset)
    out.inc_symbol = GetMemblockInt(memID,  offset): Inc offset,4
    out.dec_symbol = GetMemblockInt(memID,  offset): Inc offset,4

    // skip user data
    Inc offset,3*nk_ctx.skip_id
endfunction offset
function nkStyleSetSliderToMemblock(slider ref as nk_style_slider, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

    offset = nkItemToMemblock(slider.normal, memID, offset)
	offset = nkItemToMemblock(slider.hover, memID, offset)
	offset = nkItemToMemblock(slider.active, memID, offset)
	offset = nkColorToMemblock(slider.border_color, memID, offset)

	offset = nkColorToMemblock(slider.bar_normal, memID, offset)
	offset = nkColorToMemblock(slider.bar_hover, memID, offset)
    offset = nkColorToMemblock(slider.bar_active, memID, offset)
    offset = nkColorToMemblock(slider.bar_filled, memID, offset)

	if nk_ctx.arch64 then Inc offset,4
    offset = nkItemToMemblock(slider.cursor_normal, memID, offset)
	offset = nkItemToMemblock(slider.cursor_hover, memID, offset)
	offset = nkItemToMemblock(slider.cursor_active, memID, offset)

    SetMemblockFloat(memID,  offset, slider.border): Inc offset,4
    SetMemblockFloat(memID,  offset, slider.rounding): Inc offset,4
    SetMemblockFloat(memID,  offset, slider.bar_height): Inc offset,4
    offset = nkVec2ToMemblock(slider.padding, memID, offset)
    offset = nkVec2ToMemblock(slider.spacing, memID, offset)
    offset = nkVec2ToMemblock(slider.cursor_size, memID, offset)

    SetMemblockInt(memID,  offset, slider.show_buttons): Inc offset,4
    offset = nkStyleSetButtonToMemblock(slider.inc_button, memID, offset)
    offset = nkStyleSetButtonToMemblock(slider.dec_button, memID, offset)
    SetMemblockInt(memID,  offset, slider.inc_symbol): Inc offset,4
    SetMemblockInt(memID,  offset, slider.dec_symbol): Inc offset,4

    // skip user data
    Inc offset,3*nk_ctx.skip_id
endfunction offset
/* ------------------------------------------------------------------ */



/* ---------------------------------------------------------------------
	scrollbar
*/
type nk_style_scrollbar
    /* background */
    normal as nk_style_item
    hover as nk_style_item
    active as nk_style_item
    border_color as nk_color

    /* cursor */
    cursor_normal as nk_style_item
    cursor_hover as nk_style_item
    cursor_active as nk_style_item
    cursor_border_color as nk_color

    /* properties */
    border as float
    rounding as float
    border_cursor as float
    rounding_cursor as float
    padding as nk_vec2

    /* optional buttons */
    show_buttons as integer
    inc_button as nk_style_button
    dec_button as nk_style_button
    inc_symbol as integer
    dec_symbol as integer
endtype
function nk_style_scrollbar(memID as integer)
	result as nk_style_scrollbar
	nkStyleSetScrollbarFromMemblock(result, memID, 0)
endfunction result
function nkStyleSetScrollbarFromMemblock(out ref as nk_style_scrollbar, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemFromMemblock(out.normal, memID, offset)
	offset = nkItemFromMemblock(out.hover, memID, offset)
	offset = nkItemFromMemblock(out.active, memID, offset)
	offset = nkColorFromMemblock(out.border_color, memID, offset)
	if nk_ctx.arch64 then Inc offset,4

	offset = nkItemFromMemblock(out.cursor_normal, memID, offset)
	offset = nkItemFromMemblock(out.cursor_hover, memID, offset)
	offset = nkItemFromMemblock(out.cursor_active, memID, offset)
    offset = nkColorFromMemblock(out.cursor_border_color, memID, offset)

    out.border = GetMemblockFloat(memID,  offset): Inc offset,4
    out.rounding = GetMemblockFloat(memID,  offset): Inc offset,4
    out.border_cursor = GetMemblockFloat(memID,  offset): Inc offset,4
    out.rounding_cursor = GetMemblockFloat(memID,  offset): Inc offset,4
    offset = nkVec2FromMemblock(out.padding, memID, offset)

    out.show_buttons = GetMemblockInt(memID,  offset): Inc offset,4
    offset = nkStyleSetButtonFromMemblock(out.inc_button, memID, offset)
    offset = nkStyleSetButtonFromMemblock(out.dec_button, memID, offset)
    out.inc_symbol = GetMemblockInt(memID,  offset): Inc offset,4
    out.dec_symbol = GetMemblockInt(memID,  offset): Inc offset,4

    // skip user data
    Inc offset,3*nk_ctx.skip_id
endfunction offset
function nkStyleSetScrollbarToMemblock(scrollbar ref as nk_style_scrollbar, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

    offset = nkItemToMemblock(scrollbar.normal, memID, offset)
	offset = nkItemToMemblock(scrollbar.hover, memID, offset)
	offset = nkItemToMemblock(scrollbar.active, memID, offset)
	offset = nkColorToMemblock(scrollbar.border_color, memID, offset)
	if nk_ctx.arch64 then Inc offset,4

	offset = nkItemToMemblock(scrollbar.cursor_normal, memID, offset)
	offset = nkItemToMemblock(scrollbar.cursor_hover, memID, offset)
	offset = nkItemToMemblock(scrollbar.cursor_active, memID, offset)
    offset = nkColorToMemblock(scrollbar.cursor_border_color, memID, offset)

    SetMemblockFloat(memID,  offset, scrollbar.border): Inc offset,4
    SetMemblockFloat(memID,  offset, scrollbar.rounding): Inc offset,4
    SetMemblockFloat(memID,  offset, scrollbar.border_cursor): Inc offset,4
    SetMemblockFloat(memID,  offset, scrollbar.rounding_cursor): Inc offset,4
    offset = nkVec2ToMemblock(scrollbar.padding, memID, offset)

    SetMemblockInt(memID,  offset, scrollbar.show_buttons): Inc offset,4
    offset = nkStyleSetButtonToMemblock(scrollbar.inc_button, memID, offset)
    offset = nkStyleSetButtonToMemblock(scrollbar.dec_button, memID, offset)
    SetMemblockInt(memID,  offset, scrollbar.inc_symbol): Inc offset,4
    SetMemblockInt(memID,  offset, scrollbar.dec_symbol): Inc offset,4

    // skip user data
    Inc offset,3*nk_ctx.skip_id
endfunction offset
/* ------------------------------------------------------------------ */



/* ---------------------------------------------------------------------
	edit
*/
type nk_style_edit
    /* background */
    normal as nk_style_item
    hover as nk_style_item
    active as nk_style_item
    border_color as nk_color
    scrollbar as nk_style_scrollbar

    /* cursor  */
    cursor_normal as nk_color
    cursor_hover as nk_color
    cursor_text_normal as nk_color
    cursor_text_hover as nk_color

    /* text (unselected) */
    text_normal as nk_color
    text_hover as nk_color
    text_active as nk_color

    /* text (selected) */
    selected_normal as nk_color
    selected_hover as nk_color
    selected_text_normal as nk_color
    selected_text_hover as nk_color

    /* properties */
    border as float
    rounding as float
    cursor_size as float
    scrollbar_size as nk_vec2
    padding as nk_vec2
    row_padding as float
endtype
function nk_style_edit(memID as integer)
	result as nk_style_edit
	nkStyleSetEditFromMemblock(result, memID, 0)
endfunction result
function nkStyleSetEditFromMemblock(out ref as nk_style_edit, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemFromMemblock(out.normal, memID, offset)
	offset = nkItemFromMemblock(out.hover, memID, offset)
	offset = nkItemFromMemblock(out.active, memID, offset)
	offset = nkColorFromMemblock(out.border_color, memID, offset)
	if nk_ctx.arch64 then Inc offset,4
    offset = nkStyleSetScrollbarFromMemblock(out.scrollbar, memID, offset)

    offset = nkColorFromMemblock(out.cursor_normal, memID, offset)
	offset = nkColorFromMemblock(out.cursor_hover, memID, offset)
    offset = nkColorFromMemblock(out.cursor_text_normal, memID, offset)
	offset = nkColorFromMemblock(out.cursor_text_hover, memID, offset)

    offset = nkColorFromMemblock(out.text_normal, memID, offset)
    offset = nkColorFromMemblock(out.text_hover, memID, offset)
    offset = nkColorFromMemblock(out.text_active, memID, offset)

    offset = nkColorFromMemblock(out.selected_normal, memID, offset)
	offset = nkColorFromMemblock(out.selected_hover, memID, offset)
    offset = nkColorFromMemblock(out.selected_text_normal, memID, offset)
	offset = nkColorFromMemblock(out.selected_text_hover, memID, offset)

    out.border = GetMemblockFloat(memID,  offset): Inc offset,4
    out.rounding = GetMemblockFloat(memID,  offset): Inc offset,4
    out.cursor_size = GetMemblockFloat(memID,  offset): Inc offset,4
    offset = nkVec2FromMemblock(out.scrollbar_size, memID, offset)
    offset = nkVec2FromMemblock(out.padding, memID, offset)
    out.row_padding = GetMemblockFloat(memID,  offset): Inc offset,4
	if nk_ctx.arch64 then Inc offset,4
endfunction offset
function nkStyleSetEditToMemblock(edit ref as nk_style_edit, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

    offset = nkItemToMemblock(edit.normal, memID, offset)
	offset = nkItemToMemblock(edit.hover, memID, offset)
	offset = nkItemToMemblock(edit.active, memID, offset)
	offset = nkColorToMemblock(edit.border_color, memID, offset)
	if nk_ctx.arch64 then Inc offset,4
    offset = nkStyleSetScrollbarToMemblock(edit.scrollbar, memID, offset)

    offset = nkColorToMemblock(edit.cursor_normal, memID, offset)
	offset = nkColorToMemblock(edit.cursor_hover, memID, offset)
    offset = nkColorToMemblock(edit.cursor_text_normal, memID, offset)
	offset = nkColorToMemblock(edit.cursor_text_hover, memID, offset)

    offset = nkColorToMemblock(edit.text_normal, memID, offset)
    offset = nkColorToMemblock(edit.text_hover, memID, offset)
    offset = nkColorToMemblock(edit.text_active, memID, offset)

    offset = nkColorToMemblock(edit.selected_normal, memID, offset)
	offset = nkColorToMemblock(edit.selected_hover, memID, offset)
    offset = nkColorToMemblock(edit.selected_text_normal, memID, offset)
	offset = nkColorToMemblock(edit.selected_text_hover, memID, offset)

    SetMemblockFloat(memID, offset, edit.border): Inc offset,4
    SetMemblockFloat(memID, offset, edit.rounding): Inc offset,4
    SetMemblockFloat(memID, offset, edit.cursor_size): Inc offset,4
    offset = nkVec2ToMemblock(edit.scrollbar_size, memID, offset)
    offset = nkVec2ToMemblock(edit.padding, memID, offset)
    SetMemblockFloat(memID,  offset, edit.row_padding): Inc offset,4
	if nk_ctx.arch64 then Inc offset,4
endfunction offset
/* ------------------------------------------------------------------ */



/* ---------------------------------------------------------------------
	property
*/
type nk_style_property
    /* background */
    normal as nk_style_item
    hover as nk_style_item
    active as nk_style_item
    border_color as nk_color

    /* text */
    label_normal as nk_color
    label_hover as nk_color
    label_active as nk_color

    /* symbols */
    sym_left as integer
    sym_right as integer

    /* properties */
    border as float
    rounding as float
    padding as nk_vec2

    edit as nk_style_edit
    inc_button as nk_style_button
    dec_button as nk_style_button
endtype
function nk_style_property(memID as integer)
	result as nk_style_property
	nkStyleSetPropertyFromMemblock(result, memID, 0)
endfunction result
function nkStyleSetPropertyFromMemblock(out ref as nk_style_property, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemFromMemblock(out.normal, memID, offset)
	offset = nkItemFromMemblock(out.hover, memID, offset)
	offset = nkItemFromMemblock(out.active, memID, offset)
	offset = nkColorFromMemblock(out.border_color, memID, offset)

    offset = nkColorFromMemblock(out.label_normal, memID, offset)
	offset = nkColorFromMemblock(out.label_hover, memID, offset)
    offset = nkColorFromMemblock(out.label_active, memID, offset)

    out.sym_left = GetMemblockInt(memID,  offset): Inc offset,4
    out.sym_right = GetMemblockInt(memID,  offset): Inc offset,4

    out.border = GetMemblockFloat(memID,  offset): Inc offset,4
    out.rounding = GetMemblockFloat(memID,  offset): Inc offset,4
    offset = nkVec2FromMemblock(out.padding, memID, offset)

    offset = nkStyleSetEditFromMemblock(out.edit, memID, offset)
    offset = nkStyleSetButtonFromMemblock(out.inc_button, memID, offset)
    offset = nkStyleSetButtonFromMemblock(out.dec_button, memID, offset)

    // skip user data
    Inc offset,3*nk_ctx.skip_id
endfunction offset
function nkStyleSetPropertyToMemblock(property ref as nk_style_property, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

    offset = nkItemToMemblock(property.normal, memID, offset)
	offset = nkItemToMemblock(property.hover, memID, offset)
	offset = nkItemToMemblock(property.active, memID, offset)
	offset = nkColorToMemblock(property.border_color, memID, offset)

    offset = nkColorToMemblock(property.label_normal, memID, offset)
	offset = nkColorToMemblock(property.label_hover, memID, offset)
    offset = nkColorToMemblock(property.label_active, memID, offset)

    SetMemblockInt(memID,  offset, property.sym_left): Inc offset,4
    SetMemblockInt(memID,  offset,property.sym_right): Inc offset,4

    SetMemblockFloat(memID,  offset, property.border): Inc offset,4
    SetMemblockFloat(memID,  offset, property.rounding): Inc offset,4
    offset = nkVec2ToMemblock(property.padding, memID, offset)

	//~ if nk_ctx.arch64 then Inc offset,4
    offset = nkStyleSetEditToMemblock(property.edit, memID, offset)
    offset = nkStyleSetButtonToMemblock(property.inc_button, memID, offset)
    offset = nkStyleSetButtonToMemblock(property.dec_button, memID, offset)

    // skip user data
    Inc offset,3*nk_ctx.skip_id
endfunction offset
/* ------------------------------------------------------------------ */



/* ---------------------------------------------------------------------
	tab
*/
type nk_style_tab
    /* background */
    background as nk_style_item
    border_color as nk_color
    text as nk_color

    /* button */
    tab_maximize_button as nk_style_button
    tab_minimize_button as nk_style_button
    node_maximize_button as nk_style_button
    node_minimize_button as nk_style_button
    sym_minimize as integer
    sym_maximize as integer

    /* properties */
    border as float
    rounding as float
    indent as float
    padding as nk_vec2
    spacing as nk_vec2
endtype
function nk_style_tab(memID as integer)
	result as nk_style_tab
	nkStyleSetTabFromMemblock(result, memID, 0)
endfunction result
function nkStyleSetTabFromMemblock(out ref as nk_style_tab, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemFromMemblock(out.background, memID, offset)
	offset = nkColorFromMemblock(out.border_color, memID, offset)
	offset = nkColorFromMemblock(out.text, memID, offset)

	offset = nkStyleSetButtonFromMemblock(out.tab_maximize_button, memID, offset)
	offset = nkStyleSetButtonFromMemblock(out.tab_minimize_button, memID, offset)
	offset = nkStyleSetButtonFromMemblock(out.node_maximize_button, memID, offset)
	offset = nkStyleSetButtonFromMemblock(out.node_minimize_button, memID, offset)
    out.sym_minimize = GetMemblockInt(memID, offset): Inc offset,4
    out.sym_maximize = GetMemblockInt(memID, offset): Inc offset,4

    out.border = GetMemblockFloat(memID, offset): Inc offset,4
    out.rounding = GetMemblockFloat(memID, offset): Inc offset,4
    out.indent = GetMemblockFloat(memID, offset): Inc offset,4
    offset = nkVec2FromMemblock(out.padding, memID, offset)
    offset = nkVec2FromMemblock(out.spacing, memID, offset)
endfunction offset
function nkStyleSetTabToMemblock(tab ref as nk_style_tab, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemToMemblock(tab.background, memID, offset)
	offset = nkColorToMemblock(tab.border_color, memID, offset)
	offset = nkColorToMemblock(tab.text, memID, offset)

	offset = nkStyleSetButtonToMemblock(tab.tab_maximize_button, memID, offset)
	offset = nkStyleSetButtonToMemblock(tab.tab_minimize_button, memID, offset)
	offset = nkStyleSetButtonToMemblock(tab.node_maximize_button, memID, offset)
	offset = nkStyleSetButtonToMemblock(tab.node_minimize_button, memID, offset)
    SetMemblockInt(memID, offset, tab.sym_minimize): Inc offset,4
    SetMemblockInt(memID, offset, tab.sym_maximize): Inc offset,4

    SetMemblockFloat(memID, offset, tab.border): Inc offset,4
    SetMemblockFloat(memID, offset, tab.rounding): Inc offset,4
    SetMemblockFloat(memID, offset, tab.indent): Inc offset,4
    offset = nkVec2ToMemblock(tab.padding, memID, offset)
    offset = nkVec2ToMemblock(tab.spacing, memID, offset)
endfunction offset
/* ------------------------------------------------------------------ */



/* ---------------------------------------------------------------------
	window header
*/
type nk_style_window_header
    /* background */
    normal as nk_style_item
    hover as nk_style_item
    active as nk_style_item

    /* button */
    close_button as nk_style_button
    minimize_button as nk_style_button
    close_symbol as integer
    minimize_symbol as integer
    maximize_symbol as integer

    /* title */
    label_normal as nk_color
    label_hover as nk_color
    label_active as nk_color

    /* properties */
    align as integer
    padding as nk_vec2
    label_padding as nk_vec2
    spacing as nk_vec2
endtype
function nk_style_window_header(memID as integer)
	result as nk_style_window_header
	nkStyleSetWindowHeaderFromMemblock(result, memID, 0)
endfunction result
function nkStyleSetWindowHeaderFromMemblock(out ref as nk_style_window_header, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemFromMemblock(out.normal, memID, offset)
	offset = nkItemFromMemblock(out.hover, memID, offset)
	offset = nkItemFromMemblock(out.active, memID, offset)

	offset = nkStyleSetButtonFromMemblock(out.close_button, memID, offset)
	offset = nkStyleSetButtonFromMemblock(out.minimize_button, memID, offset)
    out.close_symbol = GetMemblockInt(memID, offset): Inc offset,4
    out.minimize_symbol = GetMemblockInt(memID, offset): Inc offset,4
    out.maximize_symbol = GetMemblockInt(memID, offset): Inc offset,4

	offset = nkColorFromMemblock(out.label_normal, memID, offset)
	offset = nkColorFromMemblock(out.label_hover, memID, offset)
	offset = nkColorFromMemblock(out.label_active, memID, offset)

    out.align = GetMemblockInt(memID, offset): Inc offset,4
    offset = nkVec2FromMemblock(out.padding, memID, offset)
    offset = nkVec2FromMemblock(out.label_padding, memID, offset)
    offset = nkVec2FromMemblock(out.spacing, memID, offset)

	if nk_ctx.arch64 then Inc offset,4
endfunction offset
function nkStyleSetWindowHeaderToMemblock(window_header ref as nk_style_window_header, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkItemToMemblock(window_header.normal, memID, offset)
	offset = nkItemToMemblock(window_header.hover, memID, offset)
	offset = nkItemToMemblock(window_header.active, memID, offset)

	offset = nkStyleSetButtonToMemblock(window_header.close_button, memID, offset)
	offset = nkStyleSetButtonToMemblock(window_header.minimize_button, memID, offset)
    SetMemblockInt(memID, offset, window_header.close_symbol): Inc offset,4
    SetMemblockInt(memID, offset, window_header.minimize_symbol): Inc offset,4
    SetMemblockInt(memID, offset, window_header.maximize_symbol): Inc offset,4

	offset = nkColorToMemblock(window_header.label_normal, memID, offset)
	offset = nkColorToMemblock(window_header.label_hover, memID, offset)
	offset = nkColorToMemblock(window_header.label_active, memID, offset)

    SetMemblockInt(memID, offset, window_header.align): Inc offset,4
    offset = nkVec2ToMemblock(window_header.padding, memID, offset)
    offset = nkVec2ToMemblock(window_header.label_padding, memID, offset)
    offset = nkVec2ToMemblock(window_header.spacing, memID, offset)

	if nk_ctx.arch64 then Inc offset,4
endfunction offset
/* ------------------------------------------------------------------ */



/* ---------------------------------------------------------------------
	window
*/
type nk_style_window
    header as nk_style_window_header
    fixed_background as nk_style_item
    background as nk_color

    border_color as nk_color
    popup_border_color as nk_color
    combo_border_color as nk_color
    contextual_border_color as nk_color
    menu_border_color as nk_color
    group_border_color as nk_color
    tooltip_border_color as nk_color
    scaler as nk_style_item

	border as Float
	combo_border as Float
	contextual_border as Float
	menu_border as Float
	group_border as Float
	tooltip_border as Float
	popup_border as Float
	min_row_height_padding as Float

	rounding as Float
    spacing as nk_vec2
    scrollbar_size as nk_vec2
    min_size as nk_vec2

    padding as nk_vec2
    group_padding as nk_vec2
    popup_padding as nk_vec2
    combo_padding as nk_vec2
    contextual_padding as nk_vec2
    menu_padding as nk_vec2
    tooltip_padding as nk_vec2
endtype
function nk_style_window(memID as integer)
	result as nk_style_window
	nkStyleSetWindowFromMemblock(result, memID, 0)
endfunction result
function nkStyleSetWindowFromMemblock(out ref as nk_style_window, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkStyleSetWindowHeaderFromMemblock(out.header, memID, offset)
	offset = nkItemFromMemblock(out.fixed_background, memID, offset)
	offset = nkColorFromMemblock(out.background, memID, offset)

	offset = nkColorFromMemblock(out.border_color, memID, offset)
	offset = nkColorFromMemblock(out.popup_border_color, memID, offset)
	offset = nkColorFromMemblock(out.combo_border_color, memID, offset)
	offset = nkColorFromMemblock(out.contextual_border_color, memID, offset)
	offset = nkColorFromMemblock(out.menu_border_color, memID, offset)
	offset = nkColorFromMemblock(out.group_border_color, memID, offset)
	offset = nkColorFromMemblock(out.tooltip_border_color, memID, offset)
	offset = nkItemFromMemblock(out.scaler, memID, offset)

	out.border = GetMemblockFloat(memID, offset): Inc offset,4
	out.combo_border = GetMemblockFloat(memID, offset): Inc offset,4
	out.contextual_border = GetMemblockFloat(memID, offset): Inc offset,4
	out.menu_border = GetMemblockFloat(memID, offset): Inc offset,4
	out.group_border = GetMemblockFloat(memID, offset): Inc offset,4
	out.tooltip_border = GetMemblockFloat(memID, offset): Inc offset,4
	out.popup_border = GetMemblockFloat(memID, offset): Inc offset,4
	out.min_row_height_padding = GetMemblockFloat(memID, offset): Inc offset,4

	out.rounding = GetMemblockFloat(memID, offset): Inc offset,4
	offset = nkVec2FromMemblock(out.spacing, memID, offset)
	offset = nkVec2FromMemblock(out.scrollbar_size, memID, offset)
	offset = nkVec2FromMemblock(out.min_size, memID, offset)

	offset = nkVec2FromMemblock(out.padding, memID, offset)
	offset = nkVec2FromMemblock(out.group_padding, memID, offset)
	offset = nkVec2FromMemblock(out.popup_padding, memID, offset)
	offset = nkVec2FromMemblock(out.combo_padding, memID, offset)
	offset = nkVec2FromMemblock(out.contextual_padding, memID, offset)
	offset = nkVec2FromMemblock(out.menu_padding, memID, offset)
	offset = nkVec2FromMemblock(out.tooltip_padding, memID, offset)
endfunction offset
function nkStyleSetWindowToMemblock(window ref as nk_style_window, memID as integer, offset as Integer)
	if GetMemblockExists(memID) = 0 then exitfunction offset

	offset = nkStyleSetWindowHeaderToMemblock(window.header, memID, offset)
	offset = nkItemToMemblock(window.fixed_background, memID, offset)
	offset = nkColorToMemblock(window.background, memID, offset)

	offset = nkColorToMemblock(window.border_color, memID, offset)
	offset = nkColorToMemblock(window.popup_border_color, memID, offset)
	offset = nkColorToMemblock(window.combo_border_color, memID, offset)
	offset = nkColorToMemblock(window.contextual_border_color, memID, offset)
	offset = nkColorToMemblock(window.menu_border_color, memID, offset)
	offset = nkColorToMemblock(window.group_border_color, memID, offset)
	offset = nkColorToMemblock(window.tooltip_border_color, memID, offset)
	offset = nkItemToMemblock(window.scaler, memID, offset)

	SetMemblockFloat(memID, offset, window.border): Inc offset,4
	SetMemblockFloat(memID, offset, window.combo_border): Inc offset,4
	SetMemblockFloat(memID, offset, window.contextual_border): Inc offset,4
	SetMemblockFloat(memID, offset, window.menu_border): Inc offset,4
	SetMemblockFloat(memID, offset, window.group_border): Inc offset,4
	SetMemblockFloat(memID, offset, window.tooltip_border): Inc offset,4
	SetMemblockFloat(memID, offset, window.popup_border): Inc offset,4
	SetMemblockFloat(memID, offset, window.min_row_height_padding): Inc offset,4

	SetMemblockFloat(memID, offset, window.rounding): Inc offset,4
	offset = nkVec2ToMemblock(window.spacing, memID, offset)
	offset = nkVec2ToMemblock(window.scrollbar_size, memID, offset)
	offset = nkVec2ToMemblock(window.min_size, memID, offset)

	offset = nkVec2ToMemblock(window.padding, memID, offset)
	offset = nkVec2ToMemblock(window.group_padding, memID, offset)
	offset = nkVec2ToMemblock(window.popup_padding, memID, offset)
	offset = nkVec2ToMemblock(window.combo_padding, memID, offset)
	offset = nkVec2ToMemblock(window.contextual_padding, memID, offset)
	offset = nkVec2ToMemblock(window.menu_padding, memID, offset)
	offset = nkVec2ToMemblock(window.tooltip_padding, memID, offset)
endfunction offset

function nkWindowGetBounds()
	result as nk_rect
	//~ result = nkRectFromString(nk.WindowGetBounds())
	nkRectFromMemblock(result, nk.WindowGetBounds(), 0)
endfunction result

function nkWindowGetSize()
	result as nk_vec2
	nkVec2FromMemblock(result, nk.WindowGetSize(), 0)
endfunction result

function nkWindowGetPosition()
	result as nk_vec2
	nkVec2FromMemblock(result, nk.WindowGetPosition(), 0)
endfunction result

function nkWindowGetPanelBounds()
	result as nk_rect
	//~ result = nkRectFromString(nk.WindowGetPanelBounds())
	nkRectFromMemblock(result, nk.WindowGetPanelBounds(),0)
endfunction result

function nkWindowGetStoredPanelBounds(slot as integer)
	result as nk_rect
	nkRectFromMemblock(result, nk.WindowGetStoredPanelBounds(slot),0)
endfunction result

function nkWindowGetContentRegion()
	result as nk_rect
	//~ result = nkRectFromString(nk.WindowGetContentRegion())
	nkRectFromMemblock(result, nk.WindowGetContentRegion(), 0)
endfunction result

function nkWindowGetContentRegionMin()
	result as nk_vec2
	nkVec2FromMemblock(result, nk.WindowGetContentRegionMin(), 0)
endfunction result

function nkWindowGetContentRegionMax()
	result as nk_vec2
	nkVec2FromMemblock(result, nk.WindowGetContentRegionMax(), 0)
endfunction result

function nkWindowGetContentRegionSize()
	result as nk_vec2
	nkVec2FromMemblock(result, nk.WindowGetContentRegionSize(), 0)
endfunction result

function nkWindowGetScroll()
	result as nk_vec2
	nkVec2FromMemblock(result, nk.WindowGetScroll(), 0)
endfunction result

function nkWindowSetBounds(name as string, bounds as nk_rect)
	nk.WindowSetBounds(name, bounds.x, bounds.y, bounds.w, bounds.h)
endfunction

function nkWindowSetPosition(name as string, position as nk_vec2)
	nk.WindowSetPosition(name, position.x, position.y)
endfunction

function nkWindowSetSize(name as string, size as nk_vec2)
	nk.WindowSetSize(name, size.x, size.y)
endfunction

function nkWindowSetScroll(scroll as nk_vec2)
	nk.WindowSetScroll(scroll.x, scroll.y)
endfunction


/* ------------------------------------------------------------------ */



/* ---------------------------------------------------------------------
	panel
*/



/* ------------------------------------------------------------------ */



/* ---------------------------------------------------------------------
	context style
*/
type nk_style
	memblocks as integer[NK_WIDGETTYPE_COUNT]
	item_size as integer
	skip_id as integer
	arch64 as integer

	text as nk_style_text
	button as nk_style_button
	context_button as nk_style_button
	menu_button as nk_style_button
	checkbox as nk_style_toggle
	option as nk_style_toggle
	selectable as nk_style_selectable
	progress as nk_style_progress
	chart as nk_style_chart
	combo as nk_style_combo
	slider as nk_style_slider
	scrollh as nk_style_scrollbar
	scrollv as nk_style_scrollbar
	edit as nk_style_edit
	property as nk_style_property
	tab as nk_style_tab
	window as nk_style_window
endtype
function nk_style()
	result as nk_style

	nk_ctx.item_size = nk.StyleGetItemSize()
	nk_ctx.item_size = nk.StyleGetItemSize()
	if nk_ctx.item_size > 36
		nk_ctx.arch64 = NK_TRUE
		nk_ctx.skip_id = 8
		//~ nk_ctx.arch64 = NK_TRUE
		//~ nk_ctx.skip_id = 8
	else
		nk_ctx.arch64 = NK_FALSE
		nk_ctx.skip_id = 4
		//~ nk_ctx.arch64 = NK_FALSE
		//~ nk_ctx.skip_id = 4
	endif

	/* text */
	nk_ctx.memblocks[NK_WIDGETTYPE_TEXT] = nk.StyleCreateMemblock(NK_WIDGETTYPE_TEXT)
	nkStyleSetTextFromMemblock(nk_ctx.text, nk_ctx.memblocks[NK_WIDGETTYPE_TEXT], 0)

	/* button */
	nk_ctx.memblocks[NK_WIDGETTYPE_BUTTON] = nk.StyleCreateMemblock(NK_WIDGETTYPE_BUTTON)
	nkStyleSetButtonFromMemblock(nk_ctx.button, nk_ctx.memblocks[NK_WIDGETTYPE_BUTTON], 0)

	/* contextual button */
	nk_ctx.memblocks[NK_WIDGETTYPE_CONTEXT_BUTTON] = nk.StyleCreateMemblock(NK_WIDGETTYPE_CONTEXT_BUTTON)
	nkStyleSetButtonFromMemblock(nk_ctx.context_button, nk_ctx.memblocks[NK_WIDGETTYPE_CONTEXT_BUTTON], 0)

	/* menu button */
	nk_ctx.memblocks[NK_WIDGETTYPE_MENU_BUTTON] = nk.StyleCreateMemblock(NK_WIDGETTYPE_MENU_BUTTON)
	nkStyleSetButtonFromMemblock(nk_ctx.menu_button, nk_ctx.memblocks[NK_WIDGETTYPE_MENU_BUTTON], 0)

	/* checkbox */
	nk_ctx.memblocks[NK_WIDGETTYPE_CHECKBOX] = nk.StyleCreateMemblock(NK_WIDGETTYPE_CHECKBOX)
	nkStyleSetToggleFromMemblock(nk_ctx.checkbox, nk_ctx.memblocks[NK_WIDGETTYPE_CHECKBOX], 0)

	/* option */
	nk_ctx.memblocks[NK_WIDGETTYPE_OPTION] = nk.StyleCreateMemblock(NK_WIDGETTYPE_OPTION)
	nkStyleSetToggleFromMemblock(nk_ctx.option, nk_ctx.memblocks[NK_WIDGETTYPE_OPTION], 0)

	/* selectable */
	nk_ctx.memblocks[NK_WIDGETTYPE_SELECTABLE] = nk.StyleCreateMemblock(NK_WIDGETTYPE_SELECTABLE)
	nkStyleSetSelectableFromMemblock(nk_ctx.selectable, nk_ctx.memblocks[NK_WIDGETTYPE_SELECTABLE], 0)

	/* progress */
	nk_ctx.memblocks[NK_WIDGETTYPE_PROGRESS] = nk.StyleCreateMemblock(NK_WIDGETTYPE_PROGRESS)
	nkStyleSetProgressFromMemblock(nk_ctx.progress, nk_ctx.memblocks[NK_WIDGETTYPE_PROGRESS], 0)

	/* chart */
	nk_ctx.memblocks[NK_WIDGETTYPE_CHART] = nk.StyleCreateMemblock(NK_WIDGETTYPE_CHART)
	nkStyleSetChartFromMemblock(nk_ctx.chart, nk_ctx.memblocks[NK_WIDGETTYPE_CHART], 0)

	/* combo */
	nk_ctx.memblocks[NK_WIDGETTYPE_COMBO] = nk.StyleCreateMemblock(NK_WIDGETTYPE_COMBO)
	nkStyleSetComboFromMemblock(nk_ctx.combo, nk_ctx.memblocks[NK_WIDGETTYPE_COMBO], 0)

	/* slider */
	nk_ctx.memblocks[NK_WIDGETTYPE_SLIDER] = nk.StyleCreateMemblock(NK_WIDGETTYPE_SLIDER)
	nkStyleSetSliderFromMemblock(nk_ctx.slider, nk_ctx.memblocks[NK_WIDGETTYPE_SLIDER], 0)

	/* scrollbar horizontal */
	nk_ctx.memblocks[NK_WIDGETTYPE_SCROLLH] = nk.StyleCreateMemblock(NK_WIDGETTYPE_SCROLLH)
	nkStyleSetScrollbarFromMemblock(nk_ctx.scrollh, nk_ctx.memblocks[NK_WIDGETTYPE_SCROLLH], 0)

	/* scrollbar vertical */
	nk_ctx.memblocks[NK_WIDGETTYPE_SCROLLV] = nk.StyleCreateMemblock(NK_WIDGETTYPE_SCROLLV)
	nkStyleSetScrollbarFromMemblock(nk_ctx.scrollv, nk_ctx.memblocks[NK_WIDGETTYPE_SCROLLV], 0)

	/* edit */
	nk_ctx.memblocks[NK_WIDGETTYPE_EDIT] = nk.StyleCreateMemblock(NK_WIDGETTYPE_EDIT)
	nkStyleSetEditFromMemblock(nk_ctx.edit, nk_ctx.memblocks[NK_WIDGETTYPE_EDIT], 0)

	/* property */
	nk_ctx.memblocks[NK_WIDGETTYPE_PROPERTY] = nk.StyleCreateMemblock(NK_WIDGETTYPE_PROPERTY)
	nkStyleSetPropertyFromMemblock(nk_ctx.property, nk_ctx.memblocks[NK_WIDGETTYPE_PROPERTY], 0)

	/* tab */
	nk_ctx.memblocks[NK_WIDGETTYPE_TAB] = nk.StyleCreateMemblock(NK_WIDGETTYPE_TAB)
	nkStyleSetTabFromMemblock(nk_ctx.tab, nk_ctx.memblocks[NK_WIDGETTYPE_TAB], 0)

	/* window */
	nk_ctx.memblocks[NK_WIDGETTYPE_WINDOW] = nk.StyleCreateMemblock(NK_WIDGETTYPE_WINDOW)
	nkStyleSetWindowFromMemblock(nk_ctx.window, nk_ctx.memblocks[NK_WIDGETTYPE_WINDOW], 0)

    /* window header */
	nk_ctx.memblocks[NK_WIDGETTYPE_WINDOW_HEADER] = nk.StyleCreateMemblock(NK_WIDGETTYPE_WINDOW_HEADER)
	nkStyleSetWindowHeaderFromMemblock(nk_ctx.window.header, nk_ctx.memblocks[NK_WIDGETTYPE_WINDOW_HEADER], 0)
endfunction nk_ctx

global _g_ms as float = 0.0
function nkSync()
    Update(GetFrameTime())
    Render()
	// if(_g_ms < GetMilliseconds())
	// nk.HandleInput()
	// 	_g_ms = GetMilliseconds()+30
	// endif
	nk.Render(1)
    Swap()
endfunction

function nkInit()
	global nk_ctx as nk_style
	global nk_mem_interface as integer
	nk.Init()

	nk.FontStashBegin()
	nk.FontStashEnd()

	nk_ctx = nk_style()
	nk_mem_interface = nk.GetMemblockInterface()
endfunction




function nkWidget()
	result as nk_rect
	//~ result = nkRectFromString(nk.Widget())
	nkRectFromMemblock(result, nk.Widget(), 0)
endfunction result

function nkWidgetFitting(padding as nk_vec2)
	result as nk_rect
	//~ result = nkRectFromString(nk.WidgetFitting(padding.x, padding.y))
	nkRectFromMemblock(result, nk.WidgetFitting(padding.x, padding.y), 0)
endfunction result

function nkWidgetPosition()
	result as nk_vec2
	nkVec2FromMemblock(result, nk.WidgetPosition(), 0)
endfunction result

function nkWidgetSize()
	result as nk_vec2
	nkVec2FromMemblock(result, nk.WidgetSize(), 0)
endfunction result




/* ---------------------------------------------------------------------
	layout
*/
function nkLayoutSpaceBounds()
	result as nk_rect
	//~ result = nkRectFromString(nk.LayoutSpaceBounds())
	nkRectFromMemblock(result, nk.LayoutSpaceBounds(),0)
endfunction result

function nkLayoutSpaceRectToScreen(rect ref as nk_rect)
	result as nk_rect
	//~ result = nkRectFromString(nk.LayoutSpaceRectToScreen(rect.x, rect.y, rect.w, rect.h))
	nkRectFromMemblock(result, nk.LayoutSpaceRectToScreen(rect.x, rect.y, rect.w, rect.h),0)
endfunction result

function nkLayoutRow(format as integer, height as float, ratio ref as float[])
	nk.LayoutRow(format, height, ratio.toJSON())
endfunction

function nkLayoutWidgetBounds()
	result as nk_rect
	nkRectFromMemblock(result, nk.LayoutWidgetBounds(),0)
endfunction result

function nkLayoutSpacePush(rect ref as nk_rect)
	nk.LayoutSpacePush(rect.x, rect.y, rect.w, rect.h)
endfunction

function nkLayoutSpaceToScreen(pos ref as nk_vec2)
	result as nk_vec2
	nkVec2FromMemblock(result, nk.LayoutSpaceToScreen(pos.x, pos.y),0)
endfunction result

function nkLayoutSpaceToLocal(pos ref as nk_vec2)
	result as nk_vec2
	nkVec2FromMemblock(result, nk.LayoutSpaceToLocal(pos.x, pos.y),0)
endfunction result

function nkLayoutSpaceRectToLocal(rect ref as nk_rect)
	result as nk_rect
	nkRectFromMemblock(result, nk.LayoutSpaceRectToLocal(rect.x, rect.y, rect.w, rect.h),0)
endfunction result


/* ---------------------------------------------------------------------
	style
*/
function nkStyleGetPropertyItem(result ref as nk_style_item, property as String)
	t as integer
	t = nkStyleGetPropertyType(property)
	if t <> NK_PROPERTYTYPE_ITEM then exitfunction

	t = nkStyleGetPropertyItemType(property)
	property = Right(property, Len(property)-2)
	select t
		case NK_ITEMTYPE_COLOR
			nkStyleGetPropertyItemColor(result.color, property)
		endcase
		case NK_ITEMTYPE_IMAGE
		  nkStyleGetPropertyItemImage(result.image, property)
		endcase
		case NK_ITEMTYPE_PATCH9
		  nkStyleGetPropertyItemPatch9(result.patch9, property)
		endcase
	endselect
endfunction

function nkStyleGetPropertyType(property as string)
	count as integer = 0
	count = CountStringTokens(property, ",")
	if count > 1 then exitfunction NK_PROPERTYTYPE_ITEM
	if count = 1 then exitfunction NK_PROPERTYTYPE_VEC2
	if CountStringTokens(property, ".") = 1 then exitfunction NK_PROPERTYTYPE_FLOAT
endfunction NK_PROPERTYTYPE_INTEGER

function nkStyleGetPropertyItemType(property as String)
	result as integer
	result = val(GetStringToken(property, ",", 1))
endfunction result

function nkStyleGetPropertyItemColor(result ref as nk_color, property as string)
	if nkStyleGetPropertyType(property) <> NK_PROPERTYTYPE_ITEM then exitfunction
	result = nkColorFromString(property)
endfunction

function nkStyleGetPropertyItemImage(result ref as nk_image, property as string)
	if nkStyleGetPropertyType(property) <> NK_PROPERTYTYPE_ITEM then exitfunction result
	if nkStyleGetPropertyItemType(property) = NK_ITEMTYPE_IMAGE then nkImageFromString(property)
endfunction result

function nkStyleGetPropertyItemPatch9(result ref as nk_patch9, property as string)
	if nkStyleGetPropertyType(property) <> NK_PROPERTYTYPE_ITEM then exitfunction result
	if nkStyleGetPropertyItemType(property) = NK_ITEMTYPE_PATCH9 then nkPatch9FromString(property)
endfunction result

function nkStyleGetPropertyVec2(result ref as nk_vec2, property as string)
	if nkStyleGetPropertyType(property) = NK_PROPERTYTYPE_VEC2 then result = nkVec2FromString(property)
endfunction result

function nkStyleGetPropertyInteger(property as string)
	result as integer
	if nkStyleGetPropertyType(property) = NK_PROPERTYTYPE_INTEGER then result = val(property)
endfunction result

function nkStyleGetPropertyFloat(property as string)
	result as float
	if nkStyleGetPropertyType(property) = NK_PROPERTYTYPE_FLOAT then result = ValFloat(property)
endfunction result

function nkStyleGetContextPropertyAsInteger(widget as string, prop as string)
	result as integer
	result = val(nk.StyleGetContextProperty(widget, prop))
endfunction result

function nkImageFromString(img_str as string)
  result as nk_image
	result.img_id = val(GetStringToken(img_str, ",", 1))
	result.w = val(GetStringToken(img_str, ",", 2))
	result.h = val(GetStringToken(img_str, ",", 3))
	result.region[0] = val(GetStringToken(img_str, ",", 4))
	result.region[1] = val(GetStringToken(img_str, ",", 5))
	result.region[2] = val(GetStringToken(img_str, ",", 6))
	result.region[3] = val(GetStringToken(img_str, ",", 7))
endfunction result
function nkImageCreate(img_id as integer)
	memid as integer
	result as nk_image
	if GetImageExists(img_id) = 0 then exitfunction result
	memid = nk.ImageCreate(img_id)
	nkImageFromMemblock(result, memid, 0)
endfunction result

function nkPatch9FromString(patch_str as string)
  result as nk_patch9
	result.img_id = val(GetStringToken(patch_str, ",", 1))
	result.w = val(GetStringToken(patch_str, ",", 2))
	result.h = val(GetStringToken(patch_str, ",", 3))
	result.region[0] = val(GetStringToken(patch_str, ",", 4))
	result.region[1] = val(GetStringToken(patch_str, ",", 5))
	result.region[2] = val(GetStringToken(patch_str, ",", 6))
	result.region[3] = val(GetStringToken(patch_str, ",", 7))
	result.border[0] = val(GetStringToken(patch_str, ",", 8))
	result.border[1] = val(GetStringToken(patch_str, ",", 9))
	result.border[2] = val(GetStringToken(patch_str, ",", 10))
	result.border[3] = val(GetStringToken(patch_str, ",", 11))
endfunction result

function nkColorFromString(color_str as string)
	result as nk_color
	result.r = val(GetStringToken(color_str, ",", 1))
	result.g = val(GetStringToken(color_str, ",", 2))
	result.b = val(GetStringToken(color_str, ",", 3))
	result.a = val(GetStringToken(color_str, ",", 4))
endfunction result

function nkColorToString(color as nk_color)
	result as string
	result = str(color.r)+","+str(color.g)+","+str(color.b)+","+str(color.a)
endfunction result

function nkColorFToInt(color ref as nk_colorf)
	result as integer
	result = makecolor(color.r*255.0, color.g*255.0, color.b*255.0, color.a*255.0)
endfunction result

function nkColorToInt(color ref as nk_color)
	result as integer
	result = makecolor(color.r, color.g, color.b, color.a)
endfunction result

function nkColorFFromInt(color as integer)
	result as nk_colorf
	result.a = (GetColorAlpha(color) / 255.0)
	result.b = GetColorBlue(color) / 255.0
	result.g = GetColorGreen(color) / 255.0
	result.r = GetColorRed(color) / 255.0
endfunction result

function nkColorFromInt(color as integer)
	result as nk_color
	result.a = GetColorAlpha(color)
	result.b = GetColorBlue(color)
	result.g = GetColorGreen(color)
	result.r = GetColorRed(color)
endfunction result

function nkVec2FromString(vec2_str as string)
	result as nk_vec2
	sign as String
	sign = Left(vec2_str, 1)
	if sign = "{" Or sign = "[" then vec2_str = Mid(vec2_str, 2, len(vec2_str)-2)

	result.x = ValFloat(GetStringToken(vec2_str,  ",",  1))
	result.y = ValFloat(GetStringToken(vec2_str,  ",",  2))
endfunction result

function nkVec2ToString(vec2 as nk_vec2)
  result as string
  result = str(vec2.x)+","+str(vec2.y)
endfunction result

function nkRectFromString(r as string)
	result as nk_rect
	result.x = ValFloat(GetStringToken(r,";",1))
	result.y = ValFloat(GetStringToken(r,";",2))
	result.w = ValFloat(GetStringToken(r,";",3))
	result.h = ValFloat(GetStringToken(r,";",4))
endfunction result

function nkHSVAToColorf(h as float, s as float, v as float, a as float)
	result as nk_colorf
	p as float
	q as float
	t as float
	f as float
	i as integer

    if (s <= 0.0)
        result.r = v: result.g = v: result.b = v: result.a = a
        exitfunction result
    endif

    h = h / (60.0/360.0)
    i = trunc(h)
    f = h - i
    p = v * (1.0 - s)
    q = v * (1.0 - (s * f))
    t = v * (1.0 - s * (1.0 - f))

    select i
		case 0: result.r = v: result.g = t: result.b = p: endcase
		case 1: result.r = q: result.g = v: result.b = p: endcase
		case 2: result.r = p: result.g = v: result.b = t: endcase
		case 3: result.r = p: result.g = q: result.b = v: endcase
		case 4: result.r = t: result.g = p: result.b = v: endcase
		case 5: result.r = v: result.g = p: result.b = q: endcase
		case default: result.r = v: result.g = t: result.b = p: endcase
	endselect
    result.a = a
endfunction result

function nkHSVAFromColorf(color as nk_colorf)
	result as float[3]
	chroma as float
	k as float
	t as float

    if (color.g < color.b)
        t = color.g: color.g = color.b: color.b = t
        K = -1.0
    endif

    if (color.r < color.g)
        t = color.r: color.r = color.g: color.g = t
        K = -2.0/6.0 - K
    endif

    if color.g < color.b then chroma = color.r - color.g else chroma = color.r - color.b
    //~ chroma = color.r - ((color.g < color.b) ? color.g: color.b)
    result[0] = abs(K + (color.g - color.b)/(6.0 * chroma + 0.00000000000000000001))
    result[1] = chroma / (color.r + 0.00000000000000000001)
    result[2] = color.r
    result[3] = color.a
endfunction result

function nkButtonColor(col ref as nk_color)
	nk.ButtonColor(MakeColor(col.r,col.g,col.b,col.a))
endfunction

function nkWidgetBounds()
	result as nk_rect
	//~ result = nkRectFromString(nk.WidgetBounds())
	nkRectFromMemblock(result, nk.WidgetBounds(), 0)
endfunction result

function nkContextualBegin(flags as integer, width as float, height as float, bound as nk_rect)
	result as integer
	result = nk.ContextualBegin(flags, width, height, bound.x, bound.y, bound.w, bound.h)
endfunction result

function nkPopupBegin(typ as integer, title as string, flags as integer, bound as nk_rect)
	result as integer
	result = nk.PopupBegin(typ, title, flags, bound.x, bound.y, bound.w, bound.h)
endfunction result

/* ---------------------------------------------------------------------
	input
*/
function nkInputIsMouseClickInRect(button as integer, rect ref as nk_rect)
	result as integer
	result = nk.InputIsMouseClickInRect(button, rect.x, rect.y, rect.w, rect.h)
endfunction result

function nkInputHasMouseClickInRect(button as integer, rect ref as nk_rect)
	result as integer
	result = nk.InputHasMouseClickInRect(button, rect.x, rect.y, rect.w, rect.h)
endfunction result

function nkInputHasMouseClickDownInRect(button as integer, rect ref as nk_rect, down as integer)
	result as integer
	result = nk.InputHasMouseClickDownInRect(button, rect.x, rect.y, rect.w, rect.h, down)
endfunction result

function nkInputIsMouseClickDownInRect(button as integer, rect ref as nk_rect, down as integer)
	result as integer
	result = nk.InputIsMouseClickDownInRect(button, rect.x, rect.y, rect.w, rect.h, down)
endfunction result

function nkInputAnyMouseClickInRect(rect ref as nk_rect)
	result as integer
	result = nk.InputAnyMouseClickInRect(rect.x, rect.y, rect.w, rect.h)
endfunction result

function nkInputIsMousePrevHoveringRect(rect ref as nk_rect)
	result as integer
	result = nk.InputIsMousePrevHoveringRect(rect.x, rect.y, rect.w, rect.h)
endfunction result

function nkInputIsMouseHoveringRect(rect ref as nk_rect)
	result as integer
	result = nk.InputIsMouseHoveringRect(rect.x, rect.y, rect.w, rect.h)
endfunction result

function nkInputMouseClicked(button as integer, rect ref as nk_rect)
	result as integer
	result = nk.InputMouseClicked(button, rect.x, rect.y, rect.w, rect.h)
endfunction result

function nkInputGetMouseDelta()
	result as nk_vec2
	result.x = nk.InputGetMouseDeltaX()
	result.y = nk.InputGetMouseDeltaY()
endfunction result

/* ---------------------------------------------------------------------
	chart
*/
function nkChartArray(mode as integer, array ref as float[], min as float, max as float)
	result as integer = -1
	nk.ChartBegin(mode, array.length+1, min, max)
	i as integer
	for i=0 to array.length
		if (nk.ChartPush(array[i])&&NK_CHART_CLICKED) = NK_CHART_CLICKED then result = i
	next
	nk.ChartEnd()
endfunction result

function nkChartColoredArray(mode as integer, color as nk_color, active as nk_color, array ref as float[], min as float, max as float)
	result as integer = -1
	nk.ChartBeginColored(mode, nkColorToInt(color), nkColorToInt(active), array.length+1, min, max)
	i as integer
	for i=0 to array.length
		if (nk.ChartPush(array[i])&&NK_CHART_CLICKED) = NK_CHART_CLICKED then result = i
	next
	nk.ChartEnd()
endfunction result

/* ---------------------------------------------------------------------
	color picker
*/
function nkColorPicker(c ref as nk_colorf, format as integer)
	result as integer
	result = nk.ColorPicker(c.r,c.g,c.b,c.a,format)
	c = nkColorFFromInt(result)
endfunction result

/* ---------------------------------------------------------------------
	draw commands
*/

function nkStrokeLine(canvas_slot as integer, p0 as nk_vec2, p1 as nk_vec2, thickness as float, color as nk_color)
	nk.StrokeLine(canvas_slot, p0.x, p0.y, p1.x, p1.y, thickness, nkColorToInt(color))
endfunction

function nkStrokeCurve(canvas_slot as integer, p0 as nk_vec2, ctrl0 as nk_vec2, ctrl1 as nk_vec2, p1 as nk_vec2, thickness as float, color as nk_color)
	nk.StrokeCurve(canvas_slot, p0.x, p0.y, p0.x+ctrl0.x, p0.y+ctrl0.y, p1.x+ctrl1.x, p1.y+ctrl1.y, p1.x, p1.y, thickness, nkColorToInt(color))
endfunction

function nkStrokeRect(canvas_slot as integer, rect as nk_rect, rounding as float, thickness as float, color as nk_color)
	nk.StrokeRect(canvas_slot, rect.x, rect.y, rect.w, rect.h, rounding, thickness, nkColorToInt(color))
endfunction

function nkFillRect(canvas_slot as integer, rect as nk_rect, rounding as float, color as nk_color)
	nk.FillRect(canvas_slot, rect.x, rect.y, rect.w, rect.h, rounding, nkColorToInt(color))
endfunction

function nkFillRectMultiColor(canvas_slot as integer, rect as nk_rect, lt as nk_color, rt as nk_color, rb as nk_color, lb as nk_color)
	nk.FillRectMultiColor(canvas_slot, rect.x, rect.y, rect.w, rect.h, nkColorToInt(lt), nkColorToInt(rt), nkColorToInt(rb), nkColorToInt(lb))
endfunction

function nkStrokeCircle(canvas_slot as integer, center as nk_vec2, radius as float, thickness as float, color as nk_color)
	nk.StrokeCircle(canvas_slot, center.x-radius, center.y-radius, radius*2, radius*2, thickness, nkColorToInt(color))
endfunction

function nkFillCircle(canvas_slot as integer, center as nk_vec2, radius as float, color as nk_color)
	nk.FillCircle(canvas_slot, center.x-radius, center.y-radius, radius*2, radius*2, nkColorToInt(color))
endfunction

function nkStrokeArc(canvas_slot as integer, center as nk_vec2, radius as float, a_min as float, a_max as float, thickness as float, color as nk_color)
	nk.StrokeArc(canvas_slot, center.x, center.y, radius,a_min,a_max, thickness, nkColorToInt(color))
endfunction

function nkFillArc(canvas_slot as integer, center as nk_vec2, radius as float, a_min as float, a_max as float, color as nk_color)
	nk.FillArc(canvas_slot, center.x, center.y, radius,a_min,a_max, nkColorToInt(color))
endfunction

function nkStrokeTriangle(canvas_slot as integer, p0 as nk_vec2, p1 as nk_vec2, p3 as nk_vec2, thickness as float, color as nk_color)
	nk.StrokeTriangle(canvas_slot, p0.x, p0.y, p1.x, p1.y, p3.x, p3.y, thickness, nkColorToInt(color))
endfunction

function nkFillTriangle(canvas_slot as integer, p0 as nk_vec2, p1 as nk_vec2, p3 as nk_vec2, color as nk_color)
	nk.FillTriangle(canvas_slot, p0.x, p0.y, p1.x, p1.y, p3.x, p3.y, nkColorToInt(color))
endfunction

function nkDrawText(canvas_slot as integer, rect as nk_rect, label as String, font_name as String, back_col as nk_color, front_col as nk_color)
	nk.DrawText(canvas_slot, rect.x, rect.y, rect.w, rect.h, label, font_name, nkColorToInt(back_col), nkColorToInt(front_col))
endfunction

function nkDrawImage(canvas_slot as integer, rect as nk_rect, img_slot as integer, color as nk_color)
	nk.DrawImage(canvas_slot, rect.x, rect.y, rect.w, rect.h, img_slot, nkColorToInt(color))
endfunction
