add get_component_id()

This commit is contained in:
jacekpoz 2024-09-10 09:56:39 +02:00
parent 40c8d69690
commit a6d741b995
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8

View file

@ -157,15 +157,20 @@ const char *ptk_component_type_to_str(PtkComponentType type) {
static uint64_t m_component_count = 0;
static uint64_t get_component_id(void) {
const uint64_t old = m_component_count;
m_component_count += 1;
return old;
}
PtkHandle ptk_box(const size_t child_count, PtkHandle *children) {
PtkComponent *ret = malloc(sizeof(PtkComponent));
*ret = (PtkComponent){
.id = m_component_count,
.id = get_component_id(),
.type = PTK_COMPONENT_TYPE_BOX,
.children = PTK_LIST_NEW(PtkHandle, child_count),
};
PTK_LIST_ADD_ALL_P(PtkHandle, ret->children, children, child_count);
m_component_count += 1;
return (PtkHandle)ret;
}
@ -173,12 +178,11 @@ PtkHandle ptk_box(const size_t child_count, PtkHandle *children) {
PtkHandle ptk_triangle(const PtkPos vertices[3], const PtkRGB color) {
PtkTriangle *ret = malloc(sizeof(PtkTriangle));
*ret = (PtkTriangle){
.id = m_component_count,
.id = get_component_id(),
.type = PTK_COMPONENT_TYPE_TRIANGLE,
.color = color,
};
memcpy(ret->vertices, vertices, sizeof(PtkPos) * 3);
m_component_count += 1;
return (PtkHandle)ret;
}
@ -186,13 +190,12 @@ PtkHandle ptk_triangle(const PtkPos vertices[3], const PtkRGB color) {
PtkHandle ptk_rect(const PtkPos top_left, const PtkSize size, const PtkRGB color) {
PtkRect *ret = malloc(sizeof(PtkRect));
*ret = (PtkRect){
.id = m_component_count,
.id = get_component_id(),
.type = PTK_COMPONENT_TYPE_RECT,
.top_left = top_left,
.size = size,
.color = color,
};
m_component_count += 1;
return (PtkHandle)ret;
}
@ -204,13 +207,12 @@ PtkHandle ptk_square(const PtkPos top_left, const float size, const PtkRGB color
PtkHandle ptk_ellipse(const PtkPos center, const PtkSize radii, const PtkRGB color) {
PtkEllipse *ret = malloc(sizeof(PtkEllipse));
*ret = (PtkEllipse){
.id = m_component_count,
.id = get_component_id(),
.type = PTK_COMPONENT_TYPE_ELLIPSE,
.center = center,
.radii = radii,
.color = color,
};
m_component_count += 1;
return (PtkHandle)ret;
}
@ -222,13 +224,12 @@ PtkHandle ptk_circle(const PtkPos center, const float radius, const PtkRGB color
PtkHandle ptk_clickable(PtkHandle hitbox, const MouseButtonCallback on_press) {
PtkClickable *ret = malloc(sizeof(PtkClickable));
*ret = (PtkClickable){
.id = m_component_count,
.id = get_component_id(),
.type = PTK_COMPONENT_TYPE_CLICKABLE,
.children = PTK_LIST_NEW(PtkHandle, 1),
.on_press = on_press,
};
PTK_LIST_ADD(PtkHandle, ret->children, hitbox);
m_component_count += 1;
return (PtkHandle)ret;
}