╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ User.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
178 179 var self = View{ .box = box, .data = data, .session = session }; 180 self.getFocus().child_id = box.children.keys()[header_index]; 181 return self; 182 } 183 184 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 185 self.box.deinit(allocator); 186 } 187 188 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 189 self.clearGrid(); 190 const header = &self.box.children.values()[header_index].widget.user_header; 191 const stack = &self.box.children.values()[stack_index].widget.stack; 192 193 // each header tab maps 1:1 to a stack child by position. mirror the 194 // selection into current_page so the host can push the matching url; 195 // all user tabs share the .user parent, so this stays on the page 196 // rather than navigating. 197 if (header.getSelectedIndex()) |index| { 198 stack.getFocus().child_id = stack.children.keys()[index]; 199 const name = self.data.route_name; 200 switch (std.meta.activeTag(stack.children.values()[index])) { 201 .home_settings => self.session.data.current_page = .{ .user_settings = name }, 202 .home_auth => self.session.data.current_page = .{ .user_auth = name }, 203 // the quit tab is tty-only and not a route, so leave current_page 204 // alone (nothing to mirror into the url). 205 .quit => {}, 206 // the repos list (the default tab) 207 else => self.session.data.current_page = .{ .user_repos = .{ .name = name, .start = self.data.repos_start } }, 208 } 209 } 210 try self.box.build(allocator, constraint, root_focus); 211 } 212 213 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 214 if (self.getFocus().child_id) |child_id| { 215 if (self.box.children.getIndex(child_id)) |current_index| { 216 const child = &self.box.children.values()[current_index].widget; 217 var index = current_index; 218 219 const direction = inp.vertDirection(key); 220 221 switch (direction) { 222 .up => { 223 switch (child.*) { 224 .user_header => { 225 try child.input(allocator, key, root_focus); 226 }, 227 .stack => { 228 if (child.stack.getSelected()) |selected_widget| { 229 const at_top = switch (selected_widget.*) { 230 .flow_box_scroll => |*v| v.getSelectedIndex() == 0, 231 .home_settings => |*v| v.getSelectedIndex() == 0, 232 .home_auth => |*v| v.getSelectedIndex() == 0, 233 .quit => |*v| v.getSelectedIndex() == 0, 234 else => false, 235 }; 236 if (at_top) { 237 index = header_index; 238 } else { 239 try child.input(allocator, key, root_focus); 240 } 241 } 242 }, 243 else => {}, 244 } 245 }, 246 .down => { 247 switch (child.*) { 248 .user_header => { 249 index = stack_index; 250 }, 251 .stack => { 252 try child.input(allocator, key, root_focus); 253 }, 254 else => {}, 255 } 256 }, 257 .none => { 258 try child.input(allocator, key, root_focus); 259 }, 260 } 261 262 if (index != current_index) { 263 root_focus.setFocus(self.box.children.keys()[index]); 264 } 265 } 266 } 267 } 268 269 pub fn clearGrid(self: *View) void { 270 self.box.clearGrid(); 271 } 272 273 pub fn getGrid(self: View) ?Grid { 274 return self.box.getGrid(); 275 } 276 277 pub fn getFocus(self: *View) *Focus { 278 return self.box.getFocus(); 279 } 280 }; 281