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