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