override fun measure()

in richtext-ui/src/commonMain/kotlin/com/halilibo/richtext/ui/TableMeasurer.kt [58:91]


  override fun measure(
    rowMeasurables: List<List<Measurable>>,
    constraints: Constraints,
  ): Measurements {
    check(constraints.hasBoundedWidth) { "Uniform tables must have bounded width" }

    val columns = rowMeasurables[0].size
    // Divide the width by the number of columns, then leave room for the padding.
    val cellSpacingWidth = cellSpacing * (columns + 1)
    val cellWidth = maxOf(
      (constraints.maxWidth - cellSpacingWidth) / columns,
      MinCellWidth.toFloat()
    )
    // TODO Handle bounded height constraints.
    //val cellSpacingHeight = cellSpacing * (rowMeasurables.size + 1)
    // val cellMaxHeight = if (!constraints.hasBoundedHeight) {
    //   Float.MAX_VALUE
    // } else {
    //   // Divide the height by the number of rows, then leave room for the padding.
    //   (constraints.maxHeight - cellSpacingHeight) / rowMeasurables.size
    // }
    val cellConstraints = Constraints(maxWidth = cellWidth.roundToInt()).constrain(constraints)

    val rowPlaceables = rowMeasurables.map { cellMeasurables ->
      cellMeasurables.map { cell ->
        cell.measure(cellConstraints)
      }
    }
    val rowHeights = rowPlaceables.map { row -> row.maxByOrNull { it.height }!!.height }
    val columnWidths = List(columns) { cellWidth.roundToInt() }

    return Measurements(rowPlaceables, columnWidths, rowHeights)
  }
}