#include #include #include #include #include SaffronWidget* saffron_widget_new() { /* This function is a generic primitive for creating widgets. You wouldn't want to do this manually unless you're a lunatic. It is meant to be wrapped around by other functions that change the default parameters, for example, what sane person makes a widget 0x0x0x0? you LUNATIC! */ SaffronWidget* widget = malloc(sizeof(SaffronWidget)); widget->x = 0; widget->y = 0; widget->w = 0; widget->h = 0; widget->draw = NULL; widget->on_click = NULL; widget->parent = NULL; widget->children = NULL; widget->child_count = 0; return widget; } void saffron_widget_free(SaffronWidget *widget) { /* should probably check if widget is NULL here * oh well, too bad so sad. not my problem if the caller * doesn't check and causes undefined behaviour. */ for (int i = 0; i < widget->child_count; i++) { saffron_widget_free(widget->children[i]); } free(widget->children); free(widget); }