aboutsummaryrefslogtreecommitdiff
path: root/src/saffron_widget.c
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-04-08 18:21:40 +1200
committerArslaan Pathan <[email protected]>2026-04-08 18:21:40 +1200
commit0f19e5f0175b0e031257ccd22f42e21baaf2f720 (patch)
treecee391e4de8b22470c143239f826055908eb1c60 /src/saffron_widget.c
parentc9660a840256308d4dde40613a1af3296d3fdead (diff)
downloadsaffron-0f19e5f0175b0e031257ccd22f42e21baaf2f720.tar.xz
saffron-0f19e5f0175b0e031257ccd22f42e21baaf2f720.zip
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!!!!!!
Diffstat (limited to 'src/saffron_widget.c')
-rw-r--r--src/saffron_widget.c31
1 files changed, 27 insertions, 4 deletions
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 <saffron_api.h>
#include <saffron_window.h>
-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++;
+}
+