Monospaced clock (#1588)

This commit is contained in:
psyvern
2025-08-29 14:21:13 +02:00
committed by GitHub
parent 883ba1181d
commit fd2ca476df
8 changed files with 49 additions and 2 deletions

View File

@@ -27,6 +27,7 @@ import androidx.compose.material.icons.rounded.AutoAwesome
import androidx.compose.material.icons.rounded.BatteryFull
import androidx.compose.material.icons.rounded.ColorLens
import androidx.compose.material.icons.rounded.DarkMode
import androidx.compose.material.icons.rounded.FormatColorText
import androidx.compose.material.icons.rounded.Height
import androidx.compose.material.icons.rounded.HorizontalSplit
import androidx.compose.material.icons.rounded.LightMode
@@ -272,6 +273,7 @@ fun Clock(
val context = LocalContext.current
val clockSettings: ClockWidgetSettings = koinInject()
val showSeconds by clockSettings.showSeconds.collectAsState(initial = false)
val monospaced by clockSettings.monospaced.collectAsState(initial = false)
val useThemeColor by clockSettings.useThemeColor.collectAsState(initial = false)
val timeFormat by clockSettings.timeFormat.collectAsState(null)
@@ -285,6 +287,7 @@ fun Clock(
compact = compact,
showSeconds = showSeconds,
twentyFourHours = isTwentyFourHours,
monospaced = monospaced,
useThemeColor = useThemeColor,
darkColors = darkColors,
style = style,
@@ -295,6 +298,7 @@ fun Clock(
compact = compact,
showSeconds = showSeconds,
twentyFourHours = isTwentyFourHours,
monospaced = monospaced,
useThemeColor = useThemeColor,
darkColors = darkColors,
)
@@ -322,6 +326,7 @@ fun Clock(
compact = compact,
showSeconds = showSeconds,
twentyFourHours = isTwentyFourHours,
monospaced = monospaced,
useThemeColor = useThemeColor,
darkColors = darkColors,
)
@@ -366,6 +371,7 @@ fun ConfigureClockWidgetSheet(
val widgetsOnHome by viewModel.widgetsOnHome.collectAsState()
val alignment by viewModel.alignment.collectAsState()
val showSeconds by viewModel.showSeconds.collectAsState()
val monospaced by viewModel.monospaced.collectAsState()
val timeFormat by viewModel.timeFormat.collectAsState()
val useAccentColor by viewModel.useThemeColor.collectAsState()
val parts by viewModel.parts.collectAsState()
@@ -513,6 +519,20 @@ fun ConfigureClockWidgetSheet(
}
)
}
AnimatedVisibility(
style is ClockWidgetStyle.Digital1 ||
style is ClockWidgetStyle.Digital2 ||
style is ClockWidgetStyle.Orbit
) {
SwitchPreference(
title = stringResource(R.string.preference_clock_widget_monospaced),
icon = Icons.Rounded.FormatColorText,
value = monospaced,
onValueChanged = {
viewModel.setMonospaced(it)
}
)
}
AnimatedVisibility(
style !is ClockWidgetStyle.Analog &&
style !is ClockWidgetStyle.Custom &&

View File

@@ -35,6 +35,7 @@ fun DigitalClock1(
compact: Boolean,
twentyFourHours: Boolean,
showSeconds: Boolean,
monospaced: Boolean,
useThemeColor: Boolean,
darkColors: Boolean,
) {
@@ -75,6 +76,7 @@ fun DigitalClock1(
val textStyle = MaterialTheme.typography.displayLarge.copy(
fontSize = if (verticalLayout) 100.sp else 48.sp,
fontWeight = FontWeight.Black,
fontFeatureSettings = if (monospaced) "tnum" else null,
textAlign = TextAlign.Center,
lineHeight = 0.8.em,
drawStyle = if (style.outlined) Stroke(width = 2.dp.toPixels()) else Fill,

View File

@@ -22,6 +22,7 @@ fun DigitalClock2(
compact: Boolean,
showSeconds: Boolean,
twentyFourHours: Boolean,
monospaced: Boolean,
useThemeColor: Boolean,
darkColors: Boolean,
) {
@@ -64,6 +65,7 @@ fun DigitalClock2(
text = formatter.format(time),
style = MaterialTheme.typography.displaySmall.copy(
fontWeight = FontWeight.Normal,
fontFeatureSettings = if (monospaced) "tnum" else null,
color = color
)
)

View File

@@ -49,6 +49,7 @@ fun OrbitClock(
compact: Boolean,
showSeconds: Boolean,
twentyFourHours: Boolean,
monospaced: Boolean,
useThemeColor: Boolean,
darkColors: Boolean,
) {
@@ -126,8 +127,12 @@ fun OrbitClock(
val contentColor = LocalContentColor.current
val textMeasurer = rememberTextMeasurer()
val minuteStyle = MaterialTheme.typography.labelMedium
val hourStyle = MaterialTheme.typography.labelLarge
val minuteStyle = MaterialTheme.typography.labelMedium.copy(
fontFeatureSettings = if (monospaced) "tnum" else null
)
val hourStyle = MaterialTheme.typography.labelLarge.copy(
fontFeatureSettings = if (monospaced) "tnum" else null
)
val strokeWidth = if (verticalLayout) 2.dp else 1.dp

View File

@@ -57,6 +57,13 @@ class ClockWidgetSettingsScreenVM : ViewModel(), KoinComponent {
settings.setShowSeconds(showSeconds)
}
val monospaced = settings.monospaced
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), false)
fun setMonospaced(monospaced: Boolean) {
settings.setMonospaced(monospaced)
}
val timeFormat = settings.timeFormat
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), TimeFormat.System)