feat: file size
This commit is contained in:
@@ -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);
|
const padding = try ctx.arena.create(vxfw.Padding);
|
||||||
padding.* = .{
|
padding.* = .{
|
||||||
.child = container_child_number_element.widget(),
|
.child = container_child_number_element.widget(),
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ pub const ItemEnum = union(enum) {
|
|||||||
|
|
||||||
pub const Element = struct {
|
pub const Element = struct {
|
||||||
item: Item,
|
item: Item,
|
||||||
|
content_size: u64,
|
||||||
|
|
||||||
fn deinit(self: *Element) void {
|
fn deinit(self: *Element) void {
|
||||||
self.item.allocator.destroy(self);
|
self.item.allocator.destroy(self);
|
||||||
|
|||||||
@@ -89,7 +89,10 @@ pub const LocalContentProvider = struct {
|
|||||||
const native_path = try getNativePathByFullName(allocator, fullName);
|
const native_path = try getNativePathByFullName(allocator, fullName);
|
||||||
defer allocator.free(native_path);
|
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
|
// FIXME: properly handle different errors
|
||||||
var dir = std.fs.cwd().openDir(native_path, .{});
|
var dir = std.fs.cwd().openDir(native_path, .{});
|
||||||
if (dir) |*d| {
|
if (dir) |*d| {
|
||||||
@@ -99,8 +102,12 @@ pub const LocalContentProvider = struct {
|
|||||||
|
|
||||||
var file = std.fs.cwd().openFile(native_path, .{});
|
var file = std.fs.cwd().openFile(native_path, .{});
|
||||||
if (file) |*f| {
|
if (file) |*f| {
|
||||||
|
const size = size: {
|
||||||
|
const stat = f.stat() catch break :size 0;
|
||||||
|
break :size stat.size;
|
||||||
|
};
|
||||||
f.close();
|
f.close();
|
||||||
break :blk .file;
|
break :blk .{ .file = .{ .size = size } };
|
||||||
} else |_| {}
|
} else |_| {}
|
||||||
|
|
||||||
return GetItemsError.NotExists;
|
return GetItemsError.NotExists;
|
||||||
@@ -136,10 +143,11 @@ pub const LocalContentProvider = struct {
|
|||||||
|
|
||||||
break :blk &container.item;
|
break :blk &container.item;
|
||||||
},
|
},
|
||||||
.file => blk: {
|
.file => |file| blk: {
|
||||||
const element = try allocator.create(Element);
|
const element = try allocator.create(Element);
|
||||||
element.* = Element{
|
element.* = Element{
|
||||||
.item = undefined,
|
.item = undefined,
|
||||||
|
.content_size = file.size,
|
||||||
};
|
};
|
||||||
|
|
||||||
const val: ItemEnum = .{
|
const val: ItemEnum = .{
|
||||||
|
|||||||
Reference in New Issue
Block a user