use children[0] for the hitbox in PtkClickable

This commit is contained in:
jacekpoz 2024-08-13 15:14:13 +02:00
parent 3231124346
commit db65f8d5bf
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
3 changed files with 3 additions and 9 deletions

View file

@ -59,7 +59,6 @@ PTK_COMPONENT_DEFINE(PtkEllipse,
typedef void (*MouseButtonCallback)(const int button, const int action, const int mods);
PTK_COMPONENT_DEFINE(PtkClickable,
PtkHandle hitbox;
MouseButtonCallback on_press;
);

View file

@ -190,9 +190,10 @@ PtkHandle ptk_clickable(PtkHandle hitbox, const MouseButtonCallback on_press) {
PtkClickable *ret = malloc(sizeof(PtkClickable));
*ret = (PtkClickable){
.type = PTK_COMPONENT_TYPE_CLICKABLE,
.hitbox = hitbox,
.children = PTK_LIST_NEW(PtkHandle, 1),
.on_press = on_press,
};
PTK_LIST_ADD(PtkHandle, ret->children, hitbox);
return (PtkHandle)ret;
}

View file

@ -90,12 +90,6 @@ void vk_component(PtkHandle component) {
PTK_LIST_ADD(PtkHandle, m_components, component);
if (component->type == PTK_COMPONENT_TYPE_CLICKABLE) {
PtkClickable *c = (PtkClickable *)component;
vk_component(c->hitbox);
return;
}
switch (component->type) {
case PTK_COMPONENT_TYPE_TRIANGLE: {
triangle((PtkTriangle *)component, 0);
@ -162,7 +156,7 @@ bool intersects(const PtkHandle component, const PtkPos point) {
case PTK_COMPONENT_TYPE_ELLIPSE:
return ellipse_intersects(*(PtkEllipse *)component, point);
case PTK_COMPONENT_TYPE_CLICKABLE:
return intersects(((PtkClickable *)component)->hitbox, point);
return intersects(component->children.data[0], point);
}
}