Добавлять объекты в родителя

This commit is contained in:
2026-02-26 21:18:37 +03:00
parent 291dbd6f85
commit 77604e7b2b
7 changed files with 25 additions and 10 deletions

View File

@@ -30,6 +30,17 @@ pub fn addObject(self: *Document, template: Object) !void {
try self.objects.append(self.allocator, obj);
}
/// Добавляет объект в документ: как ребёнка родителя (если id найден), иначе в корень.
pub fn addObjectUnderParentId(self: *Document, parent_id: ?u64, template: Object) !void {
if (parent_id) |id| {
if (self.findObjectById(id)) |parent| {
try parent.addChild(self.allocator, template, &self.next_object_id);
return;
}
}
try self.addObject(template);
}
pub fn addShape(self: *Document, parent: ?*Object, shape_kind: Object.ShapeKind) !void {
const obj = try shape.createObject(self.allocator, shape_kind);
if (parent) |p| {