this repo has no description
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

app: draw channel names

+47 -6
+18 -3
src/app.zig
··· 223 223 }, 224 224 .tick => { 225 225 for (self.clients.items) |client| { 226 - client.drainFifo(); 226 + client.drainFifo(ctx); 227 227 } 228 228 try ctx.tick(8, self.widget()); 229 229 }, ··· 276 276 if (i == idx and i == cursor) { 277 277 return .{ 278 278 .userdata = client, 279 - .drawFn = irc.Client.typeErasedNameSelectedDrawFn, 279 + .drawFn = irc.Client.drawNameSelected, 280 280 }; 281 281 } 282 282 if (i == idx) { 283 283 return .{ 284 284 .userdata = client, 285 - .drawFn = irc.Client.typeErasedNameDrawFn, 285 + .drawFn = irc.Client.drawName, 286 286 }; 287 287 } 288 288 i += 1; 289 + for (client.channels.items) |channel| { 290 + if (i == idx and i == cursor) { 291 + return .{ 292 + .userdata = channel, 293 + .drawFn = irc.Channel.drawNameSelected, 294 + }; 295 + } 296 + if (i == idx) { 297 + return .{ 298 + .userdata = channel, 299 + .drawFn = irc.Channel.drawName, 300 + }; 301 + } 302 + i += 1; 303 + } 289 304 } 290 305 return null; 291 306 }
+29 -3
src/irc.zig
··· 168 168 return l < r; 169 169 } 170 170 171 + pub fn drawName(ptr: *anyopaque, ctx: vxfw.DrawContext) Allocator.Error!vxfw.Surface { 172 + const self: *Channel = @ptrCast(@alignCast(ptr)); 173 + const text: vxfw.RichText = .{ 174 + .text = &.{ 175 + .{ .text = " " }, 176 + .{ .text = self.name }, 177 + }, 178 + .softwrap = false, 179 + }; 180 + return text.draw(ctx); 181 + } 182 + 183 + pub fn drawNameSelected(ptr: *anyopaque, ctx: vxfw.DrawContext) Allocator.Error!vxfw.Surface { 184 + const self: *Channel = @ptrCast(@alignCast(ptr)); 185 + const text: vxfw.RichText = .{ 186 + .text = &.{ 187 + .{ .text = " ", .style = .{ .reverse = true } }, 188 + .{ .text = self.name, .style = .{ .reverse = true } }, 189 + }, 190 + .softwrap = false, 191 + }; 192 + return text.draw(ctx); 193 + } 194 + 171 195 pub fn sortMembers(self: *Channel) void { 172 196 std.sort.insertion(Member, self.members.items, {}, Member.compare); 173 197 } ··· 566 590 self.fifo.deinit(); 567 591 } 568 592 569 - pub fn typeErasedNameDrawFn(ptr: *anyopaque, ctx: vxfw.DrawContext) Allocator.Error!vxfw.Surface { 593 + pub fn drawName(ptr: *anyopaque, ctx: vxfw.DrawContext) Allocator.Error!vxfw.Surface { 570 594 const self: *Client = @ptrCast(@alignCast(ptr)); 571 595 const text: vxfw.Text = .{ 572 596 .text = self.config.name orelse self.config.server, ··· 575 599 return text.draw(ctx); 576 600 } 577 601 578 - pub fn typeErasedNameSelectedDrawFn(ptr: *anyopaque, ctx: vxfw.DrawContext) Allocator.Error!vxfw.Surface { 602 + pub fn drawNameSelected(ptr: *anyopaque, ctx: vxfw.DrawContext) Allocator.Error!vxfw.Surface { 579 603 const self: *Client = @ptrCast(@alignCast(ptr)); 580 604 const text: vxfw.Text = .{ 581 605 .text = self.config.name orelse self.config.server, ··· 585 609 return text.draw(ctx); 586 610 } 587 611 588 - pub fn drainFifo(self: *Client) void { 612 + pub fn drainFifo(self: *Client, ctx: *vxfw.EventContext) void { 589 613 self.fifo_mutex.lock(); 590 614 defer self.fifo_mutex.unlock(); 591 615 while (self.fifo.readItem()) |item| { 616 + // We redraw if we have any items 617 + ctx.redraw = true; 592 618 self.handleEvent(item) catch |err| { 593 619 log.err("error: {}", .{err}); 594 620 };