libui/examples/timer/main.c

65 lines
1.0 KiB
C
Raw Normal View History

2017-08-19 17:32:52 -05:00
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "../../ui.h"
uiMultilineEntry *e;
int sayTime(void *data)
{
time_t t;
char *s;
t = time(NULL);
s = ctime(&t);
uiMultilineEntryAppend(e, s);
return 1;
}
int onClosing(uiWindow *w, void *data)
{
uiQuit();
return 1;
}
void saySomething(uiButton *b, void *data)
{
uiMultilineEntryAppend(e, "Saying something\n");
}
int main(void)
{
uiInitOptions o;
uiWindow *w;
uiBox *b;
uiButton *btn;
memset(&o, 0, sizeof (uiInitOptions));
if (uiInit(&o) != NULL)
abort();
w = uiNewWindow("Hello", 320, 240, 0);
uiWindowSetMargined(w, 1);
b = uiNewVerticalBox();
uiBoxSetPadded(b, 1);
uiWindowSetChild(w, uiControl(b));
e = uiNewMultilineEntry();
uiMultilineEntrySetReadOnly(e, 1);
btn = uiNewButton("Say Something");
uiButtonOnClicked(btn, saySomething, NULL);
uiBoxAppend(b, uiControl(btn), 0);
uiBoxAppend(b, uiControl(e), 1);
uiTimer(1000, sayTime, NULL);
uiWindowOnClosing(w, onClosing, NULL);
uiControlShow(uiControl(w));
uiMain();
return 0;
}