╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ Markdown.zig ─────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
435 _ = allocator; 436 _ = key; 437 _ = root_focus; 438 } 439 440 pub fn clearGrid(self: *Heading) void { 441 self.text.clearGrid(); 442 self.font_box.clearGrid(); 443 } 444 445 pub fn getGrid(self: Heading) ?Grid { 446 // only the one last built has a grid 447 return self.font_box.getGrid() orelse self.text.getGrid(); 448 } 449 450 pub fn getFocus(self: *Heading) *Focus { 451 return self.focus; 452 } 453 }; 454 455 // a marker column beside a child, so wrapped lines hang under the child's 456 // first line: a list item's bullet, or a quote's bar on every row. 457 pub const Gutter = struct { 458 focus: *Focus, 459 grid: ?Grid, 460 child: wgt.Box(ui.Widget), 461 marker: []const u8, 462 // draw the marker on every row rather than only the first 463 repeat: bool, 464 style: Grid.Style, 465 466 // takes ownership of `child` on success 467 fn init(allocator: std.mem.Allocator, marker: []const u8, repeat: bool, style: Grid.Style, child: wgt.Box(ui.Widget)) !Gutter { 468 return .{ .focus = try Focus.create(allocator, .container), .grid = null, .child = child, .marker = marker, .repeat = repeat, .style = style }; 469 } 470 471 pub fn deinit(self: *Gutter, allocator: std.mem.Allocator) void { 472 self.focus.destroy(allocator); 473 self.clearGrid(); 474 self.child.deinit(allocator); 475 } 476 477 pub fn build(self: *Gutter, allocator: std.mem.Allocator, constraint: layout.Constraint, root_focus: *Focus) !void { 478 self.clearGrid(); 479 self.focus.clear(); 480 const marker_width = try xitui.width.displayWidth(self.marker); 481 if (constraint.max_size.width) |w| if (w <= marker_width) return; 482 if (constraint.max_size.height == 0) return; 483 484 try self.child.build(allocator, .{ 485 .min_size = .{ .width = null, .height = null }, 486 .max_size = .{ .width = if (constraint.max_size.width) |w| w - marker_width else null, .height = constraint.max_size.height }, 487 }, root_focus); 488 const child_grid = self.child.getGrid(); 489 const child_size: layout.Size = if (child_grid) |g| g.size else .{ .width = 0, .height = 0 }; 490 491 var grid = try Grid.init(allocator, .{ .width = marker_width + child_size.width, .height = @max(1, child_size.height) }); 492 errdefer grid.deinit(); 493 for (0..if (self.repeat) grid.size.height else 1) |y| { 494 var x: usize = 0; 495 var utf8 = (try std.unicode.Utf8View.init(self.marker)).iterator(); 496 while (utf8.nextCodepoint()) |rune| { 497 (try grid.cell(x, y)).style = self.style; 498 try grid.setRune(x, y, rune); 499 x += xitui.width.cellWidth(rune); 500 } 501 } 502 if (child_grid) |g| { 503 try grid.drawGrid(g, marker_width, 0); 504 try self.focus.addChild(allocator, self.child.getFocus(), g.size, marker_width, 0); 505 } 506 self.grid = grid; 507 } 508 509 pub fn input(self: *Gutter, allocator: std.mem.Allocator, key: Key, root_focus: *Focus) !void { 510 _ = self; 511 _ = allocator; 512 _ = key; 513 _ = root_focus; 514 } 515 516 pub fn clearGrid(self: *Gutter) void { 517 if (self.grid) |*grid| { 518 grid.deinit(); 519 self.grid = null; 520 } 521 self.child.clearGrid(); 522 } 523 524 pub fn getGrid(self: Gutter) ?Grid { 525 return self.grid; 526 } 527 528 pub fn getFocus(self: *Gutter) *Focus { 529 return self.focus; 530 } 531 }; 532