Убраны комментарии лишние и улучшены модели

This commit is contained in:
2026-02-23 23:01:49 +03:00
parent b896a67fd4
commit bd58286c98
15 changed files with 169 additions and 193 deletions

View File

@@ -7,13 +7,11 @@ const basic_models = @import("models/basic_models.zig");
const WindowContext = @This();
/// Один открытый документ: документ + свой холст и движок рендера
pub const OpenDocument = struct {
document: Document,
cpu_render: CpuRenderEngine,
canvas: Canvas,
/// Инициализировать по месту (canvas хранит указатель на cpu_render этого же экземпляра).
pub fn init(allocator: std.mem.Allocator, self: *OpenDocument) void {
const default_size = basic_models.Size{ .width = 800, .height = 600 };
self.document = Document.init(allocator, default_size);
@@ -29,9 +27,7 @@ pub const OpenDocument = struct {
allocator: std.mem.Allocator,
frame_index: u64,
/// Список открытых документов (вкладок): указатели на документ+холст
documents: std.ArrayList(*OpenDocument),
/// Индекс активной вкладки; null — ни один документ не выбран
active_document_index: ?usize,
pub fn init(allocator: std.mem.Allocator) !WindowContext {
@@ -54,14 +50,12 @@ pub fn deinit(self: *WindowContext) void {
self.documents.deinit(self.allocator);
}
/// Вернуть указатель на активный открытый документ (null если нет выбранной вкладки).
pub fn activeDocument(self: *WindowContext) ?*OpenDocument {
const i = self.active_document_index orelse return null;
if (i >= self.documents.items.len) return null;
return self.documents.items[i];
}
/// Добавить новый документ и сделать его активным.
pub fn addNewDocument(self: *WindowContext) !void {
const ptr = try self.allocator.create(OpenDocument);
errdefer self.allocator.destroy(ptr);
@@ -70,14 +64,12 @@ pub fn addNewDocument(self: *WindowContext) !void {
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;
}
}
/// Закрыть вкладку по индексу; активная вкладка сдвигается при необходимости.
pub fn closeDocument(self: *WindowContext, index: usize) void {
if (index >= self.documents.items.len) return;
const open_doc = self.documents.items[index];