diff options
Diffstat (limited to 'android/app/src/main')
| -rw-r--r-- | android/app/src/main/java/org/terst/doot/widget/data/DataStore.kt | 1 | ||||
| -rw-r--r-- | android/app/src/main/java/org/terst/doot/widget/ui/WidgetTextSize.kt | 38 |
2 files changed, 39 insertions, 0 deletions
diff --git a/android/app/src/main/java/org/terst/doot/widget/data/DataStore.kt b/android/app/src/main/java/org/terst/doot/widget/data/DataStore.kt index d2f2cbb..7153cf8 100644 --- a/android/app/src/main/java/org/terst/doot/widget/data/DataStore.kt +++ b/android/app/src/main/java/org/terst/doot/widget/data/DataStore.kt @@ -17,4 +17,5 @@ object Keys { val NOW = stringPreferencesKey("now") val LAST_UPDATED = longPreferencesKey("last_updated") val IS_REFRESHING = booleanPreferencesKey("is_refreshing") + val TEXT_SIZE = stringPreferencesKey("text_size") } diff --git a/android/app/src/main/java/org/terst/doot/widget/ui/WidgetTextSize.kt b/android/app/src/main/java/org/terst/doot/widget/ui/WidgetTextSize.kt new file mode 100644 index 0000000..e44b983 --- /dev/null +++ b/android/app/src/main/java/org/terst/doot/widget/ui/WidgetTextSize.kt @@ -0,0 +1,38 @@ +package org.terst.doot.widget.ui + +import androidx.compose.ui.unit.TextUnit +import androidx.compose.ui.unit.sp +import androidx.glance.text.FontWeight + +/** + * Header and content are independent knobs (currently seeded with the same + * numbers) so either can be retuned later without affecting the other. + * SMALL reproduces the widget's original, pre-setting appearance exactly. + */ +enum class WidgetTextSize( + val headerScale: Float, + val headerWeightBump: Int, + val contentScale: Float, + val contentWeightBump: Int +) { + SMALL(1.0f, 0, 1.0f, 0), + NORMAL(1.15f, 1, 1.15f, 1), + LARGE(1.3f, 2, 1.3f, 2); + + companion object { + fun fromPref(raw: String?): WidgetTextSize = + raw?.let { name -> entries.find { it.name == name } } ?: NORMAL + } +} + +private val weightLadder = listOf(FontWeight.Normal, FontWeight.Medium, FontWeight.Bold) + +private fun bumpWeight(base: FontWeight, bump: Int): FontWeight { + val idx = weightLadder.indexOf(base).coerceAtLeast(0) + return weightLadder[(idx + bump).coerceAtMost(weightLadder.lastIndex)] +} + +fun WidgetTextSize.scaledHeaderSize(baseSp: Int): TextUnit = (baseSp * headerScale).sp +fun WidgetTextSize.scaledHeaderWeight(base: FontWeight): FontWeight = bumpWeight(base, headerWeightBump) +fun WidgetTextSize.scaledContentSize(baseSp: Int): TextUnit = (baseSp * contentScale).sp +fun WidgetTextSize.scaledContentWeight(base: FontWeight): FontWeight = bumpWeight(base, contentWeightBump) |
