aboutsummaryrefslogtreecommitdiff
path: root/src/saffron_layout.c
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-04-22 21:06:58 +1200
committerArslaan Pathan <[email protected]>2026-04-22 21:06:58 +1200
commit289ca3be66a5731fdcd8e2901514ddbb113c5076 (patch)
tree6ec66f374e042a57bcfaa288d0aa444517488d45 /src/saffron_layout.c
parent76516edf2c8c6ba36c0abb48871b5e69e9930dd2 (diff)
downloadsaffron-289ca3be66a5731fdcd8e2901514ddbb113c5076.tar.xz
saffron-289ca3be66a5731fdcd8e2901514ddbb113c5076.zip
Make the layout work roughly, make boxes have a size, update test code to work with boxes
Diffstat (limited to 'src/saffron_layout.c')
-rw-r--r--src/saffron_layout.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/saffron_layout.c b/src/saffron_layout.c
index c714bfa..62c7de2 100644
--- a/src/saffron_layout.c
+++ b/src/saffron_layout.c
@@ -1,5 +1,6 @@
#include "saffron_layout.h"
#include "saffron_api.h"
+#include "saffron_widget.h"
#include <SDL3/SDL_video.h>
#include <stdio.h>
#include <stdlib.h>
@@ -7,12 +8,14 @@
#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* saffron_box_new(SaffronOrientation orientation, SaffronHorizontalAlignment halign, SaffronVerticalAlignment valign, int spacing, int padding, int margin, int width, int height) {
SaffronBox* box = malloc(sizeof(SaffronBox));
if (!box) return NULL;
saffron_widget_init((SaffronWidget*)box);
+ ((SaffronWidget*)box)->type = SAFFRON_WIDGET_BOX;
+
box->orientation = orientation;
box->halign = halign;
box->valign = valign;
@@ -36,6 +39,28 @@ void saffron_box_layout(SaffronBox* box) {
int inner_w = content_w - (box->padding * 2);
int inner_h = content_h - (box->padding * 2);
- /* TODO actually make it layout */
+ int x_offset = inner_x;
+ int y_offset = inner_y;
+
+ /* TODO make it account for stretch and stuff */
+ for (int i = 0; i < ((SaffronWidget*)box)->child_count; i++) {
+ SaffronWidget* child = ((SaffronWidget*)box)->children[i];
+
+ if (child->pixel_perfect) continue;
+
+ if (box->orientation == SAFFRON_ORIENTATION_HORIZONTAL) {
+ child->x = x_offset;
+ child->y = y_offset;
+ x_offset += child->w + box->spacing;
+ } else {
+ child->x = x_offset;
+ child->y = y_offset;
+ y_offset += child->h + box->spacing;
+ }
+
+ if (child->type == SAFFRON_WIDGET_BOX) {
+ saffron_box_layout((SaffronBox*)child);
+ }
+ }
return;
}