Created
June 29, 2021 23:08
-
-
Save sergenes/dfc6138d6cd521fc7d1a8999d4dbd391 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
data class StudyCardDeckModel( | |
var current: Int, | |
val dataSource: List<StudyCard>, | |
val visible: Int = 3, | |
val screenWidth: Int, | |
val screenHeight: Int | |
) { | |
private val colors = arrayOf(primaryColor, secondaryColor, tertiaryColor) | |
val count = dataSource.size | |
val visibleCards: Int = StrictMath.min(visible, dataSource.size - current) | |
fun cardVisible(visibleIndex: Int) = dataSource[dataSourceIndex(visibleIndex)] | |
private fun dataSourceIndex(visibleIndex: Int): Int { | |
return current + visibleIndex | |
} | |
fun colorForIndex(visibleIndex: Int): Color { | |
val index = dataSourceIndex(visibleIndex) | |
val colorIndex = index % colors.size | |
return colors[colorIndex] | |
} | |
@Composable | |
fun cardWidthPx(): Float { | |
return with(LocalDensity.current) { cardWidth.toPx() } | |
} | |
@Composable | |
fun cardHeightPx(): Float { | |
return with(LocalDensity.current) { cardHeight.toPx() } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment