Skip to content

Commit

Permalink
Simpler code for rating display in editor app UI
Browse files Browse the repository at this point in the history
  • Loading branch information
opatry committed May 15, 2024
1 parent 9770a03 commit 6004793
Showing 1 changed file with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,23 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Star
import androidx.compose.material.icons.outlined.StarOutline
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color


@Composable
fun RatingBar(rating: Int, onClick: ((rating: Int) -> Unit)? = null) {
val starOn = remember { Icons.Filled.Star to Color(0xff_ff_dd_33) }
val starOff = remember { Icons.Outlined.StarOutline to MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled) }
Row {
repeat(rating) {
repeat(10) {
val (icon, tint) = if (it < rating) starOn else starOff
Icon(
Icons.Filled.Star,
icon,
null,
Modifier.clickable { onClick?.invoke(if (rating == it + 1) 0 else it + 1) },
tint = Color(0xff_ff_dd_33)
)
}
repeat(10 - rating) {
Icon(
Icons.Outlined.StarOutline,
null,
Modifier.clickable { onClick?.invoke(rating + it + 1) },
tint = MaterialTheme.colors.onSurface.copy(alpha = ContentAlpha.disabled)
tint = tint
)
}
}
Expand Down

0 comments on commit 6004793

Please sign in to comment.