viewById works again, layer still ontop of other things

This commit is contained in:
Harrison DiAmbrosio 2025-12-04 23:50:39 -05:00
parent 3ccf47e0be
commit 9186aeecd3
23 changed files with 282 additions and 181 deletions

56
src/types/Events.zig Normal file
View file

@ -0,0 +1,56 @@
pub const Events = @This();
const std = @import("std");
const Hook = @import("Hook.zig");
const Node = struct {
hook: *const Hook,
node: std.SinglyLinkedList.Node,
};
events: std.StringHashMap(*std.SinglyLinkedList),
allocator: std.mem.Allocator,
pub fn init(allocator: std.mem.Allocator) !Events {
return Events{
.allocator = allocator,
.events = .init(allocator),
};
}
pub fn put(self: *Events, key: []const u8, hook: *const Hook) !void {
var ll: *std.SinglyLinkedList = undefined;
if (self.events.get(key)) |sll| {
ll = sll;
} else {
ll = try self.allocator.create(std.SinglyLinkedList);
try self.events.put(key, ll);
if (self.events.get(key)) |sll| {
ll = sll;
}
}
const data = try self.allocator.create(Node);
data.* = .{
.hook = hook,
.node = .{},
};
ll.prepend(&data.node);
}
// TODO: figure out deletion
// pub fn del(self: *Events, key: ???) !void {}
pub fn exec(self: *Events, event: []const u8, args: anytype) void {
if (self.events.get(event)) |e| {
var node = e.first;
while (node) |n| : (node = n.next) {
const data: *Node = @fieldParentPtr("node", n);
data.hook.callback(args);
// FIXME: not sure why but for some reason our ll doesn't seem to want to
// admit that there's nothing after the first node.
break;
}
}
}