From fab6fd33d27c0cdc50e9e1af9361a74adeb22360 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Mon, 16 Jan 2023 17:48:34 +0100 Subject: [PATCH] check hover element on frame begin --- ugui.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ugui.c b/ugui.c index c2fbcb4..0581673 100644 --- a/ugui.c +++ b/ugui.c @@ -1018,8 +1018,17 @@ int ug_frame_begin(ug_ctx_t *ctx) ug_rect_t r = c->rca; EXPAND(r, SZ_INT(ctx->style_px->border.size)); - if (INTERSECTS(v, r)) + if (INTERSECTS(v, r)) { ctx->hover_cnt = c->id; + // update element hover for the hovered container + for (int i = 0; i < c->elem_stack.idx; i++) { + ug_element_t *e = &c->elem_stack.items[i]; + if (INTERSECTS(ctx->mouse.pos, e->rca)) { + c->hover_elem = e->id; + break; + } + } + } } printf("\n"); @@ -1307,9 +1316,11 @@ int handle_element(ug_ctx_t *ctx, ug_container_t *cnt, ug_element_t *elem) // floating cont. over bodies if (ctx->hover_cnt != cnt->id) return 0; + // if the element is not selected nor hovered then do nothing + if (cnt->hover_elem != elem->id && cnt->selected_elem != elem->id) + return 0; - if (INTERSECTS(ctx->mouse.pos, elem->rca)) { - cnt->hover_elem = elem->id; + if (cnt->hover_elem == elem->id) { if (MOUSEDOWN(ctx, BTN_ANY)) cnt->selected_elem = elem->id; } else {