axui-growth-chamber/test/main.c

81 lines
1.6 KiB
C

#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include "../src/ax.h"
#include "../src/ctxt.h"
#include "../src/backend.h"
struct ax_ctxt* ax = NULL;
static void cleanup()
{
ax_free(ax);
ax = NULL;
}
static void sigint_handler(int signum)
{
printf("\nCaught interrupt.\n");
// cleanup();
exit(0);
}
static struct ax_window* make_window()
{
ax_begin_window(ax);
ax_set_window_title(ax, "Test App");
return ax_end_window(ax);
}
static struct ax_theme* make_example_theme()
{
ax_begin_theme(ax);
ax_set_theme_color(ax, "primary", 0x00ff00);
ax_set_theme_font(ax, "default", "/usr/share/fonts/TTF/DejaVuSans.ttf", 0);
ax_set_theme_font(ax, "h1", NULL, 95);
return ax_end_theme(ax);
}
int main(void)
{
signal(SIGINT, sigint_handler);
ax = ax_new();
ax_set_logger(ax, 0, false);
int rv = 0;
#define GUARD(f) if ((rv = f) != 0) goto ax_fail;
struct ax_window* win = make_window();
struct ax_theme* thm = make_example_theme();
ax_theme_wait_until_loaded(ax, thm);
printf("it loaded!\n");
GUARD(ax_select_theme(ax, thm));
GUARD(ax_select_window(ax, win));
usleep(1000 * 1000 * 2);
/*
struct ax_evt evt;
for (;;) {
ax_wait_evt_avail(ax);
while (ax_poll_evt(ax, &evt)) {
if (evt.ty == AX_EVT_THEME_LOADED && evt.arg.theme == thm) {
printf("The font finished loading!\n");
}
}
}
*/
cleanup();
return 0;
ax_fail:
printf("ERROR: %s\n", ax_get_error(ax));
cleanup();
return rv;
}