feat: refactor
This commit is contained in:
@@ -261,68 +261,65 @@ const Model = struct {
|
||||
}
|
||||
fn createItems(
|
||||
ctx: vxfw.DrawContext,
|
||||
items1: *locked(?std.ArrayList(Arc(*models.Item))),
|
||||
locked_items: *locked(?std.ArrayList(Arc(*models.Item))),
|
||||
current_full_name: ?models.FullName,
|
||||
) !?[]vxfw.Widget {
|
||||
const text_items = blk2: {
|
||||
items1.mutex.lock();
|
||||
defer items1.mutex.unlock();
|
||||
const text_items = blk: {
|
||||
locked_items.mutex.lock();
|
||||
defer locked_items.mutex.unlock();
|
||||
|
||||
break :blk2 if (items1.data) |items| blk: {
|
||||
const children = try ctx.arena.create(std.ArrayList(*vxfw.Text));
|
||||
children.* = std.ArrayList(*vxfw.Text).init(ctx.arena);
|
||||
const items = locked_items.data orelse return null;
|
||||
const children = try ctx.arena.create(std.ArrayList(*vxfw.Text));
|
||||
children.* = std.ArrayList(*vxfw.Text).init(ctx.arena);
|
||||
|
||||
for (items.items) |*original_arc_child| {
|
||||
const arc_child = original_arc_child.retain();
|
||||
defer if (arc_child.releaseUnwrap()) |item| item.deinit();
|
||||
for (items.items) |*original_arc_child| {
|
||||
const arc_child = original_arc_child.retain();
|
||||
defer if (arc_child.releaseUnwrap()) |item| item.deinit();
|
||||
|
||||
const child = arc_child.value.*;
|
||||
const is_active = if (current_full_name) |c_full_name|
|
||||
models.FullName.eql(&c_full_name, &child.fullName)
|
||||
else
|
||||
false;
|
||||
const child = arc_child.value.*;
|
||||
const is_active = if (current_full_name) |c_full_name|
|
||||
models.FullName.eql(&c_full_name, &child.fullName)
|
||||
else
|
||||
false;
|
||||
|
||||
const fg, const bg = colors: {
|
||||
var fg: vaxis.Color = .default;
|
||||
var bg: vaxis.Color = .default;
|
||||
if (is_active) {
|
||||
fg = switch (child.item) {
|
||||
.container => .{ .index = 0 },
|
||||
.element => .{ .index = 0 },
|
||||
};
|
||||
bg = switch (child.item) {
|
||||
.container => .{ .index = 4 },
|
||||
.element => .{ .index = 7 },
|
||||
};
|
||||
} else {
|
||||
fg = switch (child.item) {
|
||||
.container => .{ .index = 4 },
|
||||
.element => .default,
|
||||
};
|
||||
bg = .default;
|
||||
}
|
||||
break :colors .{ fg, bg };
|
||||
};
|
||||
const fg, const bg = colors: {
|
||||
var fg: vaxis.Color = .default;
|
||||
var bg: vaxis.Color = .default;
|
||||
if (is_active) {
|
||||
fg = switch (child.item) {
|
||||
.container => .{ .index = 0 },
|
||||
.element => .{ .index = 0 },
|
||||
};
|
||||
bg = switch (child.item) {
|
||||
.container => .{ .index = 4 },
|
||||
.element => .{ .index = 7 },
|
||||
};
|
||||
} else {
|
||||
fg = switch (child.item) {
|
||||
.container => .{ .index = 4 },
|
||||
.element => .default,
|
||||
};
|
||||
bg = .default;
|
||||
}
|
||||
break :colors .{ fg, bg };
|
||||
};
|
||||
|
||||
//NOTE: the right padding is wrong, if the text is too long, the remainder of the text and also the space will be clipped
|
||||
const text = try std.fmt.allocPrint(ctx.arena, " {s} ", .{child.displayName});
|
||||
const text_element = try ctx.arena.create(vxfw.Text);
|
||||
text_element.* = vxfw.Text{
|
||||
.text = text,
|
||||
.overflow = .clip,
|
||||
.softwrap = false,
|
||||
.style = .{
|
||||
.bg = bg,
|
||||
.fg = fg,
|
||||
},
|
||||
};
|
||||
//NOTE: the right padding is wrong, if the text is too long, the remainder of the text and also the space will be clipped
|
||||
const text = try std.fmt.allocPrint(ctx.arena, " {s} ", .{child.displayName});
|
||||
const text_element = try ctx.arena.create(vxfw.Text);
|
||||
text_element.* = vxfw.Text{
|
||||
.text = text,
|
||||
.overflow = .clip,
|
||||
.softwrap = false,
|
||||
.style = .{
|
||||
.bg = bg,
|
||||
.fg = fg,
|
||||
},
|
||||
};
|
||||
|
||||
try children.append(text_element);
|
||||
}
|
||||
break :blk children;
|
||||
} else {
|
||||
return null;
|
||||
};
|
||||
try children.append(text_element);
|
||||
}
|
||||
break :blk children;
|
||||
};
|
||||
|
||||
const widgets = try ctx.arena.alloc(vxfw.Widget, text_items.items.len);
|
||||
|
||||
Reference in New Issue
Block a user