aboutsummaryrefslogtreecommitdiff
path: root/src/saffron_layout.c
blob: c714bfa5d38c55abc52f363680ef32e5c240ce44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#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;
}

void saffron_box_layout(SaffronBox* box) {
	if (!box || ((SaffronWidget*)box)->child_count == 0) return;

	int content_x = ((SaffronWidget*)box)->x + box->margin;
	int content_y = ((SaffronWidget*)box)->y + box->margin;
	int content_w = ((SaffronWidget*)box)->w - (box->margin * 2);
	int content_h = ((SaffronWidget*)box)->h - (box->margin * 2);

	int inner_x = content_x + box->padding;
	int inner_y = content_y + box->padding;
	int inner_w = content_w - (box->padding * 2);
	int inner_h = content_h - (box->padding * 2);

	/* TODO actually make it layout */
	return;
}