Tables.swift 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. extension BackendFeatures {
  2. /// Backend methods for tables.
  3. ///
  4. /// These are used by ``Table``.
  5. @MainActor
  6. public protocol Tables: Core {
  7. /// The default height of a table row excluding cell padding. This is a
  8. /// recommendation by the backend that SwiftCrossUI won't necessarily
  9. /// follow in all cases.
  10. var defaultTableRowContentHeight: Int { get }
  11. /// The default vertical padding to apply to table cells.
  12. ///
  13. /// This is the amount of padding added above and below each cell, not the
  14. /// total amount added along the vertical axis. It's a recommendation by the
  15. /// backend that SwiftCrossUI won't necessarily follow in all cases.
  16. var defaultTableCellVerticalPadding: Int { get }
  17. /// Creates an empty table.
  18. ///
  19. /// - Returns: A table.
  20. func createTable() -> Widget
  21. /// Sets the number of rows of a table.
  22. ///
  23. /// Existing rows outside of the new bounds should be deleted.
  24. ///
  25. /// - Parameters:
  26. /// - table: The table to set the row count of.
  27. /// - rows: The number of rows.
  28. func setRowCount(ofTable table: Widget, to rows: Int)
  29. /// Sets the labels of a table's columns. Also sets the number of columns of
  30. /// the table to the number of labels provided.
  31. ///
  32. /// - Parameters:
  33. /// - table: The table to set the column labels of.
  34. /// - labels: The column labels to set.
  35. /// - environment: The current environment.
  36. func setColumnLabels(
  37. ofTable table: Widget,
  38. to labels: [String],
  39. environment: EnvironmentValues
  40. )
  41. /// Sets the contents of the table as a flat array of cells in order of and
  42. /// grouped by row. Also sets the height of each row's content.
  43. ///
  44. /// A nested array would have significantly more overhead, especially for
  45. /// large arrays.
  46. ///
  47. /// - Parameters:
  48. /// - table: The table.
  49. /// - cells: The widgets to fill the table with.
  50. /// - rowHeights: The heights of the table's rows.
  51. func setCells(
  52. ofTable table: Widget,
  53. to cells: [Widget],
  54. withRowHeights rowHeights: [Int]
  55. )
  56. }
  57. }