this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

vxfw: add separate function pointer for event capturing

Move capture handling of events to a different method on Widget. Having
capturing phase in the same method makes it very easy to accidentally
capture an event, producing confusing results. Browsers and GTK both
require handlers to explicitly listen to capturing phase events, so
there is precedence for having this as a separate method. For
applications that want to handle it all within the same function, the
signature is the same so they can use the same function for both methods
and achieve the same result.

+8 -1
+1 -1
src/vxfw/App.zig
··· 261 261 var m_local = mouse; 262 262 m_local.col = item.local.col; 263 263 m_local.row = item.local.row; 264 - try item.widget.handleEvent(ctx, .{ .mouse = m_local }); 264 + try item.widget.captureEvent(ctx, .{ .mouse = m_local }); 265 265 try app.handleCommand(&ctx.cmds); 266 266 267 267 // If the event was consumed, we check if we need to send a mouse_leave and return
+7
src/vxfw/vxfw.zig
··· 196 196 /// The Widget interface 197 197 pub const Widget = struct { 198 198 userdata: *anyopaque, 199 + captureHandler: ?*const fn (userdata: *anyopaque, ctx: *EventContext, event: Event) anyerror!void = null, 199 200 eventHandler: ?*const fn (userdata: *anyopaque, ctx: *EventContext, event: Event) anyerror!void = null, 200 201 drawFn: *const fn (userdata: *anyopaque, ctx: DrawContext) Allocator.Error!Surface, 202 + 203 + pub fn captureEvent(self: Widget, ctx: *EventContext, event: Event) anyerror!void { 204 + if (self.captureHandler) |handle| { 205 + return handle(self.userdata, ctx, event); 206 + } 207 + } 201 208 202 209 pub fn handleEvent(self: Widget, ctx: *EventContext, event: Event) anyerror!void { 203 210 if (self.eventHandler) |handle| {