Added the new Table Widget
- Added `Table.zig` under the `src/widgets` directory and `widgets.zig` module. - Created the `drawTable()` function to draw a Table to the provided parent Window based on the provided ArrayList. - Created the `TableContext` struct to manage state and attributes for the `drawTable()` function.
This commit is contained in:
parent
392dffb307
commit
09a8188851
1 changed files with 24 additions and 13 deletions
|
@ -1,6 +1,9 @@
|
|||
const std = @import("std");
|
||||
const ascii = std.ascii;
|
||||
const fmt = std.fmt;
|
||||
const fs = std.fs;
|
||||
const heap = std.heap;
|
||||
const log = std.log;
|
||||
const mem = std.mem;
|
||||
const meta = std.meta;
|
||||
|
||||
|
@ -61,7 +64,9 @@ pub fn drawTable(
|
|||
if (table_ctx.col > headers.len - 1) table_ctx.*.col = headers.len - 1;
|
||||
for (headers[0..], 0..) |hdr_txt, idx| {
|
||||
const hdr_bg =
|
||||
if (table_ctx.active and idx == table_ctx.col) table_ctx.selected_bg else if (idx % 2 == 0) table_ctx.hdr_bg_1 else table_ctx.hdr_bg_2;
|
||||
if (table_ctx.active and idx == table_ctx.col) table_ctx.selected_bg
|
||||
else if (idx % 2 == 0) table_ctx.hdr_bg_1
|
||||
else table_ctx.hdr_bg_2;
|
||||
const hdr_win = table_win.initChild(
|
||||
idx * item_width,
|
||||
0,
|
||||
|
@ -99,7 +104,9 @@ pub fn drawTable(
|
|||
if (end > data_list.items.len) end = data_list.items.len;
|
||||
for (data_list.items[table_ctx.start..end], 0..) |data, idx| {
|
||||
const row_bg =
|
||||
if (table_ctx.active and table_ctx.start + idx == table_ctx.row) table_ctx.selected_bg else if (idx % 2 == 0) table_ctx.row_bg_1 else table_ctx.row_bg_2;
|
||||
if (table_ctx.active and table_ctx.start + idx == table_ctx.row) table_ctx.selected_bg
|
||||
else if (idx % 2 == 0) table_ctx.row_bg_1
|
||||
else table_ctx.row_bg_2;
|
||||
|
||||
const row_win = table_win.initChild(
|
||||
0,
|
||||
|
@ -129,13 +136,17 @@ pub fn drawTable(
|
|||
switch(@typeInfo(ItemT).Optional.child) {
|
||||
[]const u8 => break :nonStr opt_item,
|
||||
else => {
|
||||
break :nonStr if (alloc) |_alloc| try fmt.allocPrint(_alloc, "{any}", .{opt_item}) else fmt.comptimePrint("[unsupported ({s})]", .{@typeName(DataT)});
|
||||
},
|
||||
break :nonStr
|
||||
if (alloc) |_alloc| try fmt.allocPrint(_alloc, "{any}", .{ opt_item })
|
||||
else fmt.comptimePrint("[unsupported ({s})]", .{ @typeName(DataT) });
|
||||
}
|
||||
}
|
||||
},
|
||||
else => {
|
||||
break :nonStr if (alloc) |_alloc| try fmt.allocPrint(_alloc, "{any}", .{item}) else fmt.comptimePrint("[unsupported ({s})]", .{@typeName(DataT)});
|
||||
},
|
||||
break :nonStr
|
||||
if (alloc) |_alloc| try fmt.allocPrint(_alloc, "{any}", .{ item })
|
||||
else fmt.comptimePrint("[unsupported ({s})]", .{ @typeName(DataT) });
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue