From 11866cc021e2e2da25abc17e78bbdbae360340c7 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Sun, 7 Jan 2024 15:57:47 -0300 Subject: [PATCH] use destructuring where possible It is available since Typst 0.2.0 --- src/col-row-size.typ | 43 ++++++++++--------------------------- src/grid.typ | 7 ++---- src/renderer/old.typ | 3 +-- src/renderer/row-groups.typ | 3 +-- 4 files changed, 15 insertions(+), 41 deletions(-) diff --git a/src/col-row-size.typ b/src/col-row-size.typ index 2f28c36..09c09bf 100644 --- a/src/col-row-size.typ +++ b/src/col-row-size.typ @@ -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) } @@ -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) } } @@ -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) } } @@ -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 } } @@ -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 } } @@ -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) @@ -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) diff --git a/src/grid.typ b/src/grid.typ index 5cd1d77..ff1fb36 100644 --- a/src/grid.typ +++ b/src/grid.typ @@ -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 { @@ -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) } diff --git a/src/renderer/old.typ b/src/renderer/old.typ index ed321b1..bef5f4e 100644 --- a/src/renderer/old.typ +++ b/src/renderer/old.typ @@ -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) diff --git a/src/renderer/row-groups.typ b/src/renderer/row-groups.typ index b4565fc..7902fca 100644 --- a/src/renderer/row-groups.typ +++ b/src/renderer/row-groups.typ @@ -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