feat: file size

This commit is contained in:
2025-06-06 16:55:25 +02:00
parent 3e3f03f11a
commit feeff8cc3e
3 changed files with 40 additions and 3 deletions

View File

@@ -379,6 +379,34 @@ const Model = struct {
},
};
const padding = try ctx.arena.create(vxfw.Padding);
padding.* = .{
.child = container_child_number_element.widget(),
.padding = vxfw.Padding.horizontal(1),
.fill = .{
.style = .{
.bg = bg,
.fg = fg,
},
},
};
try item_children_list.append(.{
.widget = try draw_context.fromWidget(padding.widget(), draw_context.maxHeight1, ctx.arena),
.flex = 0,
});
} else if (child.item == .element) {
const element = child.item.element;
const container_child_number_text = try std.fmt.allocPrint(ctx.arena, "{:.1}", .{std.fmt.fmtIntSizeBin(element.content_size)});
const container_child_number_element = try ctx.arena.create(vxfw.Text);
container_child_number_element.* = vxfw.Text{
.text = container_child_number_text,
.style = .{
.bg = bg,
.fg = fg,
},
};
const padding = try ctx.arena.create(vxfw.Padding);
padding.* = .{
.child = container_child_number_element.widget(),

View File

@@ -39,6 +39,7 @@ pub const ItemEnum = union(enum) {
pub const Element = struct {
item: Item,
content_size: u64,
fn deinit(self: *Element) void {
self.item.allocator.destroy(self);

View File

@@ -89,7 +89,10 @@ pub const LocalContentProvider = struct {
const native_path = try getNativePathByFullName(allocator, fullName);
defer allocator.free(native_path);
const kind: union(enum) { directory, file } = blk: {
const kind: union(enum) {
directory,
file: struct { size: u64 },
} = blk: {
// FIXME: properly handle different errors
var dir = std.fs.cwd().openDir(native_path, .{});
if (dir) |*d| {
@@ -99,8 +102,12 @@ pub const LocalContentProvider = struct {
var file = std.fs.cwd().openFile(native_path, .{});
if (file) |*f| {
const size = size: {
const stat = f.stat() catch break :size 0;
break :size stat.size;
};
f.close();
break :blk .file;
break :blk .{ .file = .{ .size = size } };
} else |_| {}
return GetItemsError.NotExists;
@@ -136,10 +143,11 @@ pub const LocalContentProvider = struct {
break :blk &container.item;
},
.file => blk: {
.file => |file| blk: {
const element = try allocator.create(Element);
element.* = Element{
.item = undefined,
.content_size = file.size,
};
const val: ItemEnum = .{