Skip to content

Commit

Permalink
Make texts selectable for ExpressionsScreen and ConfusionScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
bingzheung committed Jun 27, 2024
1 parent a353288 commit f559c07
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -57,17 +58,19 @@ fun ConfusionScreen(navController: NavHostController) {
val parsed = fetched?.let { Json.decodeFromString<List<ConfusionElement>>(it) }
parsed?.let { entries.value = it }
}
LazyColumn(
verticalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp),
) {
if (entries.value.isNotEmpty()) {
items(entries.value) {
ConfusionElementView(it)
}
} else {
item {
Text(text = "No data")
SelectionContainer {
LazyColumn(
verticalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 8.dp),
) {
if (entries.value.isNotEmpty()) {
items(entries.value) {
ConfusionElementView(it)
}
} else {
item {
Text(text = "No data")
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Cancel
import androidx.compose.material.icons.outlined.CheckCircle
Expand Down Expand Up @@ -152,17 +153,19 @@ fun ExpressionsScreen() {

@Composable
private fun DifferentView(heading: String, lines: List<String>) {
Column(
modifier = Modifier
.padding(vertical = 8.dp)
.fillMaxWidth()
.clip(shape = RoundedCornerShape(size = 8.dp))
.background(color = MaterialTheme.colorScheme.background)
.padding(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(text = heading, fontWeight = FontWeight.SemiBold)
lines.onEach { Text(text = it) }
SelectionContainer {
Column(
modifier = Modifier
.padding(vertical = 8.dp)
.fillMaxWidth()
.clip(shape = RoundedCornerShape(size = 8.dp))
.background(color = MaterialTheme.colorScheme.background)
.padding(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(text = heading, fontWeight = FontWeight.SemiBold)
lines.onEach { Text(text = it) }
}
}
}

Expand All @@ -185,7 +188,9 @@ private fun Expression(heading: String, labels: List<LabelEntry>) {
.padding(8.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
Text(text = heading, fontWeight = FontWeight.SemiBold)
SelectionContainer {
Text(text = heading, fontWeight = FontWeight.SemiBold)
}
labels.onEach {
IconLabel(entry = it)
}
Expand All @@ -205,6 +210,8 @@ private fun IconLabel(entry: LabelEntry) {
verticalAlignment = Alignment.CenterVertically
) {
Icon(imageVector = image, contentDescription = null, modifier = Modifier.size(16.dp))
Text(text = entry.text)
SelectionContainer {
Text(text = entry.text)
}
}
}

0 comments on commit f559c07

Please sign in to comment.