Nicolai
08/14/2024, 4:47 PMNicolai
08/14/2024, 4:47 PM@Composable
fun CircularProgressBar(
modifier: Modifier = Modifier,
percentage: Float,
backgroundColor: Color,
ellipseColor: Color,
brush: Brush,
strokeWidth: Dp
) {
val startAngle = 180f
Canvas(
modifier = modifier
.size(width = 216.dp, height = 216.dp)
.padding(10.dp)
) {
drawArc(
color = backgroundColor,
startAngle,
180f,
false,
style = Stroke(strokeWidth.toPx(), cap = StrokeCap.Round),
size = Size(size.width, size.height)
)
drawArc(
brush = brush,
startAngle,
180f,
false,
style = Stroke(strokeWidth.toPx(), cap = StrokeCap.Round),
size = Size(size.width, size.height)
)
val values = listOf(0, 55, 125, 180)
for (i in values) {
val angleInDegrees = (startAngle / 2) + i.toDouble()
val radius = (size.height / 2)
val x = -(radius * sin(Math.toRadians(angleInDegrees))).toFloat() + (size.width / 2)
val y = (radius * cos(Math.toRadians(angleInDegrees))).toFloat() + (size.height / 2)
drawCircle(
color = ellipseColor,
radius = 5f,
center = Offset(x, y)
)
}
}
}
Nicolai
08/14/2024, 4:57 PM@Composable
fun CircularProgressBar(
modifier: Modifier = Modifier,
percentage: Float,
backgroundColor: Color,
ellipseColor: Color,
brush: Brush,
strokeWidth: Dp
) {
val startAngle = 180f
Box(
Modifier
.fillMaxSize()
.drawBehind {
drawArc(
color = backgroundColor,
startAngle,
180f,
false,
style = Stroke(strokeWidth.toPx(), cap = StrokeCap.Round),
size = Size(size.width, size.height * 2),
)
drawArc(
brush = brush,
startAngle,
180f,
false,
style = Stroke(strokeWidth.toPx(), cap = StrokeCap.Round),
size = Size(size.width, size.height * 2),
)
val values = listOf(0, 55, 125, 180)
for (i in values) {
val angleInDegrees = (startAngle / 2) + i.toDouble()
val radius = (size.height)
val x =
(radius * sin(Math.toRadians(angleInDegrees))).toFloat() + (size.width / 2)
val y =
(radius * cos(Math.toRadians(angleInDegrees))).toFloat() + (size.height)
drawCircle(
color = ellipseColor,
radius = 5f,
center = Offset(x, y)
)
}
}
)
}
Kirill Grouchnikov
08/14/2024, 5:18 PM