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