add self param to on_press
This commit is contained in:
parent
04ff88c4e6
commit
3f2df4ace8
3 changed files with 15 additions and 13 deletions
|
@ -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
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue