Skip to content

Commit dee0a40

Browse files
committed
Handle text overflow
1 parent 5ea1cbb commit dee0a40

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

desktop/src/main/kotlin/com/jdamcd/arrivals/desktop/ArrivalsView.kt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import androidx.compose.ui.Alignment
3030
import androidx.compose.ui.Modifier
3131
import androidx.compose.ui.graphics.Color
3232
import androidx.compose.ui.text.TextStyle
33+
import androidx.compose.ui.text.style.TextOverflow
3334
import androidx.compose.ui.unit.TextUnit
3435
import androidx.compose.ui.unit.dp
3536
import androidx.compose.ui.unit.sp
@@ -72,7 +73,7 @@ private fun Data(state: ArrivalsState.Data, onClickRefresh: () -> Unit) {
7273
.padding(top = 16.dp, bottom = 8.dp, start = 32.dp, end = 32.dp)
7374
) {
7475
val rowHeight = maxHeight / 3
75-
val textSize = (rowHeight * textScale).value.sp
76+
val textSize = (rowHeight * TEXT_SCALE).value.sp
7677

7778
Column(
7879
modifier = Modifier.fillMaxSize(),
@@ -134,7 +135,7 @@ fun Error(message: String) {
134135
.padding(top = 16.dp, bottom = 8.dp, start = 32.dp, end = 32.dp)
135136
) {
136137
val rowHeight = (maxHeight - footerHeight) / 3 // Match text size in Data composable
137-
val textSize = (rowHeight * textScale).value.sp
138+
val textSize = (rowHeight * TEXT_SCALE).value.sp
138139

139140
Column(
140141
modifier = Modifier.fillMaxSize(),
@@ -148,10 +149,9 @@ fun Error(message: String) {
148149
@Composable
149150
fun ArrivalRow(arrival: Arrival, textSize: TextUnit) {
150151
Row(
151-
horizontalArrangement = Arrangement.SpaceBetween,
152152
modifier = Modifier.fillMaxWidth()
153153
) {
154-
LedText(arrival.destination, textSize)
154+
LedText(arrival.destination, textSize, modifier = Modifier.weight(1f))
155155
if (arrival.secondsToStop < 60) {
156156
FlashingLedText(arrival.time, textSize)
157157
} else {
@@ -161,15 +161,22 @@ fun ArrivalRow(arrival: Arrival, textSize: TextUnit) {
161161
}
162162

163163
@Composable
164-
fun LedText(string: String, textSize: TextUnit, color: Color = LedYellow) {
164+
fun LedText(
165+
string: String,
166+
textSize: TextUnit,
167+
color: Color = LedYellow,
168+
modifier: Modifier = Modifier
169+
) {
165170
Text(
166171
text = string,
167172
color = color,
168173
maxLines = 1,
174+
overflow = TextOverflow.Ellipsis,
169175
style = TextStyle(
170176
fontFamily = LurFontFamily,
171177
fontSize = textSize
172-
)
178+
),
179+
modifier = modifier
173180
)
174181
}
175182

@@ -187,5 +194,5 @@ fun FlashingLedText(string: String, textSize: TextUnit) {
187194
LedText(string, textSize, LedYellow.copy(alpha = alpha))
188195
}
189196

190-
private val textScale = 0.6f
197+
private const val TEXT_SCALE = 0.58f
191198
private val footerHeight = 70.dp

0 commit comments

Comments
 (0)