╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Users.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
147 148 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 149 const direction = inp.vertDirection(key); 150 if (self.headerActive()) { 151 const search_box = self.searchBox(); 152 if (direction == .down) return root_focus.setFocus(self.listScroll().getFocus().id); 153 if (key == .enter) { 154 const text = try search_box.text(allocator); 155 defer allocator.free(text); 156 return self.submit(text); 157 } 158 return search_box.input(allocator, key, root_focus); 159 } 160 // up from the first row reaches the search box 161 if (direction == .up and self.listScroll().atTop()) return self.focusHeader(root_focus); 162 try self.listScroll().input(allocator, key, root_focus); 163 } 164 165 // the users narrowed to `text` from the first window. an empty box on an 166 // unsearched page has nothing to clear. 167 fn submit(self: *View, text: []const u8) !void { 168 if (text.len == 0 and self.data.search == null) return; 169 try self.session.navigate((ui.RoutablePage{ .home_users = .{} }).withSearch(text) orelse return); 170 } 171 172 fn searchBox(self: *View) *ui.widget.SearchBox { 173 return &self.box.children.values()[header_index].widget.box.children.values()[0].widget.search_box; 174 } 175 176 fn listScroll(self: *View) *ui.widget.FlowBox.Scroll { 177 return &self.box.children.values()[list_index].widget.flow_box_scroll; 178 } 179 180 fn headerActive(self: *View) bool { 181 return self.box.getFocus().child_id == self.box.children.keys()[header_index]; 182 } 183 184 pub fn clearGrid(self: *View) void { 185 self.box.clearGrid(); 186 } 187 188 pub fn getGrid(self: View) ?Grid { 189 return self.box.getGrid(); 190 } 191 192 pub fn getFocus(self: *View) *Focus { 193 return self.box.getFocus(); 194 } 195 196 // up leaves the tab from the search box 197 pub fn atTop(self: *View) bool { 198 return self.headerActive(); 199 } 200 201 pub fn focusHeader(self: *View, root_focus: *Focus) void { 202 root_focus.setFocus(self.searchBox().getFocus().id); 203 } 204 }; 205