Разделил главный фрейм UI на отдельные модули: tab_bar, left_panel, right_panel и canvas_view. Это улучшает читаемость и поддерживает принцип единственной ответственности. Также изменил функцию `updateVisibleImageRect`, чтобы она возвращала `bool`, указывающий на необходимость перерисовки.
28 lines
988 B
Zig
28 lines
988 B
Zig
// Верхняя строка: вкладки документов + кнопка «Новый».
|
|
const std = @import("std");
|
|
const dvui = @import("dvui");
|
|
const WindowContext = @import("../WindowContext.zig");
|
|
|
|
pub fn tabBar(ctx: *WindowContext) void {
|
|
var bar = dvui.box(
|
|
@src(),
|
|
.{ .dir = .horizontal },
|
|
.{ .expand = .horizontal, .min_size_content = .{ .h = 32 }, .background = true, .padding = dvui.Rect.all(4) },
|
|
);
|
|
{
|
|
for (ctx.documents.items, 0..) |_, i| {
|
|
var buf: [32]u8 = undefined;
|
|
const label = std.fmt.bufPrint(&buf, "Doc {d}", .{i + 1}) catch "Doc";
|
|
if (dvui.button(@src(), label, .{}, .{ .id_extra = i })) {
|
|
ctx.setActiveDocument(i);
|
|
}
|
|
}
|
|
if (dvui.button(@src(), "+", .{}, .{})) {
|
|
ctx.addNewDocument() catch |err| {
|
|
std.debug.print("addNewDocument error: {}\n", .{err});
|
|
};
|
|
}
|
|
}
|
|
bar.deinit();
|
|
}
|