From 2cc161aabfe5c1343ca504b79a6a1c7706048a91 Mon Sep 17 00:00:00 2001 From: Arslaan Pathan Date: Thu, 30 Apr 2026 13:06:18 +1200 Subject: Start work on button implementation(s) --- include/saffron_api.h | 4 ++++ include/saffron_widget.h | 1 + src/saffron_button.c | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 src/saffron_button.c diff --git a/include/saffron_api.h b/include/saffron_api.h index 0518dcb..d64b480 100644 --- a/include/saffron_api.h +++ b/include/saffron_api.h @@ -5,6 +5,7 @@ #include "saffron_window.h" #include "saffron_layout.h" #include "saffron_text.h" +#include "saffron_button.h" #include #include #include @@ -30,4 +31,7 @@ void saffron_box_layout(SaffronBox* box); SaffronText* saffron_text_new(const char* text, TTF_Font* font, SDL_Color color); void saffron_text_set_text(SaffronText* text, const char* new_text); +SaffronButton* saffron_button_new(bool enabled, void (*callback)(SaffronButton* self), int w, int h); +SaffronButton* saffron_button_new_with_text(SaffronText* text, bool enabled, void (*callback)(SaffronButton* self), int w, int h); + #endif diff --git a/include/saffron_widget.h b/include/saffron_widget.h index 5c0005c..8b9fc3c 100644 --- a/include/saffron_widget.h +++ b/include/saffron_widget.h @@ -12,6 +12,7 @@ typedef enum { typedef enum { SAFFRON_WIDGET_UNKNOWN, SAFFRON_WIDGET_BOX, + SAFFRON_WIDGET_BUTTON, SAFFRON_WIDGET_TEXT } SaffronWidgetType; diff --git a/src/saffron_button.c b/src/saffron_button.c new file mode 100644 index 0000000..f0cf77e --- /dev/null +++ b/src/saffron_button.c @@ -0,0 +1,21 @@ +#include +#include +#include + +static void saffron_button_draw(SaffronWidget* widget, SDL_Renderer* renderer) { + // do stuff here +} + +SaffronButton* saffron_button_new(bool enabled, void (*callback)(SaffronButton* self), int width, int height) { + SaffronButton* button = malloc(sizeof(SaffronButton)); + saffron_widget_init((SaffronWidget*)button); + + ((SaffronWidget*)button)->type = SAFFRON_WIDGET_BUTTON; + ((SaffronWidget*)button)->draw = saffron_button_draw; + + button->callback = callback; + button->enabled = enabled; + button->base = *saffron_box_new(SAFFRON_ORIENTATION_HORIZONTAL, SAFFRON_HALIGN_CENTER, SAFFRON_VALIGN_CENTER, 5, 5, 0, width, height); + + return button; +} -- cgit v1.2.3