╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ About.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
50 var frame = try wgt.Box(ui.Widget).init(allocator, .{ .border = .single, .round_corners = true, .direction = .vert }); 51 errdefer frame.deinit(allocator); 52 frame.getFocus().child_id = scroll.getFocus().id; 53 try frame.children.put(allocator, scroll.getFocus().id, .{ .widget = .{ .scroll = scroll }, .rect = null, .min_size = null, .flex = .grow }); 54 return .{ .frame = frame, .session = session }; 55 } 56 57 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 58 self.frame.deinit(allocator); 59 } 60 61 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 62 const focused = if (root_focus.grandchild_id) |id| self.markdownView().owns(id) else false; 63 self.frame.options.border = if (focused) .double else .single; 64 try self.frame.build(allocator, constraint, root_focus); 65 } 66 67 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 68 // the web scrolls natively and leaves tab to the browser 69 if (!self.session.is_terminal) return; 70 const sc = self.contentScroll(); 71 switch (key) { 72 .arrow_up => sc.y -= 1, 73 .arrow_down => sc.y += 1, 74 .page_up => sc.y -= 10, 75 .page_down => sc.y += 10, 76 .home => sc.y = 0, 77 .end => sc.y = std.math.maxInt(isize), 78 .mouse => |mouse| switch (mouse.action) { 79 .scroll => |dir| sc.y += if (dir == .up) -5 else 5, 80 else => {}, 81 }, 82 .tab, .back_tab => try self.markdownView().stepLink(allocator, root_focus, sc, 0, 0, key == .tab), 83 else => {}, 84 } 85 sc.clampToContent(); 86 } 87 88 pub fn clearGrid(self: *View) void { 89 self.frame.clearGrid(); 90 } 91 92 pub fn getGrid(self: View) ?Grid { 93 return self.frame.getGrid(); 94 } 95 96 pub fn getFocus(self: *View) *Focus { 97 return self.frame.getFocus(); 98 } 99 100 pub fn atTop(self: View) bool { 101 return self.frame.children.values()[0].widget.scroll.y <= 0; 102 } 103 104 fn contentScroll(self: *View) *wgt.Scroll(ui.Widget) { 105 return &self.frame.children.values()[0].widget.scroll; 106 } 107 108 fn markdownView(self: *View) *Markdown.View { 109 return &self.contentScroll().child.markdown; 110 } 111 }; 112