feat: base project

This commit is contained in:
2025-04-23 14:12:37 +02:00
parent ac72a405d8
commit 490425bfd9
8 changed files with 539 additions and 0 deletions

65
src/core/tab/tab.zig Normal file
View File

@@ -0,0 +1,65 @@
const std = @import("std");
const assert = std.debug.assert;
const Mutex = std.Thread.Mutex;
const models = @import("../models.zig");
const Container = models.Container;
const Item = models.Item;
pub const Tab = struct {
allocator: std.mem.Allocator,
currentLocation: ?*Container,
currentItems: ?std.ArrayList(Item),
threadPool: *std.Thread.Pool,
_private: Private,
const Private = struct {
currentItemsAllocator: ?std.heap.ArenaAllocator,
};
pub fn create(
threadPool: *std.Thread.Pool,
allocator: std.mem.Allocator,
) Tab {
return Tab{
.allocator = allocator,
.currentItems = null,
.currentLocation = null,
.threadPool = threadPool,
._private = .{
.currentItemsAllocator = null,
},
};
}
pub fn setCurrentLocation(self: *Tab, newLocation: *Container) void {
if (self.currentLocation) |c| {
c.item.deinit();
}
self.currentLocation = newLocation;
//TODO: Proper error handling
std.Thread.Pool.spawn(self.threadPool, loadItems, .{ self, newLocation }) catch unreachable;
}
fn loadItems(self: *Tab, location: *Container) void {
if (self._private.currentItemsAllocator) |arena| {
arena.deinit();
}
self._private.currentItemsAllocator = std.heap.ArenaAllocator.init(self.allocator);
for (location.children.items) |item| {
_ = item;
}
}
pub fn deinit(self: *Tab) void {
if (self.currentLocation) |c| {
c.deinit();
}
if (self._private.currentItemsAllocator) |arena| {
arena.deinit();
}
}
};