Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
freref committed Nov 12, 2024
2 parents 5af63e9 + 1fd920a commit eb9244b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/vxfw/App.zig
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ const MouseHandler = struct {
var m_local = mouse;
m_local.col = item.local.col;
m_local.row = item.local.row;
try item.widget.handleEvent(ctx, .{ .mouse = m_local });
try item.widget.captureEvent(ctx, .{ .mouse = m_local });
try app.handleCommand(&ctx.cmds);

// If the event was consumed, we check if we need to send a mouse_leave and return
Expand Down
7 changes: 7 additions & 0 deletions src/vxfw/vxfw.zig
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,16 @@ pub const MaxSize = struct {
/// The Widget interface
pub const Widget = struct {
userdata: *anyopaque,
captureHandler: ?*const fn (userdata: *anyopaque, ctx: *EventContext, event: Event) anyerror!void = null,
eventHandler: ?*const fn (userdata: *anyopaque, ctx: *EventContext, event: Event) anyerror!void = null,
drawFn: *const fn (userdata: *anyopaque, ctx: DrawContext) Allocator.Error!Surface,

pub fn captureEvent(self: Widget, ctx: *EventContext, event: Event) anyerror!void {
if (self.captureHandler) |handle| {
return handle(self.userdata, ctx, event);
}
}

pub fn handleEvent(self: Widget, ctx: *EventContext, event: Event) anyerror!void {
if (self.eventHandler) |handle| {
return handle(self.userdata, ctx, event);
Expand Down

0 comments on commit eb9244b

Please sign in to comment.