json сохранение

This commit is contained in:
2026-02-27 01:49:40 +03:00
parent 50821c8046
commit b7f7108f63
4 changed files with 477 additions and 0 deletions

View File

@@ -27,6 +27,17 @@ pub const OpenDocument = struct {
self.selected_object_id = null;
}
pub fn initWithDocument(allocator: std.mem.Allocator, self: *OpenDocument, doc: Document) void {
self.document = doc;
self.cpu_render = CpuRenderEngine.init(allocator, .Squares);
self.canvas = Canvas.init(
allocator,
&self.document,
(&self.cpu_render).renderEngine(),
);
self.selected_object_id = null;
}
pub fn deinit(self: *OpenDocument) void {
self.document.deinit();
self.canvas.deinit();
@@ -73,6 +84,16 @@ pub fn addNewDocument(self: *WindowContext) !void {
self.active_document_index = self.documents.items.len - 1;
}
pub fn addDocument(self: *WindowContext, doc: Document) !void {
const ptr = try self.allocator.create(OpenDocument);
errdefer self.allocator.destroy(ptr);
var doc_mut = doc;
errdefer doc_mut.deinit();
OpenDocument.initWithDocument(self.allocator, ptr, doc_mut);
try self.documents.append(self.allocator, ptr);
self.active_document_index = self.documents.items.len - 1;
}
pub fn setActiveDocument(self: *WindowContext, index: usize) void {
if (index < self.documents.items.len) {
self.active_document_index = index;