-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a5b0e14
commit 8e129be
Showing
18 changed files
with
231 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package dev.schlaubi.tonbrett.app.util | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.lazy.grid.GridCells | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalDensity | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
|
||
/** | ||
* Grid-like layout based on [FlowRow]. | ||
* | ||
* @param gridCells descriptor of [GridCells] | ||
* @param items the items inside the grid | ||
* @param horizontalArrangement The horizontal arrangement of the layout's children. | ||
* @param verticalArrangement The vertical arrangement of the layout's virtual rows. | ||
* @param modifier the [Modifier] | ||
* @param itemContent Content for the items | ||
*/ | ||
@OptIn(ExperimentalLayoutApi::class) | ||
@Composable | ||
fun <T> FlowGrid( | ||
gridCells: GridCells, | ||
items: Iterable<T>, | ||
horizontalArrangement: Arrangement.Horizontal = Arrangement.Start, | ||
verticalArrangement: Arrangement.Vertical = Arrangement.Top, | ||
modifier: Modifier = Modifier, | ||
itemContent: @Composable (T) -> Unit | ||
) = BoxWithConstraints(modifier) { | ||
val density = LocalDensity.current | ||
val spacingPx = remember(density) { with(density) { horizontalArrangement.spacing.roundToPx() } } | ||
val widths = | ||
remember(density, constraints) { with(gridCells) { density.calculateCrossAxisCellSizes(constraints.maxWidth, spacingPx) } } | ||
|
||
fun getWidth(index: Int) = with(density) { widths[index % widths.size].toDp() } | ||
|
||
FlowRow( | ||
horizontalArrangement = horizontalArrangement, | ||
verticalArrangement = verticalArrangement, | ||
) { | ||
items.forEachIndexed { index, item -> | ||
val width = getWidth(index) | ||
|
||
BoxWithConstraints(Modifier.width(width)) { | ||
itemContent(item) | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.