Created
December 4, 2022 01:17
-
-
Save fvilarino/15986314b49a46b56051e360751e366e to your computer and use it in GitHub Desktop.
Segmented Progress - Background
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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