feat: adaptive grid column count driven by window size class (Closes #4) #45
@@ -43,4 +43,35 @@ object UiConstants {
|
|||||||
WindowSizeClass.Expanded -> 24.dp
|
WindowSizeClass.Expanded -> 24.dp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grid configuration driven by [WindowSizeClass].
|
||||||
|
*
|
||||||
|
* Determines total column count and per-item spans so that:
|
||||||
|
* - **Compact** (phone): 2 attribute cards / row, 1 talent card / row
|
||||||
|
* - **Medium** (tablet): 4 attribute cards / row, 2 talent cards / row
|
||||||
|
* - **Expanded** (desktop): 4 attribute cards / row, 2 talent cards / row
|
||||||
|
*/
|
||||||
|
object Grid {
|
||||||
|
/** Total number of grid columns for the given [sizeClass]. */
|
||||||
|
fun totalColumns(sizeClass: WindowSizeClass): Int = when (sizeClass) {
|
||||||
|
WindowSizeClass.Compact -> 2
|
||||||
|
WindowSizeClass.Medium -> 4
|
||||||
|
WindowSizeClass.Expanded -> 4
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Span occupied by a single attribute card. */
|
||||||
|
fun attributeSpan(sizeClass: WindowSizeClass): Int = when (sizeClass) {
|
||||||
|
WindowSizeClass.Compact -> 1
|
||||||
|
WindowSizeClass.Medium -> 1
|
||||||
|
WindowSizeClass.Expanded -> 1
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Span occupied by a single talent card. */
|
||||||
|
fun talentSpan(sizeClass: WindowSizeClass): Int = when (sizeClass) {
|
||||||
|
WindowSizeClass.Compact -> 2
|
||||||
|
WindowSizeClass.Medium -> 2
|
||||||
|
WindowSizeClass.Expanded -> 2
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -28,8 +28,12 @@ fun ColumnScope.AttributesPage(character: ShadowrunCharacter) {
|
|||||||
val gridPadding = UiConstants.Spacing.medium(windowSizeClass)
|
val gridPadding = UiConstants.Spacing.medium(windowSizeClass)
|
||||||
val dividerPadding = UiConstants.Spacing.medium(windowSizeClass)
|
val dividerPadding = UiConstants.Spacing.medium(windowSizeClass)
|
||||||
|
|
||||||
|
val totalColumns = UiConstants.Grid.totalColumns(windowSizeClass)
|
||||||
|
val attributeSpan = UiConstants.Grid.attributeSpan(windowSizeClass)
|
||||||
|
val talentSpan = UiConstants.Grid.talentSpan(windowSizeClass)
|
||||||
|
|
||||||
LazyVerticalGrid(
|
LazyVerticalGrid(
|
||||||
columns = GridCells.Adaptive(minSize = 75.dp),
|
columns = GridCells.Fixed(totalColumns),
|
||||||
state = gridState,
|
state = gridState,
|
||||||
modifier = Modifier.fillMaxSize().padding(gridPadding),
|
modifier = Modifier.fillMaxSize().padding(gridPadding),
|
||||||
horizontalArrangement = Arrangement.spacedBy(gridSpacing),
|
horizontalArrangement = Arrangement.spacedBy(gridSpacing),
|
||||||
@@ -38,7 +42,7 @@ fun ColumnScope.AttributesPage(character: ShadowrunCharacter) {
|
|||||||
items(
|
items(
|
||||||
items = character.attributes.getAllAttributes(),
|
items = character.attributes.getAllAttributes(),
|
||||||
span = {
|
span = {
|
||||||
GridItemSpan(2)
|
GridItemSpan(attributeSpan)
|
||||||
}) { attribute ->
|
}) { attribute ->
|
||||||
Attribute(attribute)
|
Attribute(attribute)
|
||||||
}
|
}
|
||||||
@@ -53,11 +57,11 @@ fun ColumnScope.AttributesPage(character: ShadowrunCharacter) {
|
|||||||
items(
|
items(
|
||||||
items = character.talents.talents,
|
items = character.talents.talents,
|
||||||
span = {
|
span = {
|
||||||
GridItemSpan(3)
|
GridItemSpan(talentSpan)
|
||||||
}
|
}
|
||||||
) { talent ->
|
) { talent ->
|
||||||
Talent(talent, character.attributes)
|
Talent(talent, character.attributes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user