martmists
11/28/2024, 3:36 PM+---------+--------+
| 20 ms | ABCDEF |
+---------+--------+
+---------+-------------+
| 1200 ms | GHIJKLMNOPQ |
| | RSTUV |
+---------+-------------+
In traditional CSS I'd use a grid for this, but this isn't really a thing in Compose. I could add an onGloballyPositioned modifier to each element in each Row{} to determine their width and get the maximum and then apply that to all, but I feel like there should be an easier way to do something this common, but I haven't found a clean way to do it.Stylianos Gakis
11/28/2024, 3:45 PMmartmists
11/28/2024, 4:49 PMYour graphic here does not exactly have equal widths on your two items.Might be a font issue? On my screen, both elements on the left have the exact same width, matching the largest size required to fit all elements.
martmists
11/28/2024, 4:51 PMStylianos Gakis
11/28/2024, 4:52 PMStylianos Gakis
11/28/2024, 4:52 PMmartmists
11/28/2024, 4:52 PMStylianos Gakis
11/28/2024, 4:52 PMmartmists
11/28/2024, 4:53 PMStylianos Gakis
11/28/2024, 4:53 PMmartmists
11/28/2024, 4:53 PMmartmists
11/28/2024, 4:54 PMStylianos Gakis
11/28/2024, 4:55 PMStylianos Gakis
11/28/2024, 4:56 PMmartmists
11/28/2024, 4:56 PMmartmists
11/28/2024, 4:58 PMStylianos Gakis
11/28/2024, 5:00 PMrememberTextMeasurer
, try to measure all the texts that will go to your first column. And take the max width from all of them.
Then assign a fixed width to all the items in that first column. And the right item can get a weight(1f) I suppose to fill the rest
val texts List<String>...
val textStyle = tableStyle.textStyle
val textMeasurer = rememberTextMeasurer(cacheSize = texts.size)
val fixedWidth = texts.maxOf { text ->
textMeasurer.measure(
text = text,
style = textStyle,
softWrap = false,
maxLines = 1,
).size.width
}
Row {
Box(Modifier.width(fixedWidth)) { // left content here }
Box(Modifier.weight(1f, true) { // right content here }
}
Stylianos Gakis
11/28/2024, 5:02 PM