diff options
| -rw-r--r-- | include/saffron.h | 1 | ||||
| -rw-r--r-- | include/saffron_api.h | 4 | ||||
| -rw-r--r-- | include/saffron_layout.h | 33 | ||||
| -rw-r--r-- | meson.build | 2 | ||||
| -rw-r--r-- | src/saffron_layout.c | 26 | ||||
| -rw-r--r-- | src/saffron_widget.c | 13 | ||||
| -rw-r--r-- | src/saffron_window.c | 2 |
7 files changed, 75 insertions, 6 deletions
diff --git a/include/saffron.h b/include/saffron.h index aae8086..d5cc59f 100644 --- a/include/saffron.h +++ b/include/saffron.h @@ -6,5 +6,6 @@ #include "saffron_text.h" #include "saffron_widget.h" #include "saffron_window.h" +#include "saffron_layout.h" #endif diff --git a/include/saffron_api.h b/include/saffron_api.h index c2e6c9c..e8fdfb8 100644 --- a/include/saffron_api.h +++ b/include/saffron_api.h @@ -3,12 +3,14 @@ #include "saffron_widget.h" /* satisfy the lsp and also if someone includes api without the saffron.h wrapper (you lunatic) then it still works */ #include "saffron_window.h" +#include "saffron_layout.h" bool saffron_init(void); void saffron_quit(void); void saffron_widget_draw(SaffronWidget* widget, SDL_Renderer *renderer); void saffron_widget_add_child(SaffronWidget* parent, SaffronWidget* child); +void saffron_widget_init(SaffronWidget* widget); /* generic primitive for generic widgets as said below. saffron_widget_new just calls this under the hood */ SaffronWidget* saffron_widget_new(); /* generic primitive for generic widgets, e.g. the window root. ideally window root is a hbox/vbox/box once those are implemented */ void saffron_widget_free(SaffronWidget* widget); @@ -18,4 +20,6 @@ void saffron_window_show(SaffronWindow* window); void saffron_window_main(SaffronWindow* window); SaffronWidget* saffron_widget_hit_test(SaffronWidget* widget, int x, int y); +SaffronBox* saffron_box_new(SaffronOrientation orientation, SaffronHorizontalAlignment halign, SaffronVerticalAlignment valign, int spacing, int padding, int margin); + #endif diff --git a/include/saffron_layout.h b/include/saffron_layout.h new file mode 100644 index 0000000..9e5ff40 --- /dev/null +++ b/include/saffron_layout.h @@ -0,0 +1,33 @@ +#ifndef SAFFRON_LAYOUT_H +#define SAFFRON_LAYOUT_H + +#include "saffron_widget.h" + +typedef enum { + SAFFRON_ORIENTATION_VERTICAL, + SAFFRON_ORIENTATION_HORIZONTAL +} SaffronOrientation; + +typedef enum { + SAFFRON_HALIGN_LEFT, + SAFFRON_HALIGN_CENTER, + SAFFRON_HALIGN_RIGHT +} SaffronHorizontalAlignment; + +typedef enum { + SAFFRON_VALIGN_TOP, + SAFFRON_VALIGN_CENTER, + SAFFRON_VALIGN_BOTTOM +} SaffronVerticalAlignment; + +typedef struct { + SaffronWidget base; + SaffronOrientation orientation; + SaffronHorizontalAlignment halign; + SaffronVerticalAlignment valign; + int spacing; + int padding; + int margin; +} SaffronBox; + +#endif diff --git a/meson.build b/meson.build index e53b388..01f7716 100644 --- a/meson.build +++ b/meson.build @@ -10,7 +10,7 @@ sources = [ 'src/saffron.c', 'src/saffron_window.c', 'src/saffron_widget.c', - # TODO add more stuff like text/button + 'src/saffron_layout.c' ] saffron_lib = static_library('saffron', sources, include_directories: inc, dependencies: deps) 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; |
