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