this repo has no description
13
fork

Configure Feed

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

vxfw: implement event capturing for mouse events

+63 -5
+63 -5
src/vxfw/App.zig
··· 248 248 if (item.widget.eql(last_handler)) break; 249 249 } else { 250 250 try last_handler.handleEvent(ctx, .mouse_leave); 251 + self.maybe_last_handler = null; 251 252 try app.handleCommand(&ctx.cmds); 252 253 } 253 254 } 254 - while (hits.popOrNull()) |item| { 255 + 256 + const maybe_target = hits.popOrNull(); 257 + 258 + // capturing phase 259 + ctx.phase = .capturing; 260 + for (hits.items) |item| { 255 261 var m_local = mouse; 256 262 m_local.col = item.local.col; 257 263 m_local.row = item.local.row; 258 264 try item.widget.handleEvent(ctx, .{ .mouse = m_local }); 259 265 try app.handleCommand(&ctx.cmds); 260 266 261 - // If the event wasn't consumed, we keep passing it on 262 - if (!ctx.consume_event) continue; 267 + // If the event was consumed, we check if we need to send a mouse_leave and return 268 + if (ctx.consume_event) { 269 + if (self.maybe_last_handler) |last_handler| { 270 + if (!last_handler.eql(item.widget)) { 271 + try last_handler.handleEvent(ctx, .mouse_leave); 272 + self.maybe_last_handler = item.widget; 273 + try app.handleCommand(&ctx.cmds); 274 + } 275 + self.maybe_last_handler = item.widget; 276 + return; 277 + } 278 + } 279 + } 263 280 264 - self.maybe_last_handler = item.widget; 265 - return; 281 + // target phase 282 + ctx.phase = .at_target; 283 + if (maybe_target) |target| { 284 + var m_local = mouse; 285 + m_local.col = target.local.col; 286 + m_local.row = target.local.row; 287 + try target.widget.handleEvent(ctx, .{ .mouse = m_local }); 288 + try app.handleCommand(&ctx.cmds); 289 + // If the event was consumed, we check if we need to send a mouse_leave and return 290 + if (ctx.consume_event) { 291 + if (self.maybe_last_handler) |last_handler| { 292 + if (!last_handler.eql(target.widget)) { 293 + try last_handler.handleEvent(ctx, .mouse_leave); 294 + self.maybe_last_handler = target.widget; 295 + try app.handleCommand(&ctx.cmds); 296 + } 297 + self.maybe_last_handler = target.widget; 298 + return; 299 + } 300 + } 301 + } 302 + 303 + // Bubbling phase 304 + ctx.phase = .bubbling; 305 + while (hits.popOrNull()) |item| { 306 + var m_local = mouse; 307 + m_local.col = item.local.col; 308 + m_local.row = item.local.row; 309 + try item.widget.handleEvent(ctx, .{ .mouse = m_local }); 310 + try app.handleCommand(&ctx.cmds); 311 + 312 + // If the event was consumed, we check if we need to send a mouse_leave and return 313 + if (ctx.consume_event) { 314 + if (self.maybe_last_handler) |last_handler| { 315 + if (!last_handler.eql(item.widget)) { 316 + try last_handler.handleEvent(ctx, .mouse_leave); 317 + self.maybe_last_handler = item.widget; 318 + try app.handleCommand(&ctx.cmds); 319 + } 320 + self.maybe_last_handler = item.widget; 321 + return; 322 + } 323 + } 266 324 } 267 325 268 326 // If no one handled the mouse, we assume it exited