Travis Griggs
09/18/2023, 11:13 PM@Composable
fun ColorWheel(initialHue: Double, onSelect: UnaryAction<Double?>, modifier: Modifier = Modifier) {
// ...some initial variables setup
Canvas(modifier = modifier.pointerInput(Unit) {
detectTapGestures { tap ->
val r = (minOf(size.width, size.height)).float.half - WheelInset
val c = Offset(size.width.float.half, r + WheelInset)
val fromCenter = tap - c
val rFraction = fromCenter.r / r
// ... figure out what it's closest to...
onSelect(targetHue)
}
}) {
val r = (minOf(size.width, size.height)).half - WheelInset
val c = Offset(size.width.half, r + WheelInset)
val outerBox = Rect(c, r)
val innerBox = Rect(c, r.half)
// .. bunch of drawing code
}
}
One of the things that bothers me here, is that I end up recomputing the center/radius of the "area" in both the pointerInput code as well as the DrawScope code. It seems that if you're doing a custom view with custom interactions, you have to duplicate bounds relative geometry code between the two scopes. Is there a better way that I'm missing?Luke
09/19/2023, 1:34 PMBoxWithConstraints
would work?