aboutsummaryrefslogtreecommitdiff
path: root/src/saffron_widget.c
blob: 089c0408ff40f380ea09b3f332b68f434c451160 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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);
}