this repo has no description
13
fork

Configure Feed

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

at 4320ec29d03415eba80a14b2eaaff8cefa6822e8 76 lines 2.2 kB view raw
1const std = @import("std"); 2const vaxis = @import("vaxis"); 3const vxfw = vaxis.vxfw; 4 5const Model = struct { 6 split: vxfw.SplitView, 7 lhs: vxfw.Text, 8 rhs: vxfw.Text, 9 children: [1]vxfw.SubSurface = undefined, 10 11 pub fn widget(self: *Model) vxfw.Widget { 12 return .{ 13 .userdata = self, 14 .eventHandler = Model.typeErasedEventHandler, 15 .drawFn = Model.typeErasedDrawFn, 16 }; 17 } 18 19 fn typeErasedEventHandler(ptr: *anyopaque, ctx: *vxfw.EventContext, event: vxfw.Event) anyerror!void { 20 const self: *Model = @ptrCast(@alignCast(ptr)); 21 switch (event) { 22 .init => { 23 self.split.lhs = self.lhs.widget(); 24 self.split.rhs = self.rhs.widget(); 25 }, 26 .key_press => |key| { 27 if (key.matches('c', .{ .ctrl = true })) { 28 ctx.quit = true; 29 return; 30 } 31 }, 32 else => {}, 33 } 34 } 35 36 fn typeErasedDrawFn(ptr: *anyopaque, ctx: vxfw.DrawContext) std.mem.Allocator.Error!vxfw.Surface { 37 const self: *Model = @ptrCast(@alignCast(ptr)); 38 const surf = try self.split.widget().draw(ctx); 39 self.children[0] = .{ 40 .surface = surf, 41 .origin = .{ .row = 0, .col = 0 }, 42 }; 43 return .{ 44 .size = ctx.max.size(), 45 .widget = self.widget(), 46 .buffer = &.{}, 47 .children = &self.children, 48 }; 49 } 50}; 51 52pub fn main(init: std.process.Init) !void { 53 const io = init.io; 54 const alloc = init.gpa; 55 56 var buffer: [1024]u8 = undefined; 57 var app: vxfw.App = try .init(io, alloc, init.environ_map, &buffer); 58 defer app.deinit(); 59 60 const model = try alloc.create(Model); 61 defer alloc.destroy(model); 62 model.* = .{ 63 .lhs = .{ .text = "Left hand side" }, 64 .rhs = .{ .text = "right hand side" }, 65 .split = .{ .lhs = undefined, .rhs = undefined, .width = 10 }, 66 }; 67 68 model.split.lhs = model.lhs.widget(); 69 model.split.rhs = model.rhs.widget(); 70 71 try app.run(model.widget(), .{}); 72} 73 74test { 75 std.testing.refAllDecls(@This()); 76}