From 6dd7b486626d7ead8de695afceab32fda284eaf7 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 1 Dec 2024 11:46:10 -0700 Subject: [PATCH] module: add getFirstChildOfType helper Signed-off-by: Stephen Gutekanst --- src/module.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/module.zig b/src/module.zig index e0f03e4a..81c59830 100644 --- a/src/module.zig +++ b/src/module.zig @@ -391,6 +391,18 @@ pub fn Objects(options: ObjectsOptions, comptime T: type) type { pub fn removeChild(objs: *@This(), id: ObjectID, child: ObjectID) !void { return objs.internal.graph.removeChild(objs.internal.allocator, id, child); } + + /// Queries the children of the given object ID (which may be any object, including one not + /// in this list of objects - and finds the first child which would be from this list of + /// objects. + pub fn getFirstChildOfType(objs: *@This(), id: ObjectID) !?ObjectID { + var children = try objs.getChildren(id); + defer children.deinit(); + for (children.items) |child_id| { + if (objs.is(child_id)) return child_id; + } + return null; + } }; }