Skip to content

Commit

Permalink
Added sticky headers
Browse files Browse the repository at this point in the history
  • Loading branch information
NickP0is0n committed Jun 28, 2021
1 parent 7cc596c commit 4008b83
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions src/main/kotlin/me/nickp0is0n/easylocalize/ui/MainWindowView.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.nickp0is0n.easylocalize.ui

import androidx.compose.desktop.LocalAppWindow
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
Expand All @@ -12,6 +13,7 @@ import androidx.compose.runtime.snapshots.SnapshotStateList
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Notifier
import me.nickp0is0n.easylocalize.models.LocalizedString
Expand Down Expand Up @@ -56,6 +58,7 @@ class MainWindowView {
}
}

@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun StringList(strings: List<LocalizedString>) {
Column {
Expand All @@ -68,8 +71,19 @@ class MainWindowView {
.padding(start = 10.dp, top = 10.dp, end = 10.dp, bottom = 8.dp)
.border(width = 2.dp, Color(245, 245, 245))
) {
items(strings) {
StringItem(it)
val groupedByMark = strings.groupBy {
it.mark
}
groupedByMark.forEach { (mark, strings) ->
if (mark != null) {
stickyHeader {
StringMarkHeader(mark)
}
}

items(strings) {
StringItem(it)
}
}
}
}
Expand Down Expand Up @@ -108,7 +122,8 @@ class MainWindowView {
this@MainWindowView.stringList[selectedID] = LocalizedString(
currentString.id,
it,
currentString.comment
currentString.comment,
mark = currentString.mark
)
}
} },
Expand All @@ -133,7 +148,8 @@ class MainWindowView {
this@MainWindowView.stringList[selectedID] = LocalizedString(
currentString.id,
currentString.text,
it
it,
mark = currentString.mark
)
}
} },
Expand All @@ -143,6 +159,19 @@ class MainWindowView {
}
}

@Composable
private fun StringMarkHeader(text: String) {
Text(
text = text,
color = Color(30, 144, 255),
fontWeight = FontWeight.Bold,
modifier = Modifier
.background(Color(242, 245, 251))
.padding(8.dp)
.width(284.dp)
)
}

@Composable
private fun retrieveStringList(): List<LocalizedString> {
val parser = LocalizeParser()
Expand Down

0 comments on commit 4008b83

Please sign in to comment.