#include #include #include #include #include "../src/ax.h" #include "../src/ctxt.h" #include "../src/backend.h" #include "../src/util/region.h" #include "../src/concurrent/msg.h" #include "../src/concurrent/pubsub.h" struct rgn* rgn = NULL; struct ax_ctxt* ax = NULL; static void cleanup() { if (rgn != NULL) { rgn_cleanup(rgn); rgn = NULL; } 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"); ax_set_window_size(ax, 1000, 400, false); 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, fileno(stdout), false); rgn = rgn_bootstrap_new(SMALL); 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)); struct sub* ev_sub = ax__backend_sub_events(ax->bac, rgn); for (bool quit = false; !quit; ) { sub_begin_recv_and_wait(ev_sub); SUB_RECV_ALL(ev_sub) { ON(ax_msg_window_closed, { if (m.win == win) { quit = true; } break; }); default: printf("got a message: %s\n", ax__msg_name(m_type)); break; } sub_end_recv(ev_sub); } cleanup(); return 0; ax_fail: printf("ERROR: %s\n", ax_get_error(ax)); cleanup(); return rv; }