feat: added ValueBox composable for easier readability and more consistent UI

This commit is contained in:
Alex Schwemler 2026-05-06 20:41:45 +02:00
parent 939fc56ae8
commit 8e201a6986

View file

@ -124,6 +124,27 @@ fun calculateSteps(
val totalSteps = ((max - min) / stepSize).roundToInt() val totalSteps = ((max - min) / stepSize).roundToInt()
return (totalSteps - 1).coerceAtLeast(0) return (totalSteps - 1).coerceAtLeast(0)
} }
@Composable
fun ValueBox(
text: String,
modifier: Modifier = Modifier
) {
Box(
modifier = modifier,
contentAlignment = Alignment.CenterEnd
) {
Text(
text = text,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.primary,
fontWeight = FontWeight.SemiBold,
)
}
}
@Composable @Composable
private fun PlaybackSettingsSection( private fun PlaybackSettingsSection(
isTablet: Boolean, isTablet: Boolean,
@ -321,12 +342,7 @@ private fun PlaybackSettingsSection(
color = MaterialTheme.colorScheme.onSurfaceVariant, color = MaterialTheme.colorScheme.onSurfaceVariant,
) )
} }
Text( ValueBox(text = timeoutLabel, modifier = Modifier.wrapContentWidth())
text = timeoutLabel,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.primary,
fontWeight = FontWeight.SemiBold,
)
} }
var sliderValue by remember(timeoutSec) { mutableFloatStateOf(timeoutSec.toFloat()) } var sliderValue by remember(timeoutSec) { mutableFloatStateOf(timeoutSec.toFloat()) }
var lastHapticStep by remember(timeoutSec) { mutableStateOf(timeoutSec) } var lastHapticStep by remember(timeoutSec) { mutableStateOf(timeoutSec) }
@ -592,15 +608,9 @@ private fun PlaybackSettingsSection(
color = MaterialTheme.colorScheme.onSurfaceVariant, color = MaterialTheme.colorScheme.onSurfaceVariant,
) )
} }
Text( ValueBox(text = stringResource(
text = stringResource( Res.string.settings_playback_threshold_percentage_value,
Res.string.settings_playback_threshold_percentage_value, formatStep(thresholdPercent)), modifier = Modifier.wrapContentWidth())
thresholdPercent.toInt(),
),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.primary,
fontWeight = FontWeight.SemiBold,
)
} }
var sliderVal by remember(thresholdPercent) { mutableFloatStateOf(thresholdPercent) } var sliderVal by remember(thresholdPercent) { mutableFloatStateOf(thresholdPercent) }
var lastHapticPercent by remember(thresholdPercent) { mutableStateOf(thresholdPercent.toInt()) } var lastHapticPercent by remember(thresholdPercent) { mutableStateOf(thresholdPercent.toInt()) }
@ -651,8 +661,7 @@ private fun PlaybackSettingsSection(
color = MaterialTheme.colorScheme.onSurfaceVariant, color = MaterialTheme.colorScheme.onSurfaceVariant,
) )
} }
Text( ValueBox(text = stringResource(
text = stringResource(
Res.string.settings_playback_minutes_value, Res.string.settings_playback_minutes_value,
thresholdMinutes.toInt(), thresholdMinutes.toInt(),
), ),