change default component members and add PTK_COMPONENT_DEFINE

This commit is contained in:
jacekpoz 2024-08-11 21:09:02 +02:00
parent 2b5be4c732
commit 50197a6a21
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8

View file

@ -1,6 +1,7 @@
#ifndef PTK_PTK_H_
#define PTK_PTK_H_
#include <ptk_list.h>
#include <ptk_vec.h>
#include <stdbool.h>
@ -26,43 +27,41 @@ typedef enum {
PTK_COMPONENT_TYPE_BUTTON = 4,
} PtkComponentType;
typedef struct PtkComponent {
PtkComponentType type;
} PtkComponent;
PTK_LIST_DEFINE(PtkHandle);
typedef struct PtkBox {
PtkComponentType type;
size_t child_count;
PtkHandle *children;
} PtkBox;
#define PTK_COMPONENT_DEFINE(name, ...) \
typedef struct name {\
PtkComponentType type;\
PtkHandle parent;\
PTK_LIST(PtkHandle) children;\
__VA_ARGS__\
} name
typedef struct PtkTriangle {
PtkComponentType type;
PTK_COMPONENT_DEFINE(PtkComponent, );
PTK_COMPONENT_DEFINE(PtkTriangle,
PtkPos vertices[3];
PtkColor color;
} PtkTriangle;
);
typedef struct PtkRect {
PtkComponentType type;
PTK_COMPONENT_DEFINE(PtkRect,
PtkPos top_left;
PtkSize size;
PtkColor color;
} PtkRect;
);
typedef struct PtkEllipse {
PtkComponentType type;
PTK_COMPONENT_DEFINE(PtkEllipse,
PtkPos center;
PtkSize radii;
PtkColor color;
} PtkEllipse;
);
typedef void (*MouseButtonCallback)(int button, int action, int mods);
typedef struct PtkButton {
PtkComponentType type;
PTK_COMPONENT_DEFINE(PtkButton,
PtkHandle hitbox;
MouseButtonCallback on_press;
} PtkButton;
);
PtkHandle ptk_box(size_t child_count, PtkHandle *children);
PtkHandle ptk_triangle(PtkPos vertices[3], PtkColor color);