add(event): mouse event has relative position for receiving elements
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Has been cancelled

This commit is contained in:
2025-04-20 20:53:46 +02:00
parent 50450f3bbc
commit a4293ff243
3 changed files with 118 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
const std = @import("std");
const input = @import("input.zig");
const isTaggedUnion = @import("event.zig").isTaggedUnion;
@@ -870,7 +871,12 @@ pub fn Container(comptime Event: type) type {
pub fn handle(this: *@This(), event: Event) !void {
switch (event) {
.mouse => |mouse| if (mouse.in(this.origin, this.size)) {
try this.element.handle(event);
// the element receives the mouse event with relative position
std.debug.assert(mouse.x >= this.origin.x and mouse.y >= this.origin.y);
var relative_mouse: input.Mouse = mouse;
relative_mouse.x -= this.origin.x;
relative_mouse.y -= this.origin.y;
try this.element.handle(.{ .mouse = relative_mouse });
for (this.elements.items) |*element| try element.handle(event);
},
else => {