╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Home.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
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_repo_new); 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_user_new); 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 user_view = try ui.UserSettings.initView(allocator, session, &data.user_notifications, .{ .home_user = .{} }); 92 errdefer user_view.deinit(allocator); 93 try stack.children.put(allocator, user_view.getFocus().id, user_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 .user_notifications => |*v| if (v.focusHeader(root_focus)) return, 161 else => {}, 162 }; 163 index = stack_index; 164 }, 165 .stack => { 166 try child.input(allocator, key, root_focus); 167 }, 168 else => {}, 169 } 170 }, 171 .none => { 172 try child.input(allocator, key, root_focus); 173 }, 174 } 175 176 if (index != current_index) { 177 root_focus.setFocus(self.box.children.keys()[index]); 178 } 179 } 180 } 181 } 182 183 pub fn clearGrid(self: *View) void { 184 self.box.clearGrid(); 185 } 186 187 pub fn getGrid(self: View) ?Grid { 188 return self.box.getGrid(); 189 } 190 191 pub fn getFocus(self: *View) *Focus { 192 return self.box.getFocus(); 193 } 194 }; 195