aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/saffron_text.c20
-rw-r--r--src/saffron_widget.c7
2 files changed, 23 insertions, 4 deletions
diff --git a/src/saffron_text.c b/src/saffron_text.c
index 8a093ea..e2ac850 100644
--- a/src/saffron_text.c
+++ b/src/saffron_text.c
@@ -3,6 +3,11 @@
#include <SDL3/SDL.h>
#include <SDL3_ttf/SDL_ttf.h>
#include <stdlib.h>
+#include <string.h>
+
+static void saffron_text_free(SaffronWidget* self) {
+ free(((SaffronText*)self)->text);
+}
static void saffron_text_draw(SaffronWidget* widget, SDL_Renderer* renderer) {
SaffronText* text = (SaffronText*)widget;
@@ -25,7 +30,16 @@ SaffronText* saffron_text_new(const char* text, int font_size, SDL_Color color)
saffron_widget_init((SaffronWidget*)text_widget);
- // todo actually do stuff
- // and return something
- // im tired ill do this later
+ ((SaffronWidget*)text_widget)->type = SAFFRON_WIDGET_TEXT;
+ ((SaffronWidget*)text_widget)->draw = saffron_text_draw;
+ ((SaffronWidget*)text_widget)->free = saffron_text_free;
+
+ text_widget->text = malloc(strlen(text) + 1);
+ if (text_widget->text) {
+ strcpy(text_widget->text, text);
+ }
+ text_widget->font = NULL; // TODO initialize a font here
+ text_widget->color = color;
+
+ return text_widget;
}
diff --git a/src/saffron_widget.c b/src/saffron_widget.c
index b673e48..955e265 100644
--- a/src/saffron_widget.c
+++ b/src/saffron_widget.c
@@ -22,6 +22,7 @@ void saffron_widget_init(SaffronWidget* widget) {
widget->pixel_perfect = false;
widget->type = SAFFRON_WIDGET_UNKNOWN;
+ widget->free = NULL;
}
SaffronWidget* saffron_widget_new(void) {
@@ -45,6 +46,10 @@ void saffron_widget_free(SaffronWidget *widget) {
saffron_widget_free(widget->children[i]);
}
+ if (widget->free) {
+ widget->free(widget);
+ }
+
free(widget->children);
free(widget);
}
@@ -90,7 +95,7 @@ SaffronWidget* saffron_widget_hit_test(SaffronWidget* widget, int x, int y) {
for (int i = widget->child_count - 1; i >= 0; i--) {
printf("[Saffron] recursing to child (%i)\n", i);
SaffronWidget* hit = saffron_widget_hit_test(widget->children[i], x, y);
- if (hit) return hit;
+ if (hit && hit->on_click) return hit;
}
return widget;