shithub: blie

ref: 7455a7027cde79e0304bade55b6616983e2e8e1a
dir: /test/task.c/

View raw version
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <memdraw.h>
#include <event.h>
#include "../blie.h"

void
eresized(int)
{
	draw(screen, screen->r, display->white, nil, ZP);
}

void
main(int, char**)
{
	Event ev;
	Ask asks[3];
	char answer1[11];
	char answer2[11];
	
	asks[0].label = "question A";
	asks[0].value = answer1;
	asks[0].nval = 10;
	asks[1].label = "question B";
	asks[1].value = answer2;
	asks[1].nval = 10;
	asks[2].label = nil;
	asks[2].value = nil;
	
	snprint(answer1, sizeof answer1, "answer");
	snprint(answer2, sizeof answer2, "%f", 50.54);
	
	if (!initdraw(nil, nil, "asktest"))
		sysfatal("%r");
	
	eresized(0);
	einit(Emouse|Ekeyboard);
	
	for (;;) {
		switch (event(&ev)) {
		case Emouse:
			if (ev.mouse.buttons & 1) {
				if (!ask(asks, ev.mouse)) {
					fprint(2, "   abort:\n");
					fprint(2, "0: %s: %s\n", asks[0].label, asks[0].value);
					fprint(2, "1: %s: %s\n", asks[1].label, asks[1].value);
					break;
				}	
				fprint(2, "   accept:\n");
				fprint(2, "0: %s: %s\n", asks[0].label, asks[0].value);
				fprint(2, "1: %s: %s\n", asks[1].label, asks[1].value);
			}
			break;
		case Ekeyboard:
			if (ev.kbdc == 'q')
				exits(nil);
			break;
		}
	}
	exits(nil);
}