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