mattinger
03/08/2022, 3:36 PMBoxWithConstraints(
modifier = modifier
.defaultMinSize(RingDefaultMinSize, RingDefaultMinSize)
.aspectRatio(RingAspectRatio)
.padding(RingStrokeWidthOffset),
contentAlignment = Alignment.Center
) {
Canvas(modifier = Modifier.size(constraints.maxWidth.dp, constraints.maxHeight.dp)) {
drawArc(
color = ringColor,
startAngle = rotation.value,
sweepAngle = -1f * sweepAngle.value,
useCenter = false,
style = Stroke(width = RingStrokeWidth.toPx(), cap = StrokeCap.Round)
)
}
}
The problem is that when i don’t specify any size, the Box is filling it’s entire parent. I know it’s due to my use of contraints.maxWidth, but i’m unsure how to properly figure out the size of the canvas based on the constraints.Zach Klippenstein (he/him) [MOD]
03/08/2022, 4:03 PMModifier.size as well as defaultMinSize, which will effectively set the “default” size, which can be overruled by incoming constraints. I'm not sure if either of those will publish intrinsics though, you might need a layout modifier to do that.
But you definitely don't need BoxWithConstraints for this.mattinger
03/08/2022, 4:24 PMmattinger
03/08/2022, 4:24 PMCanvas(
modifier = modifier
.padding(RingStrokeWidthOffset)
.size(RingDefaultMinSize, RingDefaultMinSize)
.aspectRatio(RingAspectRatio)
) {
drawArc(
color = ringColor,
startAngle = rotation.value,
sweepAngle = -1f * sweepAngle.value,
useCenter = false,
style = Stroke(width = RingStrokeWidth.toPx(), cap = StrokeCap.Round)
)
}mattinger
03/08/2022, 4:25 PMmattinger
03/08/2022, 6:57 PMChris Sinco [G]
03/08/2022, 8:56 PMs it turns out, i looked at CircularProgressIndicator, and setting the size and just having a canvas works the way i want it to.Yes, Canvas has a size variable in the drawScope that you should use to base measurements on (which is based on the constraints passed down to it)