From 50197a6a2158fe6e141ecdbb23a0f7212453956b Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Sun, 11 Aug 2024 21:09:02 +0200 Subject: [PATCH] change default component members and add PTK_COMPONENT_DEFINE --- include/ptk.h | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/include/ptk.h b/include/ptk.h index 8661353..22c86ff 100644 --- a/include/ptk.h +++ b/include/ptk.h @@ -1,6 +1,7 @@ #ifndef PTK_PTK_H_ #define PTK_PTK_H_ +#include #include #include @@ -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);