mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Use steps for keyboard height and offset
This commit is contained in:
parent
49cbcabf5e
commit
21d55993f0
@ -392,7 +392,7 @@ fun<T: Number> SettingSlider(
|
||||
) {
|
||||
SettingSliderForDataStoreItem(
|
||||
title = title,
|
||||
item = useDataStore(setting),
|
||||
item = useDataStore(setting, blocking = true),
|
||||
default = setting.default,
|
||||
range = range,
|
||||
transform = transform,
|
||||
|
@ -51,17 +51,27 @@ fun <T> useDataStoreValueBlocking(v: SettingsKey<T>): T {
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T> useDataStore(key: Preferences.Key<T>, default: T): DataStoreItem<T> {
|
||||
fun <T> useDataStore(key: Preferences.Key<T>, default: T, blocking: Boolean = false): DataStoreItem<T> {
|
||||
val context = LocalContext.current
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
|
||||
val enableSoundFlow: Flow<T> = remember {
|
||||
context.dataStore.data.map {
|
||||
preferences -> preferences[key] ?: default
|
||||
val initialValue = remember {
|
||||
if(blocking) {
|
||||
runBlocking {
|
||||
context.getSetting(key, default)
|
||||
}
|
||||
} else {
|
||||
default
|
||||
}
|
||||
}
|
||||
|
||||
val value = enableSoundFlow.collectAsState(initial = default).value!!
|
||||
val valueFlow: Flow<T> = remember {
|
||||
context.dataStore.data.map { preferences ->
|
||||
preferences[key] ?: default
|
||||
}
|
||||
}
|
||||
|
||||
val value = valueFlow.collectAsState(initial = initialValue).value!!
|
||||
|
||||
val setValue = { newValue: T ->
|
||||
coroutineScope.launch {
|
||||
@ -76,8 +86,8 @@ fun <T> useDataStore(key: Preferences.Key<T>, default: T): DataStoreItem<T> {
|
||||
|
||||
|
||||
@Composable
|
||||
fun <T> useDataStore(key: SettingsKey<T>): DataStoreItem<T> {
|
||||
return useDataStore(key.key, key.default)
|
||||
fun <T> useDataStore(key: SettingsKey<T>, blocking: Boolean = false): DataStoreItem<T> {
|
||||
return useDataStore(key.key, key.default, blocking)
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
@ -227,15 +227,19 @@ fun ThemePicker(onSelected: (ThemeOption) -> Unit) {
|
||||
title = "Keyboard Height",
|
||||
setting = KeyboardHeightMultiplierSetting,
|
||||
range = 0.33f .. 1.75f, transform = { it },
|
||||
indicator = { "${(it * 100.0f).roundToInt()}%" }
|
||||
indicator = { "${(it * 100.0f).roundToInt()}%" },
|
||||
steps = 16
|
||||
)
|
||||
}
|
||||
item(span = { GridItemSpan(maxCurrentLineSpan) }) {
|
||||
SettingSlider(
|
||||
title = "Keyboard Offset",
|
||||
setting = KeyboardBottomOffsetSetting,
|
||||
range = 0.0f .. 128.0f, transform = { it },
|
||||
indicator = { "${String.format("%.1f", it)} dp" }
|
||||
range = 0.0f .. 50.0f,
|
||||
hardRange = 0.0f .. 250.0f,
|
||||
transform = { it },
|
||||
indicator = { "${String.format("%.1f", it)} dp" },
|
||||
steps = 9
|
||||
)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user