Created
January 29, 2024 00:48
-
-
Save milksense/6b1dd996cb588239c1944c3df69cb652 to your computer and use it in GitHub Desktop.
Multi State Progress Indicator | M3
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
MultiStateProgressIndicator( | |
Modifier | |
.padding(top = 18.dp) | |
.padding(horizontal = 8.dp) | |
.fillMaxWidth() | |
.height(16.dp), 15, 60, 25 | |
) | |
@Composable | |
private fun MultiStateProgressIndicator( | |
modifier: Modifier, | |
application: Long, | |
others: Long, | |
total: Long, | |
) { | |
val bgApp = MaterialTheme.colorScheme.primary | |
val bgTotal = MaterialTheme.colorScheme.compositeSurfaceElevation(4.dp) | |
val bgOthers = MaterialTheme.colorScheme.compositeSurfaceElevation(8.dp).blendWith(bgApp, 0.2f) | |
Canvas(modifier) { | |
val width = size.width | |
val height = size.height | |
// calc | |
val othersPrcnt = others / total.toFloat() | |
val appPrcnt = application / total.toFloat() | |
val othersOffsetEnd = width * othersPrcnt | |
val appOffsetEnd = othersOffsetEnd + (width * appPrcnt) | |
// OTHERS - APPLICATION - REST | |
drawLine(bgTotal, Offset(0f, 0f), Offset(width, 0f), height, StrokeCap.Round) | |
drawLine(bgOthers, Offset(0f, 0f), Offset(othersOffsetEnd, 0f), height, StrokeCap.Round) | |
drawLine(bgApp, Offset(othersOffsetEnd, 0f), Offset(appOffsetEnd, 0f), height, StrokeCap.Round) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment