╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Home.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
73 var users_view = try Users.View.init(allocator, &data.users, session); 74 errdefer users_view.deinit(allocator); 75 try stack.children.put(allocator, users_view.getFocus().id, .{ .home_users = users_view }); 76 } 77 78 // the header shows new repo with a login and new user without 79 // one, so keep the stack's children 1:1 with the tabs 80 if (session.data.user_id != null) { 81 var new_repo_view = try ui.NewRepo.View.init(allocator, session, .home_new_repo); 82 errdefer new_repo_view.deinit(allocator); 83 try stack.children.put(allocator, new_repo_view.getFocus().id, .{ .new_repo = new_repo_view }); 84 } else { 85 var new_user_view = try ui.NewUser.View.init(allocator, session, .home_new_user); 86 errdefer new_user_view.deinit(allocator); 87 try stack.children.put(allocator, new_user_view.getFocus().id, .{ .new_user = new_user_view }); 88 } 89 90 { 91 var auth_view = try Auth.View.init(allocator, &data.auth, session); 92 errdefer auth_view.deinit(allocator); 93 try stack.children.put(allocator, auth_view.getFocus().id, .{ .home_auth = auth_view }); 94 } 95 96 if (session.is_terminal) { 97 var quit_view = try Quit.View.init(allocator, session); 98 errdefer quit_view.deinit(allocator); 99 try stack.children.put(allocator, quit_view.getFocus().id, .{ .quit = quit_view }); 100 } 101 102 try box.children.put(allocator, stack.getFocus().id, .{ .widget = .{ .stack = stack }, .rect = null, .min_size = null }); 103 } 104 105 var self = View{ 106 .box = box, 107 }; 108 // search results open in the tab's own search box 109 self.getFocus().child_id = box.children.keys()[if (data.users.search != null) stack_index else header_index]; 110 return self; 111 } 112 113 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 114 self.box.deinit(allocator); 115 } 116 117 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 118 self.clearGrid(); 119 const header = &self.box.children.values()[header_index].widget.home_header; 120 const stack = &self.box.children.values()[stack_index].widget.stack; 121 122 // each header tab maps 1:1 to a stack child by position 123 if (header.getSelectedIndex()) |index| 124 stack.getFocus().child_id = stack.children.keys()[index]; 125 try self.box.build(allocator, constraint, root_focus); 126 } 127 128 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 129 const stack = &self.box.children.values()[stack_index].widget.stack; 130 if (self.getFocus().child_id) |child_id| { 131 if (self.box.children.getIndex(child_id)) |current_index| { 132 const child = &self.box.children.values()[current_index].widget; 133 var index = current_index; 134 135 const direction = inp.vertDirection(key); 136 137 switch (direction) { 138 .up => { 139 switch (child.*) { 140 .home_header => { 141 try child.input(allocator, key, root_focus); 142 }, 143 .stack => { 144 if (child.stack.getSelected()) |selected_widget| { 145 if (selected_widget.atTop(root_focus)) { 146 index = header_index; 147 } else { 148 try child.input(allocator, key, root_focus); 149 } 150 } 151 }, 152 else => {}, 153 } 154 }, 155 .down => { 156 switch (child.*) { 157 .home_header => { 158 if (stack.getSelected()) |selected_widget| switch (selected_widget.*) { 159 .home_users => |*v| return v.focusHeader(root_focus), 160 else => {}, 161 }; 162 index = stack_index; 163 }, 164 .stack => { 165 try child.input(allocator, key, root_focus); 166 }, 167 else => {}, 168 } 169 }, 170 .none => { 171 try child.input(allocator, key, root_focus); 172 }, 173 } 174 175 if (index != current_index) { 176 root_focus.setFocus(self.box.children.keys()[index]); 177 } 178 } 179 } 180 } 181 182 pub fn clearGrid(self: *View) void { 183 self.box.clearGrid(); 184 } 185 186 pub fn getGrid(self: View) ?Grid { 187 return self.box.getGrid(); 188 } 189 190 pub fn getFocus(self: *View) *Focus { 191 return self.box.getFocus(); 192 } 193 }; 194