nuhkoca
05/26/2022, 10:17 PMnuhkoca
05/26/2022, 10:18 PMCanvas(
Modifier
.fillMaxWidth()
.height(88.dp)
.padding(horizontal = TRTheme.spacing.default)
) {
var xOffset = 0f
val containerWidth = size.width - (2 * (proportions.size - 1)).dp.toPx()
proportions.forEachIndexed { i, proportion ->
val itemWidth = containerWidth * proportion / 100
drawRoundRect(
color = colors[i],
size = Size(itemWidth, 88.dp.toPx()),
cornerRadius = CornerRadius(4.dp.toPx(), 4.dp.toPx()),
topLeft = Offset(xOffset, 0f)
)
xOffset += itemWidth + 2.dp.toPx()
}
}
nuhkoca
05/26/2022, 10:21 PMlistOf(50, 25, 12.5, 12.5)
and want to show the respective percentage in a tooltip when clicking. E.g. if I click on the first box, I want to see %50
, etcZach Klippenstein (he/him) [MOD]
05/26/2022, 10:29 PMpointerInput
with detectTapGestures
, but it’s probably better to make each rectangle a separate composable and then apply the clickable
modifier to each – that way you get things like accessibility, focus, etc. for free.nuhkoca
05/26/2022, 11:40 PMZach Klippenstein (he/him) [MOD]
05/27/2022, 12:13 AMnuhkoca
05/27/2022, 9:37 AMste
05/27/2022, 1:09 PMRow
and `Spacer`s with their own Modifier.weight
ste
05/27/2022, 1:14 PMRow(
horizontalArrangement = Arrangement.spacedBy(2.dp),
modifier = Modifier
.fillMaxWidth()
.height(88.dp)
.padding(horizontal = TRTheme.spacing.default)
) {
proportions.forEachIndexed { i, proportion ->
Spacer(
modifier = Modifier
.clickable {
println("clicked: $i, $proportion")
}
.background(color = colors[i], shape = RoundedCornerShape(4.dp))
.weight(proportion / 100)
.fillMaxWidth()
)
}
}
nuhkoca
05/27/2022, 2:05 PMste
05/27/2022, 2:17 PMCanvas
. Otherwise, you could create a custom Shape
to draw an arc (but I don't know how that would play with clickable
):
class ArcShape(/* your params */) : Shape {
override fun createOutline(
size: Size,
layoutDirection: LayoutDirection,
density: Density
): Outline {
return Outline.Generic(
path = Path().apply {
addArc(/* stuff */)
}
)
}
}
ste
05/27/2022, 2:18 PMCanvas
approach is betterZach Klippenstein (he/him) [MOD]
05/27/2022, 4:17 PM