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 errorImportation = mutableStateOf(false)
var exportedSuccessfully = mutableStateOf(false) var exportedSuccessfully = mutableStateOf(false)
// Faire un tableau qui affiche les mots et leur définition
@Composable @Composable
fun glossaryTable(glossary: List<Word>) { fun glossaryTable(glossary: List<Word>) {
val listState = rememberLazyListState() val listState = rememberLazyListState()
Box( Box(
modifier = Modifier modifier = Modifier
.height(500.dp) .height(500.dp)
@ -166,7 +166,12 @@ fun glossaryTable(glossary: List<Word>) {
headerRow() headerRow()
} }
items(glossary) { word -> 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 @Composable
fun glossaryDataRow(word: Word) { fun glossaryDataRow(word: Word, backgroundColor: Color) {
Row( Row(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.background(Color.White) .background(backgroundColor)
.border(1.dp, Color.Black), // Ajouter une bordure à chaque ligne .border(1.dp, Color.Black),
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
val modifier = Modifier.weight(1f).padding(8.dp) val modifier = Modifier.weight(1f).padding(8.dp)

View File

@ -41,8 +41,13 @@ fun parsedWordsTable(
item { item {
parsedWordsHeaderRow() parsedWordsHeaderRow()
} }
items(parsedWords.toList()) { (word, count) -> items(parsedWords.toList()) { word ->
parsedWordsDataRow(word, count) 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 @Composable
fun parsedWordsDataRow(word: String, count: Int) { fun parsedWordsDataRow(word: String, count: Int, backgroundColor: Color) {
Row( Row(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.background(Color.White) .background(backgroundColor)
.border(1.dp, Color.Black), .border(1.dp, Color.Black),
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {