Skip to content

Instantly share code, notes, and snippets.

@fvilarino
Created December 4, 2022 01:17
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 fvilarino/15986314b49a46b56051e360751e366e to your computer and use it in GitHub Desktop.
Save fvilarino/15986314b49a46b56051e360751e366e to your computer and use it in GitHub Desktop.
Segmented Progress - Background
private fun DrawScope.drawSegments(
color: Color,
segmentHeight: Float,
segments: Int,
segmentGap: Float,
) {
// 1
val width = size.width
val start = 0f
val end = width
val gaps = (segments - 1) * segmentGap
val segmentWidth = (width - gaps) / segments
// 2
repeat(segments) { index ->
// 3
val offset = index * (segmentWidth + segmentGap)
val segmentStart = start + offset
// 4
val segmentEnd = (offset + segmentWidth).coerceAtMost(end)
// 5
drawRect(
color,
Offset(segmentStart, 0f),
Size(segmentEnd - segmentStart, segmentHeight)
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment