#include "aster.h"
#include <stdio.h>

static int clicks = 0;

/* The screen is JSON: a column with a heading,
   a number, a meter and a button. */
static void show(const AsterApp *app) {
    char v[512];
    snprintf(v, sizeof v,
        "{\"type\":\"col\",\"gap\":4,\"pad\":6,\"children\":["
        "{\"type\":\"heading\",\"title\":\"Hello, Aster\","
        "\"subtitle\":\"a whole app in C\"},"
        "{\"type\":\"stat\",\"label\":\"Clicks\",\"value\":%d},"
        "{\"type\":\"meter\",\"value\":%d,\"role\":\"accent\"},"
        "{\"type\":\"button\",\"text\":\"Add one\","
        "\"action\":\"add\"}]}", clicks, clicks * 25);
    aster_app_set_view(app, v);
}

static void on_event(void *app, const char *event) {
    (void)event;
    clicks++;
    show(app);
}

int main(void) {
    AsterApp *app = aster_app_new(
        "{\"title\":\"Hello\",\"width\":420,\"height\":256,\"scale\":2}");
    aster_app_on_event(app, on_event, app);
    show(app);
    aster_app_click(app, "Add one"); /* or aster_app_run(app): a window */
    aster_app_click(app, "Add one");
    aster_app_shot(app, "hello.png");
    aster_app_free(app);
    return 0;
}
