From 26f38b342bb2c9356a92c9a9de52739f9204e730 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Sat, 25 Oct 2025 15:11:55 +0200 Subject: [PATCH] fix weird input behavior --- lib/ugui.c3l/src/core.c3 | 3 ++- lib/ugui.c3l/src/input.c3 | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/ugui.c3l/src/core.c3 b/lib/ugui.c3l/src/core.c3 index e82ff32..8fc1e59 100644 --- a/lib/ugui.c3l/src/core.c3 +++ b/lib/ugui.c3l/src/core.c3 @@ -279,7 +279,8 @@ fn void? Ctx.frame_end(&ctx) ctx.input = ctx.current_input; ctx.current_input.events = {}; ctx.current_input.mouse.scroll = {}; - ctx.current_input.keyboard = {}; + ctx.current_input.mouse.updated = BTN_NONE; + ctx.current_input.keyboard.text_len = 0; // DO THE LAYOUT ctx.layout_element_tree()!; diff --git a/lib/ugui.c3l/src/input.c3 b/lib/ugui.c3l/src/input.c3 index 41fc703..5bc7c31 100644 --- a/lib/ugui.c3l/src/input.c3 +++ b/lib/ugui.c3l/src/input.c3 @@ -105,12 +105,10 @@ fn void Ctx.input_changefocus(&ctx, bool has_focus) ctx.has_focus = has_focus; } -macro Ctx.mouse_pressed(&ctx) => ctx.current_input.mouse.updated & ctx.current_input.mouse.down; -macro Ctx.mouse_released(&ctx) => ctx.current_input.mouse.updated & ~ctx.current_input.mouse.down; -macro Ctx.mouse_down(&ctx) => ctx.current_input.mouse.down; - -// FIXME: hthis compairson could be done with a cast using MouseButtons.inner -// property but I could not figure out how +// NOTE: all of these refer to the previous frame's data +macro Ctx.mouse_pressed(&ctx) => ctx.input.mouse.updated & ctx.input.mouse.down; +macro Ctx.mouse_released(&ctx) => ctx.input.mouse.updated & ~ctx.input.mouse.down; +macro Ctx.mouse_down(&ctx) => ctx.input.mouse.down; macro Ctx.is_mouse_pressed(&ctx, MouseButtons btn) => (ctx.mouse_pressed() & btn) != BTN_NONE; macro Ctx.is_mouse_released(&ctx, MouseButtons btn) => (ctx.mouse_released() & btn) != BTN_NONE; macro Ctx.is_mouse_down(&ctx, MouseButtons btn) => (ctx.mouse_down() & btn) != BTN_NONE; @@ -121,7 +119,7 @@ fn void Ctx.input_mouse_button(&ctx, MouseButtons buttons) { ctx.current_input.mouse.updated = ctx.current_input.mouse.down ^ buttons; ctx.current_input.mouse.down = buttons; - ctx.current_input.events.mouse_btn = (uint)ctx.current_input.mouse.down != 0 || (uint)ctx.current_input.mouse.updated != 0; + ctx.current_input.events.mouse_btn = ctx.current_input.mouse.down != BTN_NONE || ctx.current_input.mouse.updated != BTN_NONE; } // Mouse was moved, report absolute position @@ -226,10 +224,13 @@ fn String Ctx.get_keys(&ctx) => (String)ctx.input.keyboard.text[:ctx.input.keybo fn ModKeys Ctx.get_mod(&ctx) => ctx.input.keyboard.modkeys; // Modifier keys, like control or backspace -// TODO: make this call repetible to input modkeys one by one <* @param [&inout] ctx *> -fn void Ctx.input_mod_keys(&ctx, ModKeys modkeys) +fn void Ctx.input_mod_keys(&ctx, ModKeys modkeys, bool set) { - ctx.current_input.keyboard.modkeys = modkeys; + if (set) { + ctx.current_input.keyboard.modkeys |= modkeys; + } else { + ctx.current_input.keyboard.modkeys &= ~modkeys; + } ctx.current_input.events.mod_key = (uint)ctx.current_input.keyboard.modkeys != 0; }