use32
org 0x0

db 'MENUET01'
dd 0x01, START, I_END, 0x1000, 0x1000, 0x0, 0x0

include 'macros.inc'
include 'struct.inc'
include 'proc32.inc'

include 'malloc.asm'
include 'widgets.asm'

START:
	mcall	68, 11

	stdcall hbox_layout_class_new
	mov	[main_layout], eax
	stdcall rect_class_new, 20, 50
	stdcall layout_class_add_widget, [main_layout], eax, LAYOUT_VEXPAND
	stdcall rect_class_new, 30, 50
	stdcall layout_class_add_widget, [main_layout], eax, LAYOUT_MINIMAL
	stdcall rect_class_new, 60, 50
	stdcall layout_class_add_widget, [main_layout], eax, LAYOUT_HEXPAND
	stdcall spacer_class_new
	stdcall layout_class_add_widget, [main_layout], eax, LAYOUT_EXPAND
	stdcall rect_class_new, 60, 50
	stdcall layout_class_add_widget, [main_layout], eax, LAYOUT_MINIMAL
	stdcall spacer_class_new
	stdcall layout_class_add_widget, [main_layout], eax, LAYOUT_EXPAND
	stdcall rect_class_new, 40, 50
	stdcall layout_class_add_widget, [main_layout], eax, LAYOUT_VEXPAND

	stdcall layout_class_calc_min_size, [main_layout]
	mov	eax, [main_layout]
	push	[eax + widget_t.min_size.width] [eax + widget_t.min_size.height]
	pop	[pinfo.client_box.height] [pinfo.client_box.width]

	mcall	48, 4
	mov	[skin_height], eax

red:
	call	draw_window

still:
	mcall	10

	cmp	eax, 1
	je	red
	cmp	eax, 2
	je	key
	cmp	eax, 3
	je	button

	jmp	still

key:
	mcall	2
	jmp	still

button:
	mcall	17

	cmp	ah, 1
	jne	still

  .exit:
	mcall -1

draw_window:
	mcall	12, 1

	mov	ebx, 200 shl 16
	mov	bx, word[pinfo.client_box.width]
	add	bx, 10
	mov	ecx, 200 shl 16
	mov	cx, word[pinfo.client_box.height]
	add	cx, 5
	add	cx, word[skin_height]

	mcall	0, , , 0x33ffffff, ,title

	mcall	9, pinfo, -1
	xor	eax, eax
	mov	[pinfo.client_box.left], eax
	mov	[pinfo.client_box.top], eax
	stdcall widget_set_box, [main_layout], pinfo.client_box
	stdcall hbox_layout_class_arrange_widgets, [main_layout]
	stdcall widget_paint, [main_layout]

	mcall	12, 2
	ret

sz title, 'Layouts sample'

I_END:

main_layout dd ?
skin_height dd ?

pinfo process_information
