ソースを参照

fix: 优化字重挑选

HapeLee 3 ヶ月 前
親
コミット
7f9b044b95

+ 22 - 22
app/src/main/java/io/legado/app/ui/book/read/sheet/TextTitleSheet.kt

@@ -53,6 +53,7 @@ import io.legado.app.ui.theme.LegadoTheme
 import io.legado.app.ui.widget.components.AppSlider
 import io.legado.app.ui.widget.components.AppSlider
 import io.legado.app.ui.widget.components.AppTextField
 import io.legado.app.ui.widget.components.AppTextField
 import io.legado.app.ui.widget.components.SectionTitle
 import io.legado.app.ui.widget.components.SectionTitle
+import io.legado.app.ui.widget.components.ValueStepper
 import io.legado.app.ui.widget.components.alert.AppAlertDialog
 import io.legado.app.ui.widget.components.alert.AppAlertDialog
 import io.legado.app.ui.widget.components.card.NormalCard
 import io.legado.app.ui.widget.components.card.NormalCard
 import io.legado.app.ui.widget.components.dialog.ColorPickerSheet
 import io.legado.app.ui.widget.components.dialog.ColorPickerSheet
@@ -643,14 +644,6 @@ private fun FontWeightSetting(
         )
         )
     }
     }
     val weightEntries = stringArrayResource(R.array.text_font_weight)
     val weightEntries = stringArrayResource(R.array.text_font_weight)
-    val presetValue = when (value) {
-        2 -> 2
-        1 -> 1
-        0 -> 0
-        in 100..350 -> 2
-        in 650..900 -> 1
-        else -> 0
-    }
 
 
     Column {
     Column {
         Row(
         Row(
@@ -660,7 +653,7 @@ private fun FontWeightSetting(
             Box(modifier = Modifier.weight(1f)) {
             Box(modifier = Modifier.weight(1f)) {
                 TinyDropdownSettingItem(
                 TinyDropdownSettingItem(
                     title = stringResource(R.string.font_weight_text),
                     title = stringResource(R.string.font_weight_text),
-                    selectedValue = presetValue.toString(),
+                    selectedValue = value.toString(),
                     displayEntries = arrayOf(
                     displayEntries = arrayOf(
                         weightEntries[2],
                         weightEntries[2],
                         weightEntries[0],
                         weightEntries[0],
@@ -709,22 +702,29 @@ private fun FontWeightSetting(
                 containerColor = LegadoTheme.colorScheme.surfaceContainerLow,
                 containerColor = LegadoTheme.colorScheme.surfaceContainerLow,
                 cornerRadius = 12.dp,
                 cornerRadius = 12.dp,
             ) {
             ) {
-                Box(
+                ValueStepper(
+                    value = sliderValue,
+                    displayValue = sliderValue,
+                    valueRange = 100f..900f,
+                    onValueChange = {
+                        sliderValue = it
+                        onValueChange(it.toInt())
+                    },
                     modifier = Modifier
                     modifier = Modifier
                         .fillMaxSize()
                         .fillMaxSize()
                         .padding(horizontal = 12.dp),
                         .padding(horizontal = 12.dp),
-                    contentAlignment = Alignment.Center,
-                ) {
-                    AppSlider(
-                        value = sliderValue,
-                        onValueChange = { sliderValue = it },
-                        onValueChangeFinished = {
-                            onValueChange(sliderValue.toInt())
-                        },
-                        valueRange = 100f..900f,
-                        modifier = Modifier.fillMaxWidth(),
-                    )
-                }
+                    content = {
+                        AppSlider(
+                            value = sliderValue,
+                            onValueChange = { sliderValue = it },
+                            onValueChangeFinished = {
+                                onValueChange(sliderValue.toInt())
+                            },
+                            valueRange = 100f..900f,
+                            modifier = Modifier.weight(1f),
+                        )
+                    },
+                )
             }
             }
         }
         }
     }
     }

+ 17 - 11
app/src/main/java/io/legado/app/ui/widget/components/ValueStepper.kt

@@ -2,6 +2,7 @@ package io.legado.app.ui.widget.components
 
 
 import androidx.compose.foundation.layout.Arrangement
 import androidx.compose.foundation.layout.Arrangement
 import androidx.compose.foundation.layout.Row
 import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.RowScope
 import androidx.compose.material.icons.Icons
 import androidx.compose.material.icons.Icons
 import androidx.compose.material.icons.filled.Add
 import androidx.compose.material.icons.filled.Add
 import androidx.compose.material.icons.filled.Remove
 import androidx.compose.material.icons.filled.Remove
@@ -24,6 +25,7 @@ fun ValueStepper(
     stepSize: Float = 1f,
     stepSize: Float = 1f,
     showDecimal: Boolean = false,
     showDecimal: Boolean = false,
     valueFormat: ((Float) -> String)? = null,
     valueFormat: ((Float) -> String)? = null,
+    content: (@Composable RowScope.() -> Unit)? = null,
 ) {
 ) {
     Row(
     Row(
         modifier = modifier,
         modifier = modifier,
@@ -38,19 +40,23 @@ fun ValueStepper(
             enabled = enabled,
             enabled = enabled,
             icon = Icons.Default.Remove,
             icon = Icons.Default.Remove,
         )
         )
-        val displayText = valueFormat?.invoke(displayValue) ?: if (showDecimal) {
-            displayValue.toString()
+        if (content != null) {
+            content()
         } else {
         } else {
-            displayValue.toInt().toString()
+            val displayText = valueFormat?.invoke(displayValue) ?: if (showDecimal) {
+                displayValue.toString()
+            } else {
+                displayValue.toInt().toString()
+            }
+            TextCard(
+                cornerRadius = 8.dp,
+                horizontalPadding = 8.dp,
+                verticalPadding = 4.dp,
+                text = displayText,
+                backgroundColor = LegadoTheme.colorScheme.surfaceContainerHigh,
+                contentColor = LegadoTheme.colorScheme.onSurface
+            )
         }
         }
-        TextCard(
-            cornerRadius = 8.dp,
-            horizontalPadding = 8.dp,
-            verticalPadding = 4.dp,
-            text = displayText,
-            backgroundColor = LegadoTheme.colorScheme.surfaceContainerHigh,
-            contentColor = LegadoTheme.colorScheme.onSurface
-        )
         SmallOutlinedButton(
         SmallOutlinedButton(
             onClick = {
             onClick = {
                 val newValue = (value + stepSize).coerceIn(valueRange)
                 val newValue = (value + stepSize).coerceIn(valueRange)