aboutsummaryrefslogtreecommitdiff
path: root/src/saffron_widget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/saffron_widget.c')
-rw-r--r--src/saffron_widget.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/saffron_widget.c b/src/saffron_widget.c
new file mode 100644
index 0000000..089c040
--- /dev/null
+++ b/src/saffron_widget.c
@@ -0,0 +1,36 @@
+#include <SDL3/SDL.h>
+#include <stdlib.h>
+#include <saffron_widget.h>
+#include <saffron_api.h>
+#include <saffron_window.h>
+
+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);
+}