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
|
#ifndef SAFFRON_WIDGET_H
#define SAFFRON_WIDGET_H
#include <SDL3/SDL.h>
typedef enum {
SAFFRON_SIZE_FIXED, // keep normal size
SAFFRON_SIZE_STRETCH, // stretch this axis to the maximum size
SAFFRON_SIZE_SCALE // scale but keep aspect ratio. this must be set on BOTH axes (width AND height) to work. if it's only set on one, then it will default back to fixed
} SaffronSizeMode;
typedef enum {
SAFFRON_WIDGET_UNKNOWN,
SAFFRON_WIDGET_BOX,
SAFFRON_WIDGET_BUTTON,
SAFFRON_WIDGET_TEXT
} SaffronWidgetType;
typedef struct SaffronWidget {
int x, y, w, h;
void (*draw)(struct SaffronWidget* self, SDL_Renderer* renderer);
void (*on_click)(struct SaffronWidget* self);
struct SaffronWidget* parent;
struct SaffronWidget** children;
int child_count;
SaffronSizeMode width_mode;
SaffronSizeMode height_mode;
bool pixel_perfect; // Do we scale dynamically (SaffronSizeMode, etc) or use raw x, y, w, h values? If this is true, the SaffronSizeModes from earlier will be ignored. this pretty much tells the engine NOT to layout your widgets, don't expect it to allocate size for it. get better
SaffronWidgetType type;
void (*free)(struct SaffronWidget* self);
} SaffronWidget;
#endif
|