mod(mouse): fix input.Mouse.in method
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 46s
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 46s
Pass through mouse events where they actually match the corresponding `Container`. Adopt mouse event accordingly in `Scrollable` `Element` trait when passing through the mouse event to the scrollable `Container`.
This commit is contained in:
@@ -387,6 +387,10 @@ pub fn Container(comptime Event: type) type {
|
|||||||
try element.handle(.{ .resize = element_size });
|
try element.handle(.{ .resize = element_size });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
.mouse => |mouse| if (mouse.in(this.size)) {
|
||||||
|
try this.element.handle(event);
|
||||||
|
for (this.elements.items) |*element| try element.handle(event);
|
||||||
|
},
|
||||||
else => {
|
else => {
|
||||||
try this.element.handle(event);
|
try this.element.handle(event);
|
||||||
for (this.elements.items) |*element| try element.handle(event);
|
for (this.elements.items) |*element| try element.handle(event);
|
||||||
|
|||||||
@@ -112,6 +112,17 @@ pub fn Scrollable(Event: type) type {
|
|||||||
// TODO: not just pass through the given size, but rather the size that is necessary for scrollable content
|
// TODO: not just pass through the given size, but rather the size that is necessary for scrollable content
|
||||||
try this.container.handle(.{ .resize = size });
|
try this.container.handle(.{ .resize = size });
|
||||||
},
|
},
|
||||||
|
.mouse => |mouse| {
|
||||||
|
std.log.debug("mouse event detected in scrollable element {any}", .{mouse.in(this.size)});
|
||||||
|
try this.container.handle(.{
|
||||||
|
.mouse = .{
|
||||||
|
.col = mouse.col + this.anchor.col,
|
||||||
|
.row = mouse.row + this.anchor.row,
|
||||||
|
.button = mouse.button,
|
||||||
|
.kind = mouse.kind,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
else => try this.container.handle(event),
|
else => try this.container.handle(event),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ pub const Mouse = packed struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn in(this: @This(), size: Size) bool {
|
pub fn in(this: @This(), size: Size) bool {
|
||||||
return this.col >= size.anchor.col and this.col <= size.cols -| size.anchor.col and
|
return this.col >= size.anchor.col and this.col <= size.cols + size.anchor.col and
|
||||||
this.row >= size.anchor.row and this.row <= size.rows -| size.anchor.row;
|
this.row >= size.anchor.row and this.row <= size.rows + size.anchor.row;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user