From 0f19e5f0175b0e031257ccd22f42e21baaf2f720 Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Wed, 8 Apr 2026 18:21:40 +1200 Subject: Implement saffron_window_main and saffron_quit, among a few other missing APIs, and get an actual API test to work. IT WORKS IT WORKS IT WORKS THIS IS SO PEAK IT WORKS OHMYGOD IT WORKS FINALLY IT WORKS IT WORKS IT WOORKSKSKSKSKKS!!!!!! --- src/saffron_widget.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/saffron_widget.c') diff --git a/src/saffron_widget.c b/src/saffron_widget.c index 089c040..85b2013 100644 --- a/src/saffron_widget.c +++ b/src/saffron_widget.c @@ -4,7 +4,7 @@ #include #include -SaffronWidget* saffron_widget_new() { +SaffronWidget* saffron_widget_new(void) { /* 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)); @@ -24,9 +24,12 @@ SaffronWidget* saffron_widget_new() { } 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. */ + /* follow-up to my previous comment: + * yeah it is the caller's responsibility to check + * for undefined behaviour but this one line will save + * so much time down the line */ + if (!widget) return; + for (int i = 0; i < widget->child_count; i++) { saffron_widget_free(widget->children[i]); } @@ -34,3 +37,23 @@ void saffron_widget_free(SaffronWidget *widget) { free(widget->children); free(widget); } + +void saffron_widget_draw(SaffronWidget* widget, SDL_Renderer *renderer) { + if (!widget) return; + + if (widget->draw) { + widget->draw(widget, renderer); + } + + for (int i = 0; i < widget->child_count; i++) { + saffron_widget_draw(widget->children[i], renderer); + } +} + +void saffron_widget_add_child(SaffronWidget *parent, SaffronWidget *child) { + child->parent = parent; + parent->children = realloc(parent->children, sizeof(SaffronWidget*) * (parent->child_count + 1)); + parent->children[parent->child_count] = child; + parent->child_count++; +} + -- cgit v1.2.3