Возможность добавлять объекты в документ
This commit is contained in:
@@ -26,3 +26,17 @@ pub fn addObject(self: *Document, template: Object) !void {
|
|||||||
const obj = try template.clone(self.allocator);
|
const obj = try template.clone(self.allocator);
|
||||||
try self.objects.append(self.allocator, obj);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ const defaultCommonProperties = @import("Property.zig").defaultCommonProperties;
|
|||||||
const Object = @This();
|
const Object = @This();
|
||||||
|
|
||||||
pub const ShapeKind = enum {
|
pub const ShapeKind = enum {
|
||||||
rect,
|
|
||||||
line,
|
line,
|
||||||
ellipse,
|
ellipse,
|
||||||
arc,
|
arc,
|
||||||
@@ -81,13 +80,6 @@ fn createWithCommonProperties(allocator: std.mem.Allocator, shape: ShapeKind) !O
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn createRect(allocator: std.mem.Allocator) !Object {
|
|
||||||
var obj = try createWithCommonProperties(allocator, .rect);
|
|
||||||
errdefer obj.deinit(allocator);
|
|
||||||
try obj.properties.append(allocator, .{ .data = .{ .size = .{ .width = 100, .height = 100 } } });
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn createEllipse(allocator: std.mem.Allocator) !Object {
|
pub fn createEllipse(allocator: std.mem.Allocator) !Object {
|
||||||
var obj = try createWithCommonProperties(allocator, .ellipse);
|
var obj = try createWithCommonProperties(allocator, .ellipse);
|
||||||
errdefer obj.deinit(allocator);
|
errdefer obj.deinit(allocator);
|
||||||
|
|||||||
Reference in New Issue
Block a user