╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ UserNotifications.zig ────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
223 } 224 225 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 226 self.clearGrid(); 227 const header = self.headerBox(); 228 // focusing a sub tab shows its content, while the logout button leaves it 229 if (header.getFocus().child_id) |child_id| if (std.mem.indexOfScalar(usize, self.control_ids[0..tab_count], child_id)) |index| { 230 self.view_index = index; 231 }; 232 for (self.control_ids[0..tab_count], 0..) |id, index| { 233 const tab = header.children.getPtr(id) orelse unreachable; 234 ui.widget.markSelected(&tab.widget.text_box, index == self.view_index); 235 } 236 self.contentStack().getFocus().child_id = self.contentStack().children.keys()[self.view_index]; 237 // clear the incoming min height so the list scrolls within what's left 238 try self.box.build(allocator, .{ 239 .min_size = .{ .width = null, .height = null }, 240 .max_size = constraint.max_size, 241 }, root_focus); 242 } 243 244 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 245 const logout_id = self.control_ids[logout_index]; 246 if (key == .mouse and inp.leftClickOn(root_focus, logout_id, key.mouse)) return logOut(self.session); 247 const direction = inp.vertDirection(key); 248 if (self.headerActive()) { 249 const focused = root_focus.grandchild_id orelse return; 250 if (key == .enter and focused == logout_id) return logOut(self.session); 251 if (direction == .down) { 252 // the empty message has nothing to focus 253 if (self.view_index == @backingInt(ui.RoutablePage.UserView.notifications) and self.data.isEmpty()) return; 254 root_focus.setFocus(self.contentStack().getFocus().id); 255 } else if (std.mem.indexOfScalar(usize, &self.control_ids, focused)) |current| { 256 if (inp.moveTab(key, current, self.control_ids.len)) |next| root_focus.setFocus(self.control_ids[next]); 257 } 258 return; 259 } 260 if (direction == .up) if (self.contentStack().getSelected()) |selected| if (selected.atTop(root_focus)) { 261 root_focus.setFocus(self.control_ids[self.view_index]); 262 return; 263 }; 264 try self.contentStack().input(allocator, key, root_focus); 265 } 266 267 // moving up from the sub header returns to the page's tabs 268 pub fn atTop(self: *View) bool { 269 return self.headerActive(); 270 } 271 272 // arriving from the page's tabs lands on the sub header, not the content 273 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 274 root_focus.setFocus(self.control_ids[self.view_index]); 275 return true; 276 } 277 278 pub fn clearGrid(self: *View) void { 279 self.box.clearGrid(); 280 } 281 282 pub fn getGrid(self: View) ?Grid { 283 return self.box.getGrid(); 284 } 285 286 pub fn getFocus(self: *View) *Focus { 287 return self.box.getFocus(); 288 } 289 }; 290