diff --git a/examples/button.c b/examples/button.c index a163ec7..8b86b64 100644 --- a/examples/button.c +++ b/examples/button.c @@ -6,9 +6,7 @@ static const float step = 5.0f; static float hue = 360.0f; -static PtkRect *r; - -static void on_press(const int button, const int mods) { +static void on_press(PtkClickable *self, const int button, const int mods) { (void)button; (void)mods; PTK_DEBUG("pressed!"); @@ -17,6 +15,7 @@ static void on_press(const int button, const int mods) { hue = 0.0f; } + PtkRect *r = (PtkRect *)self->children.data[0]; r->color = ptk_hsv_to_rgb((PtkHSV){ .h = hue, .s = 360.0f, .v = 360.0f }); } @@ -25,13 +24,14 @@ int main(void) { return EXIT_FAILURE; } - r = (PtkRect *)ptk_rect( - (PtkPos){ .x = 100.0f, .y = 100.0f }, - (PtkSize){ .w = 100.0f, .h = 50.0f }, - (PtkRGB){ .r = 1.0f, .g = 0.0f, .b = 0.0f } - ); - return ptk_run( - ptk_clickable((PtkHandle)r, on_press) + ptk_clickable( + ptk_rect( + (PtkPos){ .x = 100.0f, .y = 100.0f }, + (PtkSize){ .w = 100.0f, .h = 50.0f }, + (PtkRGB){ .r = 1.0f, .g = 0.0f, .b = 0.0f } + ), + on_press + ) ); } diff --git a/include/ptk.h b/include/ptk.h index fb266ba..c17d406 100644 --- a/include/ptk.h +++ b/include/ptk.h @@ -57,7 +57,9 @@ PTK_COMPONENT_DEFINE(PtkEllipse, PtkRGB color; ); -typedef void (*MouseButtonCallback)(const int button, const int mods); +typedef struct PtkClickable PtkClickable; + +typedef void (*MouseButtonCallback)(PtkClickable *self, const int button, const int mods); PTK_COMPONENT_DEFINE(PtkClickable, MouseButtonCallback on_press; diff --git a/src/ptk_vk/components.c b/src/ptk_vk/components.c index 57bdc2e..a2739fb 100644 --- a/src/ptk_vk/components.c +++ b/src/ptk_vk/components.c @@ -183,10 +183,10 @@ void vk_handle_mouse_button_input(const PtkPos cursor_pos, const int button, con continue; } - const PtkClickable *c = (PtkClickable *)current; + PtkClickable *c = (PtkClickable *)current; if (intersects((PtkHandle)c, cursor_pos)) { - c->on_press(button, mods); + c->on_press(c, button, mods); vk_update_components(); } }