Skip to content

Commit

Permalink
renderer/cetz: add node names to cells
Browse files Browse the repository at this point in the history
Initial impl (should have support for custom prefixes later)

Cc #77
  • Loading branch information
PgBiel committed Dec 17, 2023
1 parent 4d0b855 commit c39bd9a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/renderer/cetz.typ
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
// 'cell-box' contains the generated cell content box.
// Requires x, y, width, height in length units.
// x, y are relative to the table's (0pt, 0pt).
#let draw-cetz-cell(cetz-draw, cell-box, x: none, y: none, width: none, height: none) = {
#let draw-cetz-cell(cetz-draw, cell, cell-box, x: none, y: none, width: none, height: none) = {
assert(type(x) == _length-type and type(y) == _length-type, message: "Tablex error: Cell x and y must be lengths. Got: " + repr(x) + ", " + repr(y))
assert(type(width) == _length-type and type(height) == _length-type, message: "Tablex error: Cell width and height must be lengths. Got: " + repr(width) + ", " + repr(height))

Expand All @@ -39,8 +39,11 @@
let top-left = convert-coords-to-cetz-units(x, y)
let bottom-right = convert-coords-to-cetz-units(x + width, y + height)

// TODO: customize prefix, or even allow a function
let node-name = "tbx-" + str(cell.x) + "-" + str(cell.y)

// cetz-draw.rect(top-left, bottom-right, fill: fill, stroke: none)
cetz-draw.content(top-left, bottom-right, cell-box)
cetz-draw.content(top-left, bottom-right, cell-box, name: node-name)
}

// Draws a line in cetz with the specified information.
Expand Down Expand Up @@ -118,7 +121,7 @@
align-default: ctx.align,
fill-default: ctx.fill)

draw-cetz-cell(cell-box, x: x, y: y, width: width, height: height)
draw-cetz-cell(cell, cell-box, x: x, y: y, width: width, height: height)
}

for line in lines {
Expand Down

0 comments on commit c39bd9a

Please sign in to comment.