From 83e0030b1c44e22f81bcaa0fa32ed86e4d0109a3 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Thu, 4 Aug 2022 02:50:07 +0200 Subject: [PATCH] Changed scale slider to dropdown --- src/main/kotlin/app/theme/Theme.kt | 2 +- .../app/ui/dialogs/settings/SettingsDialog.kt | 33 +++++++++++-------- .../app/{ => ui/dropdowns}/DropDownOption.kt | 2 +- .../kotlin/app/ui/dropdowns/ScaleDropDown.kt | 3 ++ 4 files changed, 24 insertions(+), 16 deletions(-) rename src/main/kotlin/app/{ => ui/dropdowns}/DropDownOption.kt (69%) create mode 100644 src/main/kotlin/app/ui/dropdowns/ScaleDropDown.kt diff --git a/src/main/kotlin/app/theme/Theme.kt b/src/main/kotlin/app/theme/Theme.kt index 797e4a4..a6761ec 100644 --- a/src/main/kotlin/app/theme/Theme.kt +++ b/src/main/kotlin/app/theme/Theme.kt @@ -6,7 +6,7 @@ import androidx.compose.material.Colors import androidx.compose.material.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.Color -import app.DropDownOption +import app.ui.dropdowns.DropDownOption private val defaultAppTheme: ColorsScheme = darkBlueTheme private var appTheme: ColorsScheme = defaultAppTheme diff --git a/src/main/kotlin/app/ui/dialogs/settings/SettingsDialog.kt b/src/main/kotlin/app/ui/dialogs/settings/SettingsDialog.kt index 6506599..26a7b45 100644 --- a/src/main/kotlin/app/ui/dialogs/settings/SettingsDialog.kt +++ b/src/main/kotlin/app/ui/dialogs/settings/SettingsDialog.kt @@ -11,7 +11,7 @@ import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import app.DropDownOption +import app.ui.dropdowns.DropDownOption import app.theme.* import app.ui.components.AdjustableOutlinedTextField import app.ui.components.ScrollableColumn @@ -21,10 +21,10 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.launch import androidx.compose.runtime.getValue import androidx.compose.runtime.setValue -import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalDensity import app.extensions.handMouseClickable import app.preferences.DEFAULT_UI_SCALE +import app.ui.dropdowns.ScaleDropDown import app.viewmodels.SettingsViewModel enum class SettingsCategory(val displayName: String) { @@ -184,30 +184,35 @@ fun UiSettings(settingsViewModel: SettingsViewModel) { } val density = LocalDensity.current.density + val options = listOf( + ScaleDropDown(1f, "100%"), + ScaleDropDown(1.5f, "150%"), + ScaleDropDown(2f, "200%"), + ScaleDropDown(2.5f, "250%"), + ScaleDropDown(3f, "300%"), + ) + var scaleValue by remember { val savedScaleUi = settingsViewModel.scaleUi val scaleUi = if (savedScaleUi == DEFAULT_UI_SCALE) { density } else { savedScaleUi - } * 100 + } - mutableStateOf(scaleUi) + val matchingOption = options.firstOrNull { it.value == scaleUi } ?: options.first() + mutableStateOf(matchingOption) } - SettingSlider( + SettingDropDown( title = "Scale", subtitle = "Adapt the size the UI to your preferred scale", - value = scaleValue, - onValueChanged = { newValue -> + dropDownOptions = options, + currentOption = scaleValue, + onOptionSelected = { newValue -> scaleValue = newValue - }, - onValueChangeFinished = { - settingsViewModel.scaleUi = scaleValue / 100 - }, - steps = 5, - minValue = 100f, - maxValue = 300f, + settingsViewModel.scaleUi = newValue.value + } ) } diff --git a/src/main/kotlin/app/DropDownOption.kt b/src/main/kotlin/app/ui/dropdowns/DropDownOption.kt similarity index 69% rename from src/main/kotlin/app/DropDownOption.kt rename to src/main/kotlin/app/ui/dropdowns/DropDownOption.kt index 3b6767b..ec63c0d 100644 --- a/src/main/kotlin/app/DropDownOption.kt +++ b/src/main/kotlin/app/ui/dropdowns/DropDownOption.kt @@ -1,4 +1,4 @@ -package app +package app.ui.dropdowns interface DropDownOption { val optionName: String diff --git a/src/main/kotlin/app/ui/dropdowns/ScaleDropDown.kt b/src/main/kotlin/app/ui/dropdowns/ScaleDropDown.kt new file mode 100644 index 0000000..f9f778b --- /dev/null +++ b/src/main/kotlin/app/ui/dropdowns/ScaleDropDown.kt @@ -0,0 +1,3 @@ +package app.ui.dropdowns + +class ScaleDropDown(val value: Float, override val optionName: String) : DropDownOption \ No newline at end of file