this repo has no description
13
fork

Configure Feed

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

vxfw: remove handles_mouse from Surface

Don't require that surfaces explicitly declare mouse handling. We either
pass an event to the eventHandler or we don't. Along with this, we
remove all native widget passthrough events (IE we never pass an event
to a child). Native widgets which don't handle events also set
eventHandler to null, which prevents any null pointer issues also

+1 -41
-1
src/vxfw/Button.zig
··· 110 110 111 111 var button_surf = try vxfw.Surface.initWithChildren(ctx.arena, self.widget(), surf.size, surf.children); 112 112 @memset(button_surf.buffer, .{ .style = style }); 113 - button_surf.handles_mouse = true; 114 113 button_surf.focusable = true; 115 114 return button_surf; 116 115 }
-6
src/vxfw/Center.zig
··· 12 12 pub fn widget(self: *const Center) vxfw.Widget { 13 13 return .{ 14 14 .userdata = @constCast(self), 15 - .eventHandler = typeErasedEventHandler, 16 15 .drawFn = typeErasedDrawFn, 17 16 }; 18 - } 19 - 20 - fn typeErasedEventHandler(ptr: *anyopaque, ctx: *vxfw.EventContext, event: vxfw.Event) anyerror!void { 21 - const self: *const Center = @ptrCast(@alignCast(ptr)); 22 - return self.child.handleEvent(ctx, event); 23 17 } 24 18 25 19 fn typeErasedDrawFn(ptr: *anyopaque, ctx: vxfw.DrawContext) Allocator.Error!vxfw.Surface {
-15
src/vxfw/ListView.zig
··· 109 109 self.ensureScroll(); 110 110 return ctx.consumeAndRedraw(); 111 111 } 112 - 113 - // All other keypresses go to our focused child 114 - switch (self.children) { 115 - .slice => |slice| { 116 - if (slice.len == 0) return; 117 - const child = slice[self.cursor]; 118 - return child.handleEvent(ctx, event); 119 - }, 120 - .builder => |builder| { 121 - if (builder.itemAtIdx(self.cursor, self.cursor)) |child| { 122 - return child.handleEvent(ctx, event); 123 - } 124 - }, 125 - } 126 112 }, 127 113 else => {}, 128 114 } ··· 307 293 // Set state 308 294 { 309 295 surface.focusable = true; 310 - surface.handles_mouse = true; 311 296 // Assume we have more. We only know we don't after drawing 312 297 self.scroll.has_more = true; 313 298 }
-6
src/vxfw/Padding.zig
··· 43 43 pub fn widget(self: *const Padding) vxfw.Widget { 44 44 return .{ 45 45 .userdata = @constCast(self), 46 - .eventHandler = typeErasedEventHandler, 47 46 .drawFn = typeErasedDrawFn, 48 47 }; 49 - } 50 - 51 - fn typeErasedEventHandler(ptr: *anyopaque, ctx: *vxfw.EventContext, event: vxfw.Event) anyerror!void { 52 - const self: *const Padding = @ptrCast(@alignCast(ptr)); 53 - return self.child.handleEvent(ctx, event); 54 48 } 55 49 56 50 fn typeErasedDrawFn(ptr: *anyopaque, ctx: vxfw.DrawContext) Allocator.Error!vxfw.Surface {
-6
src/vxfw/SizedBox.zig
··· 13 13 pub fn widget(self: *const SizedBox) vxfw.Widget { 14 14 return .{ 15 15 .userdata = @constCast(self), 16 - .eventHandler = typeErasedEventHandler, 17 16 .drawFn = typeErasedDrawFn, 18 17 }; 19 - } 20 - 21 - fn typeErasedEventHandler(ptr: *anyopaque, ctx: *vxfw.EventContext, event: vxfw.Event) anyerror!void { 22 - const self: *const SizedBox = @ptrCast(@alignCast(ptr)); 23 - return self.child.handleEvent(ctx, event); 24 18 } 25 19 26 20 fn typeErasedDrawFn(ptr: *anyopaque, ctx: vxfw.DrawContext) Allocator.Error!vxfw.Surface {
-1
src/vxfw/SplitView.zig
··· 129 129 } 130 130 131 131 var surface = try vxfw.Surface.initWithChildren(ctx.arena, self.widget(), max, &self.children); 132 - surface.handles_mouse = true; 133 132 for (0..max.height) |row| { 134 133 surface.writeCell(self.width + 1, @intCast(row), .{ 135 134 .char = .{ .grapheme = "│", .width = 1 },
-1
src/vxfw/TextField.zig
··· 207 207 .{ .width = max_width, .height = @max(ctx.min.height, 1) }, 208 208 ); 209 209 surface.focusable = true; 210 - surface.handles_mouse = true; 211 210 212 211 const base: vaxis.Cell = .{ .style = .{} }; 213 212 @memset(surface.buffer, base);
+1 -5
src/vxfw/vxfw.zig
··· 267 267 268 268 /// If this widget / Surface is focusable 269 269 focusable: bool = false, 270 - /// If this widget can handle mouse events 271 - handles_mouse: bool = false, 272 270 273 271 /// Cursor state 274 272 cursor: ?CursorState = null, ··· 332 330 .buffer = self.buffer[0 .. self.size.width * height], 333 331 .children = self.children, 334 332 .focusable = self.focusable, 335 - .handles_mouse = self.handles_mouse, 336 333 }; 337 334 } 338 335 ··· 340 337 /// always be translated to local Surface coordinates. Asserts that this Surface does contain Point 341 338 pub fn hitTest(self: Surface, list: *std.ArrayList(HitResult), point: Point) Allocator.Error!void { 342 339 assert(point.col < self.size.width and point.row < self.size.height); 343 - if (self.handles_mouse) 344 - try list.append(.{ .local = point, .widget = self.widget }); 340 + try list.append(.{ .local = point, .widget = self.widget }); 345 341 for (self.children) |child| { 346 342 if (!child.containsPoint(point)) continue; 347 343 const child_point: Point = .{