change default component members and add PTK_COMPONENT_DEFINE
This commit is contained in:
parent
2b5be4c732
commit
50197a6a21
1 changed files with 19 additions and 20 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue