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