mirror of
https://codeberg.org/fairyglade/ly.git
synced 2026-08-19 03:54:20 +02:00
No more lids
This commit is contained in:
parent
7d42254ee5
commit
3c54c1613a
3 changed files with 22 additions and 16 deletions
|
|
@ -12,6 +12,8 @@ const VTable = struct {
|
|||
calculate_timeout_fn: ?*const fn (ptr: *anyopaque, ctx: *anyopaque) anyerror!?usize,
|
||||
};
|
||||
|
||||
pub var idCounter: u64 = 0;
|
||||
|
||||
id: u64,
|
||||
display_name: []const u8,
|
||||
keybinds: ?TerminalBuffer.KeybindMap,
|
||||
|
|
@ -101,8 +103,9 @@ pub fn init(
|
|||
};
|
||||
};
|
||||
|
||||
idCounter += 1;
|
||||
return .{
|
||||
.id = @intFromPtr(Impl.vtable.draw_fn),
|
||||
.id = idCounter,
|
||||
.display_name = display_name,
|
||||
.keybinds = keybinds,
|
||||
.pointer = pointer,
|
||||
|
|
|
|||
|
|
@ -8,9 +8,8 @@ const Position = @import("../Position.zig");
|
|||
const TerminalBuffer = @import("../TerminalBuffer.zig");
|
||||
const Widget = @import("../Widget.zig");
|
||||
|
||||
lid: u64, // HACK: we need to differenciate between labels in `updateCustomInfo`.
|
||||
// The underlying widget ID doesn't have the properties needed.
|
||||
allocator: ?Allocator,
|
||||
instance: ?Widget,
|
||||
text: []const u8,
|
||||
max_width: ?usize,
|
||||
fg: u32,
|
||||
|
|
@ -32,8 +31,8 @@ pub fn init(
|
|||
) Label {
|
||||
lidCounter += 1;
|
||||
return .{
|
||||
.lid = lidCounter,
|
||||
.allocator = null,
|
||||
.instance = null,
|
||||
.text = text,
|
||||
.max_width = max_width,
|
||||
.fg = fg,
|
||||
|
|
@ -50,7 +49,8 @@ pub fn deinit(self: *Label) void {
|
|||
}
|
||||
|
||||
pub fn widget(self: *Label) Widget {
|
||||
return Widget.init(
|
||||
if (self.instance) |inst| return inst;
|
||||
self.instance = Widget.init(
|
||||
"Label",
|
||||
null,
|
||||
self,
|
||||
|
|
@ -61,6 +61,7 @@ pub fn widget(self: *Label) Widget {
|
|||
null,
|
||||
calculateTimeout,
|
||||
);
|
||||
return self.instance.?; // We already created the Widget.
|
||||
}
|
||||
|
||||
pub fn setTextAlloc(
|
||||
|
|
|
|||
24
src/main.zig
24
src/main.zig
|
|
@ -75,6 +75,7 @@ const CustomInfoLabel = struct {
|
|||
lbl: Label
|
||||
};
|
||||
|
||||
|
||||
const UiState = struct {
|
||||
allocator: Allocator,
|
||||
auth_fails: u64,
|
||||
|
|
@ -1084,19 +1085,20 @@ pub fn main() !void {
|
|||
|
||||
var lblIter = custom.labels.iterator();
|
||||
while (lblIter.next()) |i| {
|
||||
const w = Label.init("",
|
||||
null,
|
||||
state.buffer.fg,
|
||||
state.buffer.bg,
|
||||
&updateCustomInfo,
|
||||
null,
|
||||
);
|
||||
i.value_ptr.id = w.lid;
|
||||
i.value_ptr.counter = 2;
|
||||
try state.custom_info.append(state.allocator, .{
|
||||
.info = i.value_ptr.*,
|
||||
.lbl = w
|
||||
.lbl = .init(
|
||||
"",
|
||||
null,
|
||||
state.buffer.fg,
|
||||
state.buffer.bg,
|
||||
&updateCustomInfo,
|
||||
null
|
||||
)
|
||||
});
|
||||
var latest = &state.custom_info.items[state.custom_info.items.len-1];
|
||||
latest.info.id = latest.lbl.widget().id;
|
||||
latest.info.counter = 2;
|
||||
}
|
||||
defer {
|
||||
for (state.custom_info.items) |*item| {
|
||||
|
|
@ -1763,7 +1765,7 @@ fn updateClock(self: *Label, ptr: *anyopaque) !void {
|
|||
|
||||
fn updateCustomInfo(lbl: *Label, ptr: *anyopaque) !void {
|
||||
const state: *UiState = @ptrCast(@alignCast(ptr));
|
||||
const wid = lbl.lid;
|
||||
const wid = lbl.widget().id;
|
||||
var stdout = std.ArrayList(u8).empty;
|
||||
defer stdout.deinit(state.allocator);
|
||||
var stderr = std.ArrayList(u8).empty;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue