Skip to content

Commit

Permalink
use destructuring where possible
Browse files Browse the repository at this point in the history
It is available since Typst 0.2.0
  • Loading branch information
PgBiel committed Jan 7, 2024
1 parent 04ed3fa commit 11866cc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 41 deletions.
43 changes: 11 additions & 32 deletions src/col-row-size.typ
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@
gutter = frac-width * (gutter / 1fr)
}

for i-size in frac-tracks {
let i = i-size.at(0)
let size = i-size.at(1)

for (i, size) in frac-tracks {
tracks.at(i) = frac-width * (size / 1fr)
}

Expand All @@ -161,11 +158,8 @@
let cell-cols = range(cell.x, cell.x + cell.colspan)
let last-auto-col = none

for i-col in columns.enumerate().filter(i-col => i-col.at(0) in cell-cols) {
let i = i-col.at(0)
let col = i-col.at(1)

if col == auto {
for (i, col) in columns.enumerate() {
if i in cell-cols and col == auto {
last-auto-col = max-if-not-none(last-auto-col, i)
}
}
Expand All @@ -179,11 +173,8 @@
let cell-rows = range(cell.y, cell.y + cell.rowspan)
let last-auto-row = none

for i-row in rows.enumerate().filter(i-row => i-row.at(0) in cell-rows) {
let i = i-row.at(0)
let row = i-row.at(1)

if row == auto {
for (i, row) in rows.enumerate() {
if i in cell-rows and row == auto {
last-auto-row = max-if-not-none(last-auto-row, i)
}
}
Expand All @@ -199,11 +190,8 @@
let cell-cols = range(cell.x, cell.x + cell.colspan)
let size = 0pt

for i-col in columns.enumerate().filter(i-col => i-col.at(0) in cell-cols) {
let i = i-col.at(0)
let col = i-col.at(1)

if type(col) == _length-type {
for (i, col) in columns.enumerate() {
if i in cell-cols and type(col) == _length-type {
size += col
}
}
Expand All @@ -218,11 +206,8 @@
let cell-rows = range(cell.y, cell.y + cell.rowspan)
let size = 0pt

for i-row in rows.enumerate().filter(i-row => i-row.at(0) in cell-rows) {
let i = i-row.at(0)
let row = i-row.at(1)

if type(row) == _length-type {
for (i, row) in rows.enumerate() {
if i in cell-rows and type(row) == _length-type {
size += row
}
}
Expand All @@ -236,10 +221,7 @@
let auto-sizes = ()
let new-columns = columns

for i-col in columns.enumerate() {
let i = i-col.at(0)
let col = i-col.at(1)

for (i, col) in columns.enumerate() {
if col == auto {
// max cell width
let col-size = grid-get-column(grid, i)
Expand Down Expand Up @@ -451,10 +433,7 @@
let auto-sizes = ()
let new-rows = rows

for i-row in rows.enumerate() {
let i = i-row.at(0)
let row = i-row.at(1)

for (i, row) in rows.enumerate() {
if row == auto {
// max cell height
let row-size = grid-get-row(grid, i)
Expand Down
7 changes: 2 additions & 5 deletions src/grid.typ
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@
let cell-positions = positions-spanned-by(cell, x: this-x, y: this-y, x-limit: x-limit, y-limit: none)

for position in cell-positions {
let px = position.at(0)
let py = position.at(1)
let (px, py) = position
let currently-there = grid-at(grid, px, py)

if currently-there != none {
Expand Down Expand Up @@ -335,9 +334,7 @@
}

// for missing cell positions: add empty cell
for index-item in grid.items.enumerate() {
let index = index-item.at(0)
let item = index-item.at(1)
for (index, item) in grid.items.enumerate() {
if item == none {
grid.items.at(index) = new-empty-cell(grid, index: index)
}
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/old.typ
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@
let group-rows = row-group.rows
let hlines = row-group.hlines
let vlines = row-group.vlines
let start-y = row-group.y-span.at(0)
let end-y = row-group.y-span.at(1)
let (start-y, end-y) = row-group.y-span

locate(loc => {
// let old-page = latest-page-state.at(loc)
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/row-groups.typ
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@
let row-group = this-row-group

// get where the row starts and where it ends
let start-y = row-group.y-span.at(0)
let end-y = row-group.y-span.at(1)
let (start-y, end-y) = row-group.y-span

let next-y = end-y + 1

Expand Down

0 comments on commit 11866cc

Please sign in to comment.