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
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Has been cancelled
This commit is contained in:
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user