Skip to content

Commit 440eeae

Browse files
committed
feat: Enhance SliderControl with scaling, decimals, and postfix
1 parent 2e10043 commit 440eeae

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ caffeine.version=3.2.2
1616

1717
api.version=1.16.4
1818
core.version=1.18.10
19-
ui.version=1.19.4
19+
ui.version=1.19.5
2020
app.version=1.6.5

ui/src/main/kotlin/dev/paulee/ui/components/Slider.kt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ import androidx.compose.ui.Alignment
1111
import androidx.compose.ui.Modifier
1212
import androidx.compose.ui.text.font.FontWeight
1313
import androidx.compose.ui.unit.dp
14+
import dev.paulee.ui.App
15+
import dev.paulee.ui.Config
1416
import dev.paulee.ui.LocalI18n
17+
import java.util.Locale
1518
import kotlin.math.abs
19+
import kotlin.math.round
1620

1721
@Composable
1822
fun SliderControl(
@@ -22,6 +26,9 @@ fun SliderControl(
2226
minValue: Float,
2327
maxValue: Float,
2428
defaultValue: Float,
29+
scaleFactor: Float = 1f,
30+
decimalCount: Int = 1,
31+
postfix: String = "",
2532
modifier: Modifier = Modifier,
2633
) {
2734
val locale = LocalI18n.current
@@ -61,7 +68,7 @@ fun SliderControl(
6168
border = BorderStroke(1.dp, MaterialTheme.colors.primary.copy(alpha = 0.14f))
6269
) {
6370
Text(
64-
text = formatSliderValue(clampedValue),
71+
text = formatSliderValue(clampedValue, scaleFactor, decimalCount, postfix),
6572
modifier = Modifier.padding(horizontal = 12.dp, vertical = 6.dp),
6673
style = MaterialTheme.typography.caption.copy(fontWeight = FontWeight.SemiBold),
6774
color = MaterialTheme.colors.primary
@@ -92,18 +99,27 @@ fun SliderControl(
9299
horizontalArrangement = Arrangement.SpaceBetween,
93100
) {
94101
Text(
95-
text = formatSliderValue(minValue),
102+
text = formatSliderValue(minValue, scaleFactor, decimalCount, postfix),
96103
style = MaterialTheme.typography.caption,
97104
color = supportingColor
98105
)
99106

100107
Text(
101-
text = formatSliderValue(maxValue),
108+
text = formatSliderValue(maxValue, scaleFactor, decimalCount, postfix),
102109
style = MaterialTheme.typography.caption,
103110
color = supportingColor
104111
)
105112
}
106113
}
107114
}
108115

109-
private fun formatSliderValue(value: Float): String = String.format("%.2f", value)
116+
private fun formatSliderValue(value: Float, scaleFactor: Float, decimalCount: Int, postfix: String): String {
117+
val pattern = buildString {
118+
append("%.")
119+
append(decimalCount.coerceAtLeast(0))
120+
append("f")
121+
}
122+
123+
val numberAsStr = String.format(Locale.forLanguageTag(App.Language.current.tag), pattern, value * scaleFactor)
124+
return if (postfix.isNotBlank()) "$numberAsStr$postfix" else numberAsStr
125+
}

ui/src/main/kotlin/dev/paulee/ui/components/TableView.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import dev.paulee.api.plugin.Tag
4141
import dev.paulee.ui.*
4242
import java.awt.Toolkit
4343
import java.awt.datatransfer.StringSelection
44+
import kotlin.math.round
4445

4546
private val systemClipboard = Toolkit.getDefaultToolkit().systemClipboard
4647

@@ -493,11 +494,14 @@ private fun QuerySettingsPanel(
493494
text = locale["main.query_settings.similarity"],
494495
value = Config.queryEmbSimilarity,
495496
onValueChange = {
496-
Config.queryEmbSimilarity = it
497+
Config.queryEmbSimilarity = round(it * 100) / 100f
497498
},
498499
minValue = 0.5f,
499500
maxValue = 1.0f,
500-
defaultValue = 0.8f
501+
defaultValue = 0.8f,
502+
scaleFactor = 100f,
503+
decimalCount = 0,
504+
postfix = " %"
501505
)
502506
}
503507
}

0 commit comments

Comments
 (0)