Alternate color for tables

main
CAPEL Maxime 2024-01-15 10:32:40 +01:00
parent 04ed49e551
commit 740f4de441
2 changed files with 24 additions and 14 deletions

View File

@ -152,10 +152,10 @@ var importedSuccessfully = mutableStateOf(false)
var errorImportation = mutableStateOf(false)
var exportedSuccessfully = mutableStateOf(false)
// Faire un tableau qui affiche les mots et leur définition
@Composable
fun glossaryTable(glossary: List<Word>) {
val listState = rememberLazyListState()
Box(
modifier = Modifier
.height(500.dp)
@ -166,7 +166,12 @@ fun glossaryTable(glossary: List<Word>) {
headerRow()
}
items(glossary) { word ->
glossaryDataRow(word)
val backgroundColor = if (glossary.indexOf(word) % 2 == 0) {
Color.White
} else {
Color.LightGray
}
glossaryDataRow(word = word, backgroundColor = backgroundColor)
}
}
}
@ -212,12 +217,12 @@ fun cellContent(text: String, modifier: Modifier = Modifier) {
}
@Composable
fun glossaryDataRow(word: Word) {
fun glossaryDataRow(word: Word, backgroundColor: Color) {
Row(
modifier = Modifier
.fillMaxWidth()
.background(Color.White)
.border(1.dp, Color.Black), // Ajouter une bordure à chaque ligne
.background(backgroundColor)
.border(1.dp, Color.Black),
verticalAlignment = Alignment.CenterVertically
) {
val modifier = Modifier.weight(1f).padding(8.dp)

View File

@ -41,8 +41,13 @@ fun parsedWordsTable(
item {
parsedWordsHeaderRow()
}
items(parsedWords.toList()) { (word, count) ->
parsedWordsDataRow(word, count)
items(parsedWords.toList()) { word ->
val backgroundColor = if (parsedWords.toList().indexOf(word) % 2 == 0) {
Color.White
} else {
Color.LightGray
}
parsedWordsDataRow(word = word.first, count = word.second, backgroundColor = backgroundColor)
}
}
@ -98,11 +103,11 @@ fun parsedWordsHeaderRow() {
}
@Composable
fun parsedWordsDataRow(word: String, count: Int) {
fun parsedWordsDataRow(word: String, count: Int, backgroundColor: Color) {
Row(
modifier = Modifier
.fillMaxWidth()
.background(Color.White)
.background(backgroundColor)
.border(1.dp, Color.Black),
verticalAlignment = Alignment.CenterVertically
) {