Skip to content

Commit

Permalink
Render column titles in the first row of a table (no special styling …
Browse files Browse the repository at this point in the history
…yet)
  • Loading branch information
stackotter committed Oct 13, 2023
1 parent 1a30f34 commit 2d19ca1
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions Sources/SwiftCrossUI/Views/Table.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,33 @@ public struct Table<Row>: View {
_ children: EmptyViewContent.Children,
backend: Backend
) -> Backend.Widget {
return backend.createTable(rows: rows.count, columns: columns.count)
return backend.createTable(rows: rows.count + 1, columns: columns.count)
}

public func update<Backend: AppBackend>(
_ widget: Backend.Widget,
children: EmptyViewContent.Children,
backend: Backend
) {
backend.setRowCount(ofTable: widget, to: rows.count)
backend.setRowCount(ofTable: widget, to: rows.count + 1)
backend.setColumnCount(ofTable: widget, to: columns.count)
for i in 0..<rows.count {
let row = rows[i]
for j in 0..<columns.count {
for (i, column) in columns.enumerated() {
backend.setCell(
at: CellPosition(0, i),
inTable: widget,
to: backend.createTextView(
content: column.title,
shouldWrap: false
)
)
}
for (i, row) in rows.enumerated() {
for (j, column) in columns.enumerated() {
backend.setCell(
at: CellPosition(i, j),
at: CellPosition(i + 1, j),
inTable: widget,
to: backend.createTextView(
content: columns[j].value(row),
content: column.value(row),
shouldWrap: false
)
)
Expand Down

0 comments on commit 2d19ca1

Please sign in to comment.