aboutsummaryrefslogtreecommitdiff
path: root/src/saffron_widget.c
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-04-09 14:08:23 +1200
committerArslaan Pathan <[email protected]>2026-04-09 14:08:23 +1200
commit0cebba8c7013201ec685b0ca35212294d3d009f3 (patch)
treecadeb245975e79aa5758724eac38c22d901ed2eb /src/saffron_widget.c
parent0f19e5f0175b0e031257ccd22f42e21baaf2f720 (diff)
downloadsaffron-0cebba8c7013201ec685b0ca35212294d3d009f3.tar.xz
saffron-0cebba8c7013201ec685b0ca35212294d3d009f3.zip
Click event routing
IT WORKS IT WORKS IT WORKS YESSSSSSSSSSSSSSSSS
Diffstat (limited to 'src/saffron_widget.c')
-rw-r--r--src/saffron_widget.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/saffron_widget.c b/src/saffron_widget.c
index 85b2013..932b7a5 100644
--- a/src/saffron_widget.c
+++ b/src/saffron_widget.c
@@ -1,8 +1,7 @@
#include <SDL3/SDL.h>
+#include <stdio.h>
#include <stdlib.h>
-#include <saffron_widget.h>
-#include <saffron_api.h>
-#include <saffron_window.h>
+#include <saffron.h>
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! */
@@ -57,3 +56,26 @@ void saffron_widget_add_child(SaffronWidget *parent, SaffronWidget *child) {
parent->child_count++;
}
+SaffronWidget* saffron_widget_hit_test(SaffronWidget* widget, int x, int y) {
+ if (!widget) {
+ printf("[saffron] hit test: widget is NULL!\n");
+ return NULL;
+ }
+ if (x < widget->x || x > widget->x + widget->w) {
+ printf("[saffron] hit test: widget failed X bounds check!\n");
+ return NULL;
+ }
+ if (y < widget->y || y > widget->y + widget->h) {
+ printf("[saffron] hit test: widget failed Y bounds check!\n");
+ return NULL;
+ }
+
+ // check children front to back
+ 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;
+ }
+
+ return widget;
+}