╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Undo.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
558 try addLabeled(allocator, details, detail_button.label, detail_button.text, detail_button.link); 559 } 560 if (failure) |message| try addText(allocator, details, try self.session.page_arena.allocator().print("error: {s}", .{message}), null, .single); 561 self.shown_failure = failure; 562 details.getFocus().kind = if (enabled) .{ .custom = item.form } else .container; 563 details.getFocus().child_id = details.children.keys()[0]; 564 self.detailScroll().x = 0; 565 self.detailScroll().y = 0; 566 self.detailScroll().getFocus().version +%= 1; 567 self.detailed_index = index; 568 } 569 570 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 571 self.clearGrid(); 572 if (self.data.clear) return try self.box.build(allocator, constraint, root_focus); 573 try self.refreshDetail(allocator); 574 const rows = &self.listScroll().child.box; 575 if (self.data.items.len == 0) { 576 const failure = self.session.data.undo_failure orelse self.data.failure; 577 if (!std.meta.eql(self.shown_failure, failure)) { 578 const message = if (failure) |name| try self.session.page_arena.allocator().print("error: {s}", .{name}) else "no undo history"; 579 try rows.children.values()[0].widget.text_box.setContent(allocator, message); 580 self.shown_failure = failure; 581 } 582 } 583 for (rows.children.keys(), rows.children.values()) |id, *child| ui.widget.markSelected(&child.widget.text_box, rows.getFocus().child_id == id); 584 const both_fit = if (constraint.max_size.width) |width| width >= list_max_width + detail_min_width else true; 585 self.contentBox().children.values()[0].max_size = if (both_fit) .{ .width = list_max_width, .height = null } else null; 586 const width = if (constraint.max_size.width) |value| if (both_fit) value - list_max_width else value else detail_min_width; 587 self.contentBox().children.values()[1].min_size = .{ .width = width, .height = null }; 588 for (self.detailScroll().child.box.children.values()) |*child| child.max_size = .{ .width = width -| 2, .height = null }; 589 try self.box.build(allocator, constraint, root_focus); 590 } 591 592 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 593 // the sub header sits above whichever content the route selects. 594 // scrolling crosses the boundary the same way the arrow keys do 595 const direction = inp.vertDirection(key); 596 if (self.headerActive()) { 597 if (direction == .down) root_focus.setFocus(self.box.children.values()[content_index].widget.getFocus().id); 598 return; 599 } 600 if (self.data.clear) { 601 if (direction == .up) root_focus.setFocus(self.headerBox().getFocus().id) else try self.clearInput(key, root_focus); 602 return; 603 } 604 if (direction == .up and self.contentAtTop()) { 605 root_focus.setFocus(self.headerBox().getFocus().id); 606 return; 607 } 608 try self.refreshDetail(allocator); 609 if (self.detailActive()) { 610 const details = &self.detailScroll().child.box; 611 if (self.selected()) |index| { 612 if (activated(root_focus, details.children.keys()[0], key) and self.data.handle.canUndo() and self.data.items[index].index > 0) { 613 self.requestUndo(ui.RoutablePage.repoUndoRoute(self.data.identity, self.data.items[index].index) orelse return error.RouteTooLong); 614 return; 615 } 616 } 617 if (inp.rowDelta(key, @intCast(details.children.count()))) |delta| { 618 ui.widget.moveRowFocus(details, self.detailScroll(), root_focus, delta); 619 } else if (key == .arrow_left) { 620 root_focus.setFocus(self.listScroll().getFocus().id); 621 } 622 } else if (inp.rowDelta(key, @intCast(self.listScroll().child.box.children.count()))) |delta| { 623 ui.widget.moveRowFocus(&self.listScroll().child.box, self.listScroll(), root_focus, delta); 624 } else switch (key) { 625 .arrow_right, .enter => if (self.selected() != null) { 626 root_focus.setFocus(self.detailScroll().getFocus().id); 627 }, 628 else => {}, 629 } 630 } 631 632 // the confirm button submits the form the web renderer posts 633 fn clearInput(self: *View, key: Key, root_focus: *Focus) !void { 634 const center = &self.box.children.values()[content_index].widget.center; 635 const button_id = center.child.box.getFocus().child_id orelse return; 636 if (!activated(root_focus, button_id, key) or !self.data.handle.canUndo()) return; 637 self.requestUndo(ui.RoutablePage.repoUndoClearRoute(self.data.identity) orelse return error.RouteTooLong); 638 } 639 640 fn contentAtTop(self: *View) bool { 641 const scroll = if (self.detailActive()) self.detailScroll() else self.listScroll(); 642 const rows = &scroll.child.box; 643 const id = rows.getFocus().child_id orelse return true; 644 return rows.children.getIndex(id) == 0 and scroll.y == 0; 645 } 646 647 // moving up from the sub header returns to the page's tabs 648 pub fn atTop(self: *View) bool { 649 return self.headerActive(); 650 } 651 652 // arriving from the page's tabs lands on the sub header, not the content 653 pub fn focusHeader(self: *View, root_focus: *Focus) bool { 654 root_focus.setFocus(self.headerBox().getFocus().id); 655 return true; 656 } 657 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 658 self.box.deinit(allocator); 659 } 660 pub fn clearGrid(self: *View) void { 661 self.box.clearGrid(); 662 } 663 pub fn getGrid(self: View) ?Grid { 664 return self.box.getGrid(); 665 } 666 pub fn getFocus(self: *View) *Focus { 667 return self.box.getFocus(); 668 } 669 }; 670