From 740f4de441af9f303c1a8d8a42f092f597b72b0a Mon Sep 17 00:00:00 2001 From: CAPEL Maxime <83071634+fortyup@users.noreply.github.com> Date: Mon, 15 Jan 2024 10:32:40 +0100 Subject: [PATCH] Alternate color for tables --- src/main/kotlin/main/Detail.kt | 25 +++++++++++++++---------- src/main/kotlin/main/nb_occurrence.kt | 13 +++++++++---- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/main/Detail.kt b/src/main/kotlin/main/Detail.kt index 76f4662..aef5905 100644 --- a/src/main/kotlin/main/Detail.kt +++ b/src/main/kotlin/main/Detail.kt @@ -152,21 +152,26 @@ 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) { val listState = rememberLazyListState() + Box( modifier = Modifier .height(500.dp) .padding(10.dp) ) { - LazyColumn(state = listState, modifier = Modifier.padding(16.dp)) { - item { - headerRow() - } - items(glossary) { word -> - glossaryDataRow(word) + LazyColumn(state = listState, modifier = Modifier.padding(16.dp)) { + item { + headerRow() + } + items(glossary) { 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) diff --git a/src/main/kotlin/main/nb_occurrence.kt b/src/main/kotlin/main/nb_occurrence.kt index 05022e6..e188adb 100644 --- a/src/main/kotlin/main/nb_occurrence.kt +++ b/src/main/kotlin/main/nb_occurrence.kt @@ -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 ) {