make on_press only activate when action is GLFW_PRESS

This commit is contained in:
jacekpoz 2024-08-13 17:01:03 +02:00
parent e2a0e79df8
commit 061e5799f9
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
3 changed files with 19 additions and 15 deletions

View file

@ -8,9 +8,8 @@ static const float color_step = 10.0f;
static PtkRect *r;
static void on_press(const int button, const int action, const int mods) {
static void on_press(const int button, const int mods) {
(void)button; (void)mods;
if (action == GLFW_PRESS) {
PTK_DEBUG("pressed!");
r->color.b += color_step / 255.0f;
if (r->color.b > 1.0f) {
@ -27,7 +26,6 @@ static void on_press(const int button, const int action, const int mods) {
}
}
}
}
int main(void) {
if (!ptk_init(800, 600, "button", (PtkVersion){ .major = 0, .minor = 1, .patch = 0 })) {

View file

@ -56,7 +56,7 @@ PTK_COMPONENT_DEFINE(PtkEllipse,
PtkColor color;
);
typedef void (*MouseButtonCallback)(const int button, const int action, const int mods);
typedef void (*MouseButtonCallback)(const int button, const int mods);
PTK_COMPONENT_DEFINE(PtkClickable,
MouseButtonCallback on_press;

View file

@ -5,6 +5,8 @@
#include <ptk_vk/components.h>
#include <ptk_vk/init.h>
#include <GLFW/glfw3.h>
static PtkHandle m_root_component;
static PTK_LIST(PtkHandle) m_components;
@ -171,6 +173,10 @@ bool intersects(const PtkHandle component, const PtkPos point) {
}
void vk_handle_mouse_button_input(const PtkPos cursor_pos, const int button, const int action, const int mods) {
if (action == GLFW_RELEASE) {
return;
}
for (size_t i = 0; i < m_components.size; ++i) {
const PtkHandle current = m_components.data[i];
if (current->type != PTK_COMPONENT_TYPE_CLICKABLE) {
@ -180,7 +186,7 @@ void vk_handle_mouse_button_input(const PtkPos cursor_pos, const int button, con
const PtkClickable *c = (PtkClickable *)current;
if (intersects((PtkHandle)c, cursor_pos)) {
c->on_press(button, action, mods);
c->on_press(button, mods);
vk_update_components();
}
}