Возможность добавлять объекты в документ

This commit is contained in:
2026-02-23 23:52:47 +03:00
parent dd9d5deb92
commit aeda3ee0d0
2 changed files with 14 additions and 8 deletions

View File

@@ -26,3 +26,17 @@ pub fn addObject(self: *Document, template: Object) !void {
const obj = try template.clone(self.allocator);
try self.objects.append(self.allocator, obj);
}
pub fn addShape(self: *Document, parent: ?*Object, shape: Object.ShapeKind) !void {
const obj = switch (shape) {
.line => try Object.createLine(self.allocator),
.ellipse => try Object.createEllipse(self.allocator),
.broken => try Object.createBrokenLine(self.allocator),
.arc => return error.ArcNotImplemented,
};
if (parent) |p| {
try p.addChild(self.allocator, obj);
} else {
try self.addObject(obj);
}
}