aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-04-21 15:28:04 +1200
committerArslaan Pathan <[email protected]>2026-04-21 15:28:04 +1200
commit12fb8e70c79fb262a06431bfbd0e4ce97380d2a8 (patch)
tree684a4ef53637317486736c6a5bc7e9b823336b2f /src
parent3cdc4ac982c0a708dcd50a2f83f984303342902b (diff)
downloadsaffron-12fb8e70c79fb262a06431bfbd0e4ce97380d2a8.tar.xz
saffron-12fb8e70c79fb262a06431bfbd0e4ce97380d2a8.zip
Add foundations for layout
Diffstat (limited to 'src')
-rw-r--r--src/saffron_layout.c26
-rw-r--r--src/saffron_widget.c13
-rw-r--r--src/saffron_window.c2
3 files changed, 36 insertions, 5 deletions
diff --git a/src/saffron_layout.c b/src/saffron_layout.c
new file mode 100644
index 0000000..cc91246
--- /dev/null
+++ b/src/saffron_layout.c
@@ -0,0 +1,26 @@
+#include "saffron_layout.h"
+#include "saffron_api.h"
+#include <SDL3/SDL_video.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <SDL3/SDL.h>
+#include <SDL3_ttf/SDL_ttf.h>
+#include <saffron.h>
+
+SaffronBox* saffron_box_new(SaffronOrientation orientation, SaffronHorizontalAlignment halign, SaffronVerticalAlignment valign, int spacing, int padding, int margin) {
+ SaffronBox* box = malloc(sizeof(SaffronBox));
+ if (!box) return NULL;
+
+ saffron_widget_init((SaffronWidget*)box);
+
+ box->orientation = orientation;
+ box->halign = halign;
+ box->valign = valign;
+ box->spacing = spacing;
+ box->padding = padding;
+ box->margin = margin;
+
+ return box;
+}
+
+
diff --git a/src/saffron_widget.c b/src/saffron_widget.c
index 932b7a5..850d1b8 100644
--- a/src/saffron_widget.c
+++ b/src/saffron_widget.c
@@ -3,10 +3,7 @@
#include <stdlib.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! */
- SaffronWidget* widget = malloc(sizeof(SaffronWidget));
-
+void saffron_widget_init(SaffronWidget* widget) {
widget->x = 0;
widget->y = 0;
widget->w = 0;
@@ -18,6 +15,14 @@ SaffronWidget* saffron_widget_new(void) {
widget->parent = NULL;
widget->children = NULL;
widget->child_count = 0;
+}
+
+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! */
+ SaffronWidget* widget = malloc(sizeof(SaffronWidget));
+ if (widget) {
+ saffron_widget_init(widget);
+ }
return widget;
}
diff --git a/src/saffron_window.c b/src/saffron_window.c
index a25fa0e..c595c08 100644
--- a/src/saffron_window.c
+++ b/src/saffron_window.c
@@ -7,7 +7,7 @@
SaffronWindow* saffron_window_new(const char* title, int w, int h) {
SaffronWindow* window = malloc(sizeof(SaffronWindow));
- window->root = saffron_widget_new(); // frick, need to implement this.
+ window->root = saffron_widget_new();
window->title = title;
window->w = window->root->w = w;
window->h = window->root->h = h;