╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Issues.zig ───────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1116 // the terminal submit paths: the new form commits a new-issue event, the 1117 // edit form re-emits the selected issue's event with the form's content. 1118 // the web posts the forms to their routes instead. 1119 fn submitForm(self: *View, allocator: std.mem.Allocator) !void { 1120 if (self.data.view == .edit) { 1121 try self.submitEditedIssue(allocator); 1122 } else { 1123 try self.submitNewIssue(allocator); 1124 } 1125 } 1126 1127 // commit the new issue to the repo's events branch and navigate to it. 1128 // this is the terminal path; the web posts the form to the issue route, 1129 // so the wasm side never runs (or compiles) the repo access below. 1130 fn submitNewIssue(self: *View, allocator: std.mem.Allocator) !void { 1131 if (comptime wasm) return; 1132 const io = self.session.io orelse return; 1133 const src = self.data.repo_source orelse return; 1134 1135 const form = self.issueForm(); 1136 const title_input = &form.children.values()[title_field_index].widget.text_input; 1137 const tags_input = &form.children.values()[tags_field_index].widget.text_input; 1138 const description_input = &form.children.values()[description_field_index].widget.text_input; 1139 1140 const title = try title_input.text(allocator); 1141 defer allocator.free(title); 1142 const tags = try tags_input.text(allocator); 1143 defer allocator.free(tags); 1144 const description = try description_input.text(allocator); 1145 defer allocator.free(description); 1146 1147 if (!evt.Issue.fieldsValid(title, tags)) return; 1148 1149 var id_bytes: [evt.event_id_size]u8 = undefined; 1150 io.random(&id_bytes); 1151 const event_id_hex = std.fmt.bytesToHex(id_bytes, .lower); 1152 1153 const event = evt.EventWithId{ 1154 .id = event_id_hex, 1155 .timestamp = @intCast(std.Io.Timestamp.now(io, .real).toSeconds()), 1156 .event = .{ .issue = .{ 1157 .title = title, 1158 .description = description, 1159 .tags = tags, 1160 } }, 1161 }; 1162 1163 switch (src.repo_kind) { 1164 inline else => |repo_kind| { 1165 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, .{ .path = src.path }); 1166 defer any_repo.deinit(io, allocator); 1167 switch (any_repo) { 1168 inline else => |*repo| try evt.consume(repo_kind, repo.self_repo_opts, io, allocator, repo, evt.events_ref, &.{event}), 1169 } 1170 }, 1171 } 1172 1173 // wipe the form so a return visit starts fresh 1174 title_input.clear(allocator); 1175 tags_input.clear(allocator); 1176 description_input.clear(allocator); 1177 1178 const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, .open, "", &event_id_hex) orelse return; 1179 try self.session.navigate(route); 1180 } 1181 1182 // re-emit the selected issue's event with the form's content (status 1183 // preserved), then reload the issue's page. this is the terminal path; 1184 // the web posts the form to the edit route. 1185 fn submitEditedIssue(self: *View, allocator: std.mem.Allocator) !void { 1186 if (comptime wasm) return; 1187 const io = self.session.io orelse return; 1188 const src = self.data.repo_source orelse return; 1189 const entry = self.data.selectedIssue() orelse return; 1190 1191 const form = self.issueForm(); 1192 const title_input = &form.children.values()[title_field_index].widget.text_input; 1193 const tags_input = &form.children.values()[tags_field_index].widget.text_input; 1194 const description_input = &form.children.values()[description_field_index].widget.text_input; 1195 1196 const title = try title_input.text(allocator); 1197 defer allocator.free(title); 1198 const tags = try tags_input.text(allocator); 1199 defer allocator.free(tags); 1200 const description = try description_input.text(allocator); 1201 defer allocator.free(description); 1202 1203 if (!evt.Issue.fieldsValid(title, tags)) return; 1204 1205 var id_bytes: [evt.event_id_size]u8 = undefined; 1206 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 1207 1208 switch (src.repo_kind) { 1209 inline else => |repo_kind| { 1210 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, .{ .path = src.path }); 1211 defer any_repo.deinit(io, allocator); 1212 switch (any_repo) { 1213 inline else => |*repo| try evt.Issue.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .fields = .{ 1214 .title = title, 1215 .tags = tags, 1216 .description = description, 1217 } }), 1218 } 1219 }, 1220 } 1221 1222 const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, entry.issue.status, "", entry.id) orelse return; 1223 try self.session.navigate(route); 1224 } 1225 1226 // flip the shown issue's status by re-emitting its event, then reload the 1227 // page rooted at the issue so the view reflects the change. this is the 1228 // terminal path; the web posts the button's form to the status route. 1229 fn toggleIssueStatus(self: *View, allocator: std.mem.Allocator, index: usize) !void { 1230 if (comptime wasm) return; 1231 const io = self.session.io orelse return; 1232 const src = self.data.repo_source orelse return; 1233 const sel = self.detailed_index[index] orelse return; 1234 const entry = self.window(index).issues[sel]; 1235 1236 const status: evt.Issue.Status = switch (entry.issue.status) { 1237 .open => .closed, 1238 .closed => .open, 1239 }; 1240 1241 var id_bytes: [evt.event_id_size]u8 = undefined; 1242 _ = try std.fmt.hexToBytes(&id_bytes, entry.id[0 .. evt.event_id_size * 2]); 1243 1244 switch (src.repo_kind) { 1245 inline else => |repo_kind| { 1246 var any_repo = try rp.AnyRepo(repo_kind, .{}).open(io, allocator, .{ .path = src.path }); 1247 defer any_repo.deinit(io, allocator); 1248 switch (any_repo) { 1249 inline else => |*repo| try evt.Issue.update(repo_kind, repo.self_repo_opts, io, allocator, repo, &id_bytes, .{ .status = status }), 1250 } 1251 }, 1252 } 1253 1254 const route = ui.RoutablePage.repoIssuesRoute(self.data.identity, status, "", entry.id) orelse return; 1255 try self.session.navigate(route); 1256 } 1257 1258 // arrow keys move the tag selection; at the flow's edges focus crosses to 1259 // the neighboring widgets. 1260 fn tagsInput(self: *View, index: usize, key: Key, root_focus: *Focus) !void { 1261 const tf = self.tagFlow(index) orelse return; 1262 const cid = tf.focus.child_id orelse return; 1263 const cur = tf.indexOfFocusId(cid) orelse return; 1264 const count = tf.text_boxes.items.len; 1265 const sc = self.detailScroll(index); 1266 switch (key) { 1267 .arrow_left => if (cur > 0) self.focusTag(index, tf, root_focus, cur - 1) else try self.focusList(index, root_focus), 1268 .arrow_right => if (cur + 1 < count) self.focusTag(index, tf, root_focus, cur + 1), 1269 .arrow_up => if (tf.rowStep(cur, false)) |i| self.focusTag(index, tf, root_focus, i) else self.focusTitle(index, root_focus), 1270 .arrow_down => if (tf.rowStep(cur, true)) |i| self.focusTag(index, tf, root_focus, i) else try self.focusDescription(index, root_focus), 1271 .home => self.focusTag(index, tf, root_focus, 0), 1272 .end => self.focusTag(index, tf, root_focus, count - 1), 1273 .mouse => |mouse| switch (mouse.action) { 1274 .scroll => |dir| { 1275 sc.y += if (dir == .up) @as(isize, -1) else 1; 1276 sc.clampToContent(); 1277 }, 1278 else => {}, 1279 }, 1280 else => {}, 1281 } 1282 } 1283 1284 const button_in_row_index: usize = 1; 1285 const edit_in_row_index: usize = 2; 1286 const title_child_index: usize = 0; 1287 const tags_child_index: usize = 1; 1288 1289 fn tagFlow(self: *View, index: usize) ?*ui.TagFlow { 1290 const inner = self.detailInner(index); 1291 if (inner.children.count() <= tags_child_index) return null; 1292 return switch (inner.children.values()[tags_child_index].widget) { 1293 .tag_flow => |*tf| tf, 1294 else => null, 1295 }; 1296 } 1297 1298 fn tagsFocused(self: *View, index: usize) bool { 1299 const inner = self.detailInner(index); 1300 const cid = inner.getFocus().child_id orelse return false; 1301 return inner.children.getIndex(cid) == tags_child_index and self.tagFlow(index) != null; 1302 } 1303 1304 // the open/close button inside the detail frame's tool row. 1305 fn statusButton(self: *View, index: usize) ?*wgt.TextBox(ui.Widget) { 1306 const row = self.toolRow(index); 1307 if (row.children.count() == 0) return null; 1308 return &row.children.values()[button_in_row_index].widget.text_box; 1309 } 1310 1311 fn toolRowFocused(self: *View, index: usize) bool { 1312 const outer = self.detailOuter(index); 1313 const cid = outer.getFocus().child_id orelse return false; 1314 return outer.children.getIndex(cid) == tool_row_index; 1315 } 1316 1317 fn focusTag(self: *View, index: usize, tf: *ui.TagFlow, root_focus: *Focus, item: usize) void { 1318 root_focus.setFocus(tf.text_boxes.items[item].getFocus().id); 1319 // keep the tag visible on the terminal: its rect offset by the flow's 1320 // position in the pane. 1321 if (self.session.is_terminal and item < tf.rects.items.len) { 1322 if (self.detailInner(index).children.values()[tags_child_index].rect) |flow_rect| { 1323 var rect = tf.rects.items[item]; 1324 rect.x += flow_rect.x; 1325 rect.y += flow_rect.y; 1326 self.detailScroll(index).scrollToRect(rect); 1327 } 1328 } 1329 } 1330 1331 fn titleFocused(self: *View, index: usize) bool { 1332 const inner = self.detailInner(index); 1333 const cid = inner.getFocus().child_id orelse return false; 1334 return inner.children.getIndex(cid) == title_child_index; 1335 } 1336 1337 // the title sits at the top of the pane, so focusing it scrolls there. 1338 fn focusTitle(self: *View, index: usize, root_focus: *Focus) void { 1339 const inner = self.detailInner(index); 1340 if (inner.children.count() == 0) return; 1341 root_focus.setFocus(inner.children.keys()[title_child_index]); 1342 self.detailScroll(index).y = 0; 1343 } 1344 1345 fn focusTags(self: *View, index: usize, root_focus: *Focus) !void { 1346 const tf = self.tagFlow(index) orelse return; 1347 if (tf.text_boxes.items.len == 0) return; 1348 const cid = tf.focus.child_id orelse tf.text_boxes.items[0].getFocus().id; 1349 const item = tf.indexOfFocusId(cid) orelse 0; 1350 self.focusTag(index, tf, root_focus, item); 1351 } 1352 1353 fn focusDescription(self: *View, index: usize, root_focus: *Focus) !void { 1354 if (self.description_id[index]) |id| root_focus.setFocus(id); 1355 } 1356 1357 // return to the tool row's last-focused button (the header when the 1358 // description page shows no row). 1359 fn focusToolRow(self: *View, index: usize, root_focus: *Focus) void { 1360 const cid = self.toolRow(index).getFocus().child_id orelse return self.focusHeader(root_focus); 1361 root_focus.setFocus(cid); 1362 } 1363 1364 // enter the detail pane. an empty pane (no issues) can't be entered. 1365 fn focusDetail(self: *View, index: usize, root_focus: *Focus) !void { 1366 if (self.detailInner(index).children.count() == 0) return; 1367 root_focus.setFocus(self.detailOuter(index).getFocus().id); 1368 } 1369 1370 // return to the list. 1371 fn focusList(self: *View, index: usize, root_focus: *Focus) !void { 1372 root_focus.setFocus(self.listScroll(index).getFocus().id); 1373 } 1374 1375 // cross to the header tabs above the stack. 1376 fn focusHeader(self: *View, root_focus: *Focus) void { 1377 root_focus.setFocus(self.box.children.keys()[header_index]); 1378 } 1379 1380 pub fn clearGrid(self: *View) void { 1381 self.box.clearGrid(); 1382 } 1383 1384 pub fn getGrid(self: View) ?Grid { 1385 return self.box.getGrid(); 1386 } 1387 1388 pub fn getFocus(self: *View) *Focus { 1389 return self.box.getFocus(); 1390 } 1391 1392 // for the parent's "scroll up at the top jumps to the header" check: at the 1393 // top only while the header tabs hold focus, so up from the split 1394 // crosses into the tabs first. 1395 pub fn getSelectedIndex(self: *View) ?usize { 1396 return if (self.headerActive()) 0 else 1; 1397 } 1398 }; 1399 1400 // the "a:" navigation link for `status`'s issues page filtered to the 1401 // url-encoded `tag` and rooted at issue `id` within `identity` ("owner/name"). 1402 // a rooted url ignores `status` (it derives its view from the issue's own); 1403 // with an empty `id` this is the bare list link. 1404 fn issuesLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: evt.Issue.Status, tag: []const u8, id: []const u8) ![]const u8 { 1405 const route = ui.RoutablePage.repoIssuesRoute(identity, status, tag, id) orelse return error.RouteTooLong; 1406 const url = try route.toUrl(page_arena); 1407 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 1408 } 1409 1410 // the in-page "ai:" anchor for selecting issue `id` in `identity`'s list; the 1411 // href is only followed with js off. 1412 fn issueRowLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, id: []const u8) ![]const u8 { 1413 const route = ui.RoutablePage.repoIssuesRoute(identity, .open, "", id) orelse return error.RouteTooLong; 1414 const url = try route.toUrl(page_arena); 1415 return std.fmt.allocPrint(page_arena.allocator(), "ai:{s}", .{url}); 1416 } 1417 1418 // the "a:" link to the whole-description page of issue `id` within `identity`. 1419 fn descriptionLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, id: []const u8) ![]const u8 { 1420 const route = ui.RoutablePage.repoIssuesDescriptionRoute(identity, id) orelse return error.RouteTooLong; 1421 const url = try route.toUrl(page_arena); 1422 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 1423 } 1424 1425 // the "a:" link to `status`'s issues list filtered to `tag` (raw; encoded here). 1426 fn tagLink(page_arena: *std.heap.ArenaAllocator, identity: []const u8, status: evt.Issue.Status, tag: []const u8) ![]const u8 { 1427 const encoded = try ui.urlEncodeRef(page_arena.allocator(), tag); 1428 const route = ui.RoutablePage.repoIssuesRoute(identity, status, encoded, "") orelse return error.RouteTooLong; 1429 const url = try route.toUrl(page_arena); 1430 return std.fmt.allocPrint(page_arena.allocator(), "a:{s}", .{url}); 1431 } 1432 1433 // tabs switching between the issues page's views. 1434 pub const Header = struct { 1435 box: wgt.Box(ui.Widget), 1436 tab_ids: std.AutoArrayHashMapUnmanaged(usize, void), 1437 1438 pub fn init(allocator: std.mem.Allocator, session: *ui.Session, data: *const Self) !Header { 1439 var box = try wgt.Box(ui.Widget).init(allocator, .{ .border_style = null, .direction = .horiz }); 1440 errdefer box.deinit(allocator); 1441 1442 var tab_ids: std.AutoArrayHashMapUnmanaged(usize, void) = .empty; 1443 errdefer tab_ids.deinit(allocator); 1444 1445 const aa = session.page_arena.allocator(); 1446 1447 // a list tab per status, labeled with its listing's issue count 1448 for ([_]evt.Issue.Status{ .open, .closed }) |status| { 1449 const route = ui.RoutablePage.repoIssuesRoute(data.identity, status, data.tag, "") orelse return error.RouteTooLong; 1450 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 1451 const label = try std.fmt.allocPrint(aa, "{s} ({d})", .{ @tagName(status), data.window(status).count }); 1452 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1453 errdefer text_box.deinit(allocator); 1454 text_box.getFocus().focusable = true; 1455 text_box.getFocus().kind = .{ .custom = link }; 1456 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1457 try box.children.put(allocator, text_box.getFocus().id, .{ 1458 .widget = .{ .text_box = text_box }, 1459 .rect = null, 1460 .min_size = .{ .width = label.len + 2, .height = null }, 1461 }); 1462 } 1463 1464 // tags tab, labeled with the active tag filter 1465 { 1466 const tags_route = ui.RoutablePage.repoIssuesTagsRoute(data.identity, data.tag) orelse return error.RouteTooLong; 1467 const tags_link = try std.fmt.allocPrint(aa, "ai:{s}", .{try tags_route.toUrl(session.page_arena)}); 1468 const label = if (data.tag.len == 0) "tags" else blk: { 1469 const decoded = std.Uri.percentDecodeInPlace(try aa.dupe(u8, data.tag)); 1470 break :blk try std.fmt.allocPrint(aa, "tags ({s})", .{decoded}); 1471 }; 1472 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1473 errdefer text_box.deinit(allocator); 1474 text_box.getFocus().focusable = true; 1475 text_box.getFocus().kind = .{ .custom = tags_link }; 1476 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1477 try box.children.put(allocator, text_box.getFocus().id, .{ 1478 .widget = .{ .text_box = text_box }, 1479 .rect = null, 1480 .min_size = .{ .width = label.len + 2, .height = null }, 1481 }); 1482 } 1483 1484 // new-issue tab; an edit url shows the edit tab in its place 1485 { 1486 const route = if (data.view == .edit) 1487 ui.RoutablePage.repoIssuesEditRoute(data.identity, data.selected_id) orelse return error.RouteTooLong 1488 else 1489 ui.RoutablePage.repoIssuesNewRoute(data.identity) orelse return error.RouteTooLong; 1490 const link = try std.fmt.allocPrint(aa, "ai:{s}", .{try route.toUrl(session.page_arena)}); 1491 const label: []const u8 = if (data.view == .edit) "edit" else "new"; 1492 var text_box = try wgt.TextBox(ui.Widget).init(allocator, label, .{ .border_style = .single, .rounded_corners = true, .wrap_kind = .none }); 1493 errdefer text_box.deinit(allocator); 1494 text_box.getFocus().focusable = true; 1495 text_box.getFocus().kind = .{ .custom = link }; 1496 try tab_ids.put(allocator, text_box.getFocus().id, {}); 1497 try box.children.put(allocator, text_box.getFocus().id, .{ 1498 .widget = .{ .text_box = text_box }, 1499 .rect = null, 1500 .min_size = .{ .width = label.len + 2, .height = null }, 1501 }); 1502 } 1503 1504 var self = Header{ .box = box, .tab_ids = tab_ids }; 1505 // the tab matching the page's view is selected initially. 1506 self.getFocus().child_id = self.tab_ids.keys()[View.viewIndex(data.view)]; 1507 return self; 1508 } 1509 1510 pub fn deinit(self: *Header, allocator: std.mem.Allocator) void { 1511 self.box.deinit(allocator); 1512 self.tab_ids.deinit(allocator); 1513 } 1514 1515 pub fn build(self: *Header, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 1516 self.clearGrid(); 1517 // only the selected tab shows its border 1518 for (self.box.children.keys(), self.box.children.values()) |id, *child| { 1519 switch (child.widget) { 1520 .text_box => |*tb| tb.options.border_style = if (self.getFocus().child_id == id) .single else .hidden, 1521 else => {}, 1522 } 1523 } 1524 try self.box.build(allocator, constraint, root_focus); 1525 } 1526 1527 pub fn input(self: *Header, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 1528 _ = allocator; 1529 const current_tab = self.currentTabIndex() orelse return; 1530 if (inp.moveTab(key, current_tab, self.tab_ids.count())) |new_tab| { 1531 root_focus.setFocus(self.tab_ids.keys()[new_tab]); 1532 } 1533 } 1534 1535 pub fn clearGrid(self: *Header) void { 1536 self.box.clearGrid(); 1537 } 1538 1539 pub fn getGrid(self: Header) ?Grid { 1540 return self.box.getGrid(); 1541 } 1542 1543 pub fn getFocus(self: *Header) *Focus { 1544 return self.box.getFocus(); 1545 } 1546 1547 pub fn getSelectedIndex(self: Header) ?usize { 1548 return self.currentTabIndex(); 1549 } 1550 1551 fn currentTabIndex(self: Header) ?usize { 1552 const child_id = self.box.focus.child_id orelse return null; 1553 return self.tab_ids.getIndex(child_id); 1554 } 1555 }; 1556