╭ Header.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 const evt = @import("../../event.zig"); 3 const ui = @import("../../ui.zig"); 4 const inp = @import("../input.zig"); 5 const xit = @import("xit"); 6 const xitui = xit.xitui; 7 const wgt = xitui.widget; 8 const layout = xitui.layout; 9 const Key = xitui.input.Key; 10 const Grid = xitui.grid.Grid; 11 const Focus = xitui.focus.Focus; 12 13 pub const AuthTab = @import("./../AuthTab.zig"); 14 15 const RefOrOid = ui.RoutablePage.RefOrOid; 16 const Array = ui.RoutablePage.Array(ui.RoutablePage.repo_route_max_len); 17 18 name: []const u8, 19 owner_name: []const u8, 20 title: ui.Title, 21 auth_tab: AuthTab, 22 // the ref/oid this page is viewing, so the files and commits tabs both link to 23 // it (switching tabs keeps the same ref). the value is url-encoded. 24 ref_or_oid: RefOrOid, 25 ref_or_oid_value: []const u8, 26 // the issues tab's tag filter, url-encoded ("" = unfiltered), so the tab links 27 // back to the filtered list. 28 issues_tag: []const u8, 29 patches_tag: []const u8, 30 discussions_tag: []const u8, 31 32 const Self = @This(); 33 34 pub fn init(arena: *std.heap.ArenaAllocator, name: []const u8, owner_name: []const u8, ref_or_oid: RefOrOid, ref_or_oid_value: []const u8, issues_tag: []const u8, patches_tag: []const u8, discussions_tag: []const u8) !Self { 35 return .{ 36 .name = name, 37 .owner_name = owner_name, 38 .title = try ui.Title.init(arena, name), 39 .auth_tab = AuthTab.init(), 40 .ref_or_oid = ref_or_oid, 41 .ref_or_oid_value = ref_or_oid_value, 42 .issues_tag = issues_tag, 43 .patches_tag = patches_tag, 44 .discussions_tag = discussions_tag, 45 }; 46 } 47 48 pub const View = struct { 49 scroll: wgt.Scroll(ui.Widget), 50 data: *const Self, 51 tab_ids: std.AutoArrayHashMapUnmanaged(usize, void), 52 tabs_id: usize, 53 first_group_width: usize, 54 55 pub fn init(allocator: std.mem.Allocator, data: *const Self, session: *ui.Session) !View { 56 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = .hidden, .rounded_corners = true, .direction = .horiz }); 57 errdefer box.deinit(allocator); 58 59 var title_box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 60 var title_box_owned = false; 61 errdefer if (!title_box_owned) title_box.deinit(allocator); 62 63 var tabs_box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 64 var tabs_box_owned = false; 65 errdefer if (!tabs_box_owned) tabs_box.deinit(allocator); 66 67 var tab_ids: std.AutoArrayHashMapUnmanaged(usize, void) = .empty; 68 errdefer tab_ids.deinit(allocator); 69 70 const aa = session.page_arena.allocator(); 71 const ref_name = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.ref_or_oid_value)); 72 const bottom_label = try ui.clippedBottomLabel(try aa.alloc(u8, ui.clipped_bottom_label_max_len), ref_name); 73 const bottom_label_width = try xitui.width.displayWidth(bottom_label); 74 var first_group_width = try data.title.width(); 75 76 // the user's name (local mode has no user pages to link to) 77 if (!session.data.is_local) { 78 var text_buf: [evt.User.name_max_len + 1]u8 = undefined; 79 const text = try std.fmt.bufPrint(&text_buf, "{s}/", .{data.owner_name}); 80 const link = try std.fmt.allocPrint(aa, "a:/user/{s}", .{data.owner_name}); 81 82 var text_box = try wgt.TextBox(ui.Widget).init(allocator, text, .{ .border_style = .hidden, .wrap_kind = .none }); 83 errdefer text_box.deinit(allocator); 84 text_box.getFocus().focusable = true; 85 text_box.getFocus().kind = .{ .custom = link }; 86 first_group_width += try xitui.width.displayWidth(text) + 2; 87 try title_box.children.put(allocator, text_box.getFocus().id, .{ 88 .widget = .{ .text_box = text_box }, 89 .rect = null, 90 .min_size = null, 91 }); 92 } 93 94 // local routes carry no identity, so their urls come out elided 95 const identity = if (session.data.is_local) "" else try std.fmt.allocPrint(aa, "{s}/{s}", .{ data.owner_name, data.name }); 96 97 // title links to the repo's files root (the bare route, so it resolves 98 // to the default branch). 99 { 100 const files_root_route = ui.RoutablePage.repoFilesRoute(identity, null, "", "", 0) orelse return error.RouteTooLong; 101 const title_link = try std.fmt.allocPrint(aa, "a:{s}", .{try files_root_route.toUrl(session.page_arena)}); 102 var title_view = try ui.Title.View.init(allocator, &data.title); 103 errdefer title_view.deinit(allocator); 104 title_view.getFocus().focusable = true; 105 title_view.getFocus().kind = .{ .custom = title_link }; 106 try title_box.children.put(allocator, title_view.getFocus().id, .{ 107 .widget = .{ .title = title_view }, 108 .rect = null, 109 .min_size = null, 110 }); 111 } 112 113 // spacer 114 { 115 var text = try wgt.Text(ui.Widget).init(allocator, " "); 116 errdefer text.deinit(allocator); 117 try tabs_box.children.put(allocator, text.getFocus().id, .{ 118 .widget = .{ .text = text }, 119 .rect = null, 120 .min_size = .{ .width = 1, .height = null }, 121 }); 122 } 123 124 // every tab link is repo-scoped so selecting one stays on this page — 125 // switching its stack and updating the url — instead of navigating to 126 // the global settings or auth pages. the "ai:" prefix makes each an 127 // in-page anchor: crossPageLink ignores it so a wasm click just switches 128 // tabs (the page already holds every tab's content), while the href is 129 // still followed with js off. the files tab routes through the shared 130 // helper so the /repo/.../files url format lives in one place. 131 // both tabs link to the ref/oid this page is viewing, so switching tabs 132 // keeps the same ref (the files tab opens at its root directory). 133 const current_page = session.data.current_page; 134 const current_tag = std.meta.activeTag(current_page); 135 const files_route = ui.RoutablePage.repoFilesRoute(identity, data.ref_or_oid, data.ref_or_oid_value, "", 0) orelse return error.RouteTooLong; 136 const files_link = try ui.inPageTabLink(session, files_route, current_tag == .repo_files); 137 const commits_route = ui.RoutablePage.repoCommitsRoute(identity, data.ref_or_oid, data.ref_or_oid_value, 0, "") orelse return error.RouteTooLong; 138 const commits_link = try ui.inPageTabLink(session, commits_route, current_tag == .repo_commits); 139 const refs_route = ui.RoutablePage.repoRefsRoute(identity, .branch, "") orelse return error.RouteTooLong; 140 const refs_link = try ui.inPageTabLink(session, refs_route, current_tag == .repo_refs); 141 const issues_route = ui.RoutablePage.repoIssuesRoute(identity, .open, data.issues_tag, "") orelse return error.RouteTooLong; 142 const issues_link = try ui.inPageTabLink(session, issues_route, current_tag == .repo_issues); 143 const patches_route = ui.RoutablePage.repoPatchesRoute(identity, .open, data.patches_tag, "") orelse return error.RouteTooLong; 144 const patches_link = try ui.inPageTabLink(session, patches_route, current_tag == .repo_patches); 145 const discussions_route = ui.RoutablePage.repoDiscussionsRoute(identity, data.discussions_tag, "") orelse return error.RouteTooLong; 146 const discussions_link = try ui.inPageTabLink(session, discussions_route, current_tag == .repo_discussions); 147 const events_route = ui.RoutablePage.repoEventsRoute(identity, .active, null, "") orelse return error.RouteTooLong; 148 const events_link = try ui.inPageTabLink(session, events_route, current_tag == .repo_events); 149 const settings_route = ui.RoutablePage{ .repo_settings = Array.from(identity) orelse return error.RouteTooLong }; 150 const settings_link = try ui.inPageTabLink(session, settings_route, current_tag == .repo_settings); 151 const auth_route = ui.RoutablePage{ .repo_auth = Array.from(identity) orelse return error.RouteTooLong }; 152 const auth_link = try ui.inPageTabLink(session, auth_route, current_tag == .repo_auth); 153 154 // the tab matching the current page is focused initially; matching by 155 // link (rather than position) keeps this robust to tab changes. 156 var selected_tab: ?usize = null; 157 158 // files tab 159 { 160 var text_box = try wgt.TextBox(ui.Widget).init(allocator, "files", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none, .bottom_label = bottom_label }); 161 errdefer text_box.deinit(allocator); 162 text_box.getFocus().focusable = true; 163 text_box.getFocus().kind = .{ .custom = files_link }; 164 try tab_ids.put(allocator, text_box.getFocus().id, {}); 165 if (current_tag == .repo_files) selected_tab = text_box.getFocus().id; 166 try tabs_box.children.put(allocator, text_box.getFocus().id, .{ 167 .widget = .{ .text_box = text_box }, 168 .rect = null, 169 .min_size = .{ .width = @max("files".len, bottom_label_width) + 2, .height = null }, 170 }); 171 } 172 173 // commits tab 174 { 175 var text_box = try wgt.TextBox(ui.Widget).init(allocator, "commits", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none, .bottom_label = bottom_label }); 176 errdefer text_box.deinit(allocator); 177 text_box.getFocus().focusable = true; 178 text_box.getFocus().kind = .{ .custom = commits_link }; 179 try tab_ids.put(allocator, text_box.getFocus().id, {}); 180 if (current_tag == .repo_commits) selected_tab = text_box.getFocus().id; 181 try tabs_box.children.put(allocator, text_box.getFocus().id, .{ 182 .widget = .{ .text_box = text_box }, 183 .rect = null, 184 .min_size = .{ .width = @max("commits".len, bottom_label_width) + 2, .height = null }, 185 }); 186 } 187 188 // refs tab 189 { 190 var text_box = try wgt.TextBox(ui.Widget).init(allocator, "refs", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 191 errdefer text_box.deinit(allocator); 192 text_box.getFocus().focusable = true; 193 text_box.getFocus().kind = .{ .custom = refs_link }; 194 try tab_ids.put(allocator, text_box.getFocus().id, {}); 195 if (current_tag == .repo_refs) selected_tab = text_box.getFocus().id; 196 try tabs_box.children.put(allocator, text_box.getFocus().id, .{ 197 .widget = .{ .text_box = text_box }, 198 .rect = null, 199 .min_size = .{ .width = "refs".len + 2, .height = null }, 200 }); 201 } 202 203 // issues tab 204 { 205 var text_box = try wgt.TextBox(ui.Widget).init(allocator, "issues", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 206 errdefer text_box.deinit(allocator); 207 text_box.getFocus().focusable = true; 208 text_box.getFocus().kind = .{ .custom = issues_link }; 209 try tab_ids.put(allocator, text_box.getFocus().id, {}); 210 if (current_tag == .repo_issues) selected_tab = text_box.getFocus().id; 211 try tabs_box.children.put(allocator, text_box.getFocus().id, .{ 212 .widget = .{ .text_box = text_box }, 213 .rect = null, 214 .min_size = .{ .width = "issues".len + 2, .height = null }, 215 }); 216 } 217 218 // patches tab 219 { 220 var text_box = try wgt.TextBox(ui.Widget).init(allocator, "patches", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 221 errdefer text_box.deinit(allocator); 222 text_box.getFocus().focusable = true; 223 text_box.getFocus().kind = .{ .custom = patches_link }; 224 try tab_ids.put(allocator, text_box.getFocus().id, {}); 225 if (current_tag == .repo_patches) selected_tab = text_box.getFocus().id; 226 try tabs_box.children.put(allocator, text_box.getFocus().id, .{ 227 .widget = .{ .text_box = text_box }, 228 .rect = null, 229 .min_size = .{ .width = "patches".len + 2, .height = null }, 230 }); 231 } 232 233 // discussions tab 234 { 235 var text_box = try wgt.TextBox(ui.Widget).init(allocator, "discussions", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 236 errdefer text_box.deinit(allocator); 237 text_box.getFocus().focusable = true; 238 text_box.getFocus().kind = .{ .custom = discussions_link }; 239 try tab_ids.put(allocator, text_box.getFocus().id, {}); 240 if (current_tag == .repo_discussions) selected_tab = text_box.getFocus().id; 241 try tabs_box.children.put(allocator, text_box.getFocus().id, .{ 242 .widget = .{ .text_box = text_box }, 243 .rect = null, 244 .min_size = .{ .width = "discussions".len + 2, .height = null }, 245 }); 246 } 247 248 // events 249 { 250 var text_box = try wgt.TextBox(ui.Widget).init(allocator, "events", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 251 errdefer text_box.deinit(allocator); 252 text_box.getFocus().focusable = true; 253 text_box.getFocus().kind = .{ .custom = events_link }; 254 try tab_ids.put(allocator, text_box.getFocus().id, {}); 255 if (current_tag == .repo_events) selected_tab = text_box.getFocus().id; 256 try tabs_box.children.put(allocator, text_box.getFocus().id, .{ 257 .widget = .{ .text_box = text_box }, 258 .rect = null, 259 .min_size = .{ .width = "events".len + 2, .height = null }, 260 }); 261 } 262 263 // spacer pushes settings + auth to the right 264 { 265 var spacer = try ui.Spacer.init(allocator); 266 errdefer spacer.deinit(allocator); 267 try tabs_box.children.put(allocator, spacer.getFocus().id, .{ 268 .widget = .{ .spacer = spacer }, 269 .rect = null, 270 .min_size = null, 271 .flex = .grow, 272 }); 273 } 274 275 // settings tab. settings are account preferences, so it needs a login 276 // (which also rules out local mode, which has no accounts). 277 if (session.data.user_id != null) { 278 var text_box = try wgt.TextBox(ui.Widget).init(allocator, "settings", .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 279 errdefer text_box.deinit(allocator); 280 text_box.getFocus().focusable = true; 281 text_box.getFocus().kind = .{ .custom = settings_link }; 282 try tab_ids.put(allocator, text_box.getFocus().id, {}); 283 if (current_tag == .repo_settings) selected_tab = text_box.getFocus().id; 284 try tabs_box.children.put(allocator, text_box.getFocus().id, .{ 285 .widget = .{ .text_box = text_box }, 286 .rect = null, 287 .min_size = .{ .width = "settings".len + 2, .height = null }, 288 }); 289 } 290 291 // auth tab (login / logout). AuthTab defaults to the global ai:/auth 292 // link; repoint its instance at this repo's auth route so it stays on 293 // this page. local mode has no accounts, so it has no auth tab. 294 if (!session.data.is_local) { 295 var auth_tab = try AuthTab.View.init(allocator, session); 296 errdefer auth_tab.deinit(allocator); 297 auth_tab.text_box.getFocus().kind = .{ .custom = auth_link }; 298 try tab_ids.put(allocator, auth_tab.getFocus().id, {}); 299 if (current_tag == .repo_auth) selected_tab = auth_tab.getFocus().id; 300 try tabs_box.children.put(allocator, auth_tab.getFocus().id, .{ 301 .widget = .{ .auth_tab = auth_tab }, 302 .rect = null, 303 .min_size = .{ .width = auth_tab.minWidth(), .height = null }, 304 }); 305 } 306 307 // quit tab 308 if (session.is_terminal) { 309 var text_box = try wgt.TextBox(ui.Widget).init(allocator, ui.Quit.tab_label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 310 errdefer text_box.deinit(allocator); 311 text_box.getFocus().focusable = true; 312 text_box.getFocus().kind = .{ .custom = ui.Quit.tab_kind }; 313 try tab_ids.put(allocator, text_box.getFocus().id, {}); 314 try tabs_box.children.put(allocator, text_box.getFocus().id, .{ 315 .widget = .{ .text_box = text_box }, 316 .rect = null, 317 // the label is a single column; +2 for the border 318 .min_size = .{ .width = 1 + 2, .height = null }, 319 }); 320 } 321 322 tabs_box.getFocus().child_id = selected_tab orelse tab_ids.keys()[0]; 323 const title_id = title_box.getFocus().id; 324 const tabs_id = tabs_box.getFocus().id; 325 try box.children.put(allocator, title_id, .{ 326 .widget = .{ .box = title_box }, 327 .rect = null, 328 .min_size = null, 329 }); 330 title_box_owned = true; 331 try box.children.put(allocator, tabs_id, .{ 332 .widget = .{ .box = tabs_box }, 333 .rect = null, 334 .min_size = null, 335 }); 336 tabs_box_owned = true; 337 box.getFocus().child_id = tabs_id; 338 339 return .{ 340 .scroll = try wgt.Scroll(ui.Widget).init(allocator, .{ .box = box }, .{ .direction = .horiz, .show_bar = false, .web_native = !session.is_terminal }), 341 .data = data, 342 .tab_ids = tab_ids, 343 .tabs_id = tabs_id, 344 .first_group_width = first_group_width, 345 }; 346 } 347 348 pub fn deinit(self: *View, allocator: std.mem.Allocator) void { 349 self.scroll.deinit(allocator); 350 self.tab_ids.deinit(allocator); 351 } 352 353 pub fn build(self: *View, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 354 self.clearGrid(); 355 const box = &self.scroll.child.box; 356 const tabs_child = self.tabsChild(); 357 const tabs_box = &tabs_child.widget.box; 358 359 // only the selected tab shows its border 360 const selected_tab = if (box.getFocus().child_id == self.tabs_id) tabs_box.getFocus().child_id else null; 361 var tabs_width: usize = 0; 362 for (tabs_box.children.keys(), tabs_box.children.values()) |id, *child| { 363 const tb: ?*wgt.TextBox(ui.Widget) = switch (child.widget) { 364 .text_box => |*x| x, 365 .auth_tab => |*at| blk: { 366 // the label tracks login state per frame, so the width must too 367 child.min_size = .{ .width = at.minWidth(), .height = null }; 368 break :blk &at.text_box; 369 }, 370 else => null, 371 }; 372 if (tb) |t| { 373 t.options.border_style = if (selected_tab == id) .single else .hidden; 374 } 375 tabs_width += if (child.min_size) |min_size| min_size.width orelse 0 else 0; 376 } 377 378 const viewport_width = constraint.max_size.width orelse constraint.min_size.width; 379 // the outer box's hidden border occupies two columns. keep the title 380 // and tabs together if they fit; otherwise tab strip on its own row. 381 const content_width = if (viewport_width) |width| width -| 2 else null; 382 const wrap = if (content_width) |width| self.first_group_width + tabs_width > width else false; 383 box.options.direction = if (wrap) .vert else .horiz; 384 tabs_child.min_size = if (wrap) .{ .width = content_width, .height = null } else null; 385 386 var scroll_constraint = constraint; 387 scroll_constraint.min_size.width = viewport_width; 388 try self.scroll.build(allocator, scroll_constraint, root_focus); 389 } 390 391 pub fn input(self: *View, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 392 _ = allocator; 393 const current_tab = self.currentTabIndex() orelse return; 394 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 395 const tab_id = self.tab_ids.keys()[new_tab]; 396 root_focus.setFocus(tab_id); 397 const tabs_child = self.tabsChild(); 398 const tabs_rect = tabs_child.rect orelse return; 399 const tab = tabs_child.widget.box.children.get(tab_id) orelse return; 400 var rect = tab.rect orelse return; 401 rect.x += tabs_rect.x; 402 rect.y += tabs_rect.y; 403 self.scroll.scrollToRect(rect); 404 } 405 } 406 407 pub fn clearGrid(self: *View) void { 408 self.scroll.clearGrid(); 409 } 410 411 pub fn getGrid(self: View) ?Grid { 412 return self.scroll.getGrid(); 413 } 414 415 pub fn getFocus(self: *View) *Focus { 416 return self.scroll.getFocus(); 417 } 418 419 pub fn getSelectedIndex(self: View) ?usize { 420 return self.currentTabIndex(); 421 } 422 423 fn currentTabIndex(self: View) ?usize { 424 if (self.scroll.child.box.focus.child_id != self.tabs_id) return null; 425 const child_id = self.tabsChild().widget.box.focus.child_id orelse return null; 426 return self.tab_ids.getIndex(child_id); 427 } 428 429 fn tabsChild(self: *const View) *wgt.Box(ui.Widget).Child { 430 return self.scroll.child.box.children.getPtr(self.tabs_id) orelse unreachable; 431 } 432 }; 433