╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Commits.zig ──────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1019 }; 1020 } 1021 1022 pub const View = struct { 1023 box: wgt.Box(ui.Widget), 1024 data: *const Header, 1025 1026 pub fn init(allocator: std.mem.Allocator, data: *const Header, session: *ui.Session, location: ui.RoutablePage.RepoLocation) !Header.View { 1027 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 1028 errdefer box.deinit(allocator); 1029 1030 if (!session.data.is_local) { 1031 if (try ui.widget.CopyableText.initClone(allocator, session, location)) |value| { 1032 var clone_url = value; 1033 errdefer clone_url.deinit(allocator); 1034 const min_width = clone_url.minWidth(); 1035 box.getFocus().child_id = clone_url.getFocus().id; 1036 try box.children.put(allocator, clone_url.getFocus().id, .{ .widget = .{ .copyable_text = clone_url }, .rect = null, .min_size = .{ .width = min_width, .height = 3 }, .max_size = .{ .width = min_width, .height = 3 } }); 1037 } 1038 } 1039 1040 var spacer = try ui.widget.Spacer.init(allocator); 1041 errdefer spacer.deinit(allocator); 1042 try box.children.put(allocator, spacer.getFocus().id, .{ .widget = .{ .spacer = spacer }, .rect = null, .min_size = null }); 1043 1044 var text_box = try wgt.TextBox.init(allocator, data.content, .{ .border_style = .hidden, .wrap_kind = .none }); 1045 errdefer text_box.deinit(allocator); 1046 try box.children.put(allocator, text_box.getFocus().id, .{ .widget = .{ .text_box = text_box }, .rect = null, .min_size = null, .flex = .shrink }); 1047 1048 return .{ .box = box, .data = data }; 1049 } 1050 1051 pub fn deinit(self: *Header.View, allocator: std.mem.Allocator) void { 1052 self.box.deinit(allocator); 1053 } 1054 1055 pub fn build(self: *Header.View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1056 self.clearGrid(); 1057 try self.box.build(allocator, constraint, root_focus); 1058 } 1059 1060 pub fn input(self: *Header.View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1061 const clone_url = self.cloneUrl() orelse return; 1062 try clone_url.input(allocator, key, root_focus); 1063 } 1064 1065 pub fn focusCloneUrl(self: *Header.View, root_focus: *Focus) bool { 1066 const clone_url = self.cloneUrl() orelse return false; 1067 root_focus.setFocus(clone_url.getFocus().id); 1068 return true; 1069 } 1070 1071 pub fn hasCloneUrl(self: *Header.View) bool { 1072 return self.cloneUrl() != null; 1073 } 1074 1075 fn cloneUrl(self: *Header.View) ?*ui.widget.CopyableText { 1076 for (self.box.children.values()) |*child| switch (child.widget) { 1077 .copyable_text => |*copyable_text| return copyable_text, 1078 else => {}, 1079 }; 1080 return null; 1081 } 1082 1083 pub fn clearGrid(self: *Header.View) void { 1084 self.box.clearGrid(); 1085 } 1086 1087 pub fn getGrid(self: Header.View) ?Grid { 1088 return self.box.getGrid(); 1089 } 1090 1091 pub fn getFocus(self: *Header.View) *Focus { 1092 return self.box.getFocus(); 1093 } 1094 }; 1095 }; 1096