port +list-themes to latest libvaxis

This commit is contained in:
furtidev
2024-11-16 20:02:35 +06:00
parent e7b9a2ac95
commit a6bdd2f201

View File

@ -500,8 +500,8 @@ const Preview = struct {
const theme_list = win.child(.{ const theme_list = win.child(.{
.x_off = 0, .x_off = 0,
.y_off = 0, .y_off = 0,
.width = .{ .limit = 32 }, .width = 32,
.height = .{ .limit = win.height }, .height = win.height,
}); });
var highlight: ?usize = null; var highlight: ?usize = null;
@ -543,7 +543,8 @@ const Preview = struct {
theme_list.fill(.{ .style = self.ui_standard() }); theme_list.fill(.{ .style = self.ui_standard() });
for (0..theme_list.height) |row| { for (0..theme_list.height) |row_capture| {
const row: u16 = @intCast(row_capture);
const index = self.window + row; const index = self.window + row;
if (index >= self.filtered.items.len) break; if (index >= self.filtered.items.len) break;
@ -556,7 +557,7 @@ const Preview = struct {
}; };
if (style == .selected) { if (style == .selected) {
_ = try theme_list.printSegment( _ = theme_list.printSegment(
.{ .{
.text = " ", .text = " ",
.style = self.ui_selected(), .style = self.ui_selected(),
@ -567,7 +568,7 @@ const Preview = struct {
}, },
); );
} }
_ = try theme_list.printSegment( _ = theme_list.printSegment(
.{ .{
.text = theme.theme, .text = theme.theme,
.style = switch (style) { .style = switch (style) {
@ -586,8 +587,9 @@ const Preview = struct {
); );
if (style == .selected) { if (style == .selected) {
if (theme.theme.len < theme_list.width - 4) { if (theme.theme.len < theme_list.width - 4) {
for (2 + theme.theme.len..theme_list.width - 2) |i| for (2 + theme.theme.len..theme_list.width - 2) |i_capture| {
_ = try theme_list.printSegment( const i: u16 = @intCast(i_capture);
_ = theme_list.printSegment(
.{ .{
.text = " ", .text = " ",
.style = self.ui_selected(), .style = self.ui_selected(),
@ -597,8 +599,9 @@ const Preview = struct {
.col_offset = i, .col_offset = i,
}, },
); );
}
} }
_ = try theme_list.printSegment( _ = theme_list.printSegment(
.{ .{
.text = " ", .text = " ",
.style = self.ui_selected(), .style = self.ui_selected(),
@ -625,12 +628,8 @@ const Preview = struct {
.{ .{
.x_off = win.width / 2 -| width / 2, .x_off = win.width / 2 -| width / 2,
.y_off = win.height / 2 -| height / 2, .y_off = win.height / 2 -| height / 2,
.width = .{ .width = width,
.limit = width, .height = height,
},
.height = .{
.limit = height,
},
.border = .{ .border = .{
.where = .all, .where = .all,
.style = self.ui_standard(), .style = self.ui_standard(),
@ -660,8 +659,9 @@ const Preview = struct {
.{ .keys = "", .help = "Close search window." }, .{ .keys = "", .help = "Close search window." },
}; };
for (key_help, 0..) |help, i| { for (key_help, 0..) |help, captured_i| {
_ = try child.printSegment( const i: u16 = @intCast(captured_i);
_ = child.printSegment(
.{ .{
.text = help.keys, .text = help.keys,
.style = self.ui_standard(), .style = self.ui_standard(),
@ -671,7 +671,7 @@ const Preview = struct {
.col_offset = 2, .col_offset = 2,
}, },
); );
_ = try child.printSegment( _ = child.printSegment(
.{ .{
.text = "", .text = "",
.style = self.ui_standard(), .style = self.ui_standard(),
@ -681,7 +681,7 @@ const Preview = struct {
.col_offset = 15, .col_offset = 15,
}, },
); );
_ = try child.printSegment( _ = child.printSegment(
.{ .{
.text = help.help, .text = help.help,
.style = self.ui_standard(), .style = self.ui_standard(),
@ -697,12 +697,8 @@ const Preview = struct {
const child = win.child(.{ const child = win.child(.{
.x_off = 20, .x_off = 20,
.y_off = win.height - 5, .y_off = win.height - 5,
.width = .{ .width = win.width - 40,
.limit = win.width - 40, .height = 3,
},
.height = .{
.limit = 3,
},
.border = .{ .border = .{
.where = .all, .where = .all,
.style = self.ui_standard(), .style = self.ui_standard(),
@ -714,8 +710,9 @@ const Preview = struct {
} }
} }
pub fn drawPreview(self: *Preview, alloc: std.mem.Allocator, win: vaxis.Window, x_off: usize) !void { pub fn drawPreview(self: *Preview, alloc: std.mem.Allocator, win: vaxis.Window, x_off_unconverted: i17) !void {
const width = win.width - x_off; const x_off: u16 = @intCast(x_off_unconverted);
const width: u16 = win.width - x_off;
const theme = self.themes[self.filtered.items[self.current]]; const theme = self.themes[self.filtered.items[self.current]];