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