Skip to content

Instantly share code, notes, and snippets.

@StephenVinouze
Last active January 14, 2022 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StephenVinouze/37ad7f77f6fefb7f54f7a2573cb7a08d to your computer and use it in GitHub Desktop.
Save StephenVinouze/37ad7f77f6fefb7f54f7a2573cb7a08d to your computer and use it in GitHub Desktop.
@Composable
fun SegmentedProgressBar(
segmentCount: Int,
modifier: Modifier = Modifier,
spacing: Dp = 0.dp,
angle: Float = 0f,
segmentColor: SegmentColor = SegmentColor(),
) {
val computer = remember { SegmentCoordinatesComputer() }
val spacingPx = LocalDensity.current.run { spacing.toPx() }
Canvas(
modifier = modifier.fillMaxWidth(),
onDraw = {
(0 until segmentCount).forEach { position ->
val segmentCoordinates = computer.segmentCoordinates(
position = position,
segmentCount = segmentCount,
width = size.width,
height = size.height,
spacing = spacingPx,
angle = angle
)
drawSegment(
coordinates = segmentCoordinates,
color = segmentColor
)
}
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment