Skip to content

Commit 5284895

Browse files
committed
Units and discrete inputs for continuous number setting values
1 parent 99d1c14 commit 5284895

File tree

6 files changed

+29
-9
lines changed

6 files changed

+29
-9
lines changed

src/main/kotlin/com/lambda/config/settings/numeric/DoubleSetting.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,20 @@ class DoubleSetting(
4646
unit,
4747
visibility
4848
) {
49+
private var valueIndex: Int
50+
get() = ((value - range.start) / step).toInt()
51+
set(index) {
52+
value = (range.start + index * step).coerceIn(range)
53+
}
54+
4955
override fun ImGuiBuilder.buildLayout() {
5056
text(name)
5157

5258
sameLine()
5359
helpMarker(description)
5460

55-
inputDouble("##$name", ::value)
61+
val maxIndex = ((range.endInclusive - range.start) / step).toInt()
62+
slider("##$name", ::valueIndex, 0, maxIndex, super.toString())
5663
}
5764

5865
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {

src/main/kotlin/com/lambda/config/settings/numeric/FloatSetting.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,20 @@ class FloatSetting(
4545
unit,
4646
visibility
4747
) {
48+
private var valueIndex: Int
49+
get() = ((value - range.start) / step).toInt()
50+
set(index) {
51+
value = (range.start + index * step).coerceIn(range)
52+
}
53+
4854
override fun ImGuiBuilder.buildLayout() {
4955
text(name)
5056

5157
sameLine()
5258
helpMarker(description)
5359

54-
inputFloat("##$name", ::value)
60+
val maxIndex = ((range.endInclusive - range.start) / step).toInt()
61+
slider("##$name", ::valueIndex, 0, maxIndex, super.toString())
5562
}
5663

5764
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {

src/main/kotlin/com/lambda/config/settings/numeric/IntegerSetting.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class IntegerSetting(
5151
sameLine()
5252
helpMarker(description)
5353

54-
slider("##$name", ::value, range.start, range.endInclusive, "%d$unit")
54+
slider("##$name", ::value, range.start, range.endInclusive, super.toString())
5555
}
5656

5757
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {

src/main/kotlin/com/lambda/config/settings/numeric/LongSetting.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,20 @@ class LongSetting(
4545
unit,
4646
visibility
4747
) {
48-
var intValue = value.toInt()
48+
private var valueIndex: Int
49+
get() = ((value - range.start) / step).toInt()
50+
set(index) {
51+
value = (range.start + index * step).coerceIn(range)
52+
}
4953

5054
override fun ImGuiBuilder.buildLayout() {
5155
text(name)
5256

5357
sameLine()
5458
helpMarker(description)
5559

56-
inputInt("##$name", ::intValue) { value = it.toLong() }
60+
val maxIndex = ((range.endInclusive - range.start) / step).toInt()
61+
slider("##$name", ::valueIndex, 0, maxIndex, super.toString())
5762
}
5863

5964
override fun CommandBuilder.buildCommand(registry: CommandRegistryAccess) {

src/main/kotlin/com/lambda/interaction/request/rotation/RotationMode.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.lambda.interaction.request.rotation.RotationMode.Lock
2121
import com.lambda.interaction.request.rotation.RotationMode.None
2222
import com.lambda.interaction.request.rotation.RotationMode.Silent
2323
import com.lambda.interaction.request.rotation.RotationMode.Sync
24+
import com.lambda.util.NamedEnum
2425

2526

2627
/**

src/main/kotlin/com/lambda/module/modules/debug/SettingTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ object SettingTest : Module(
5454
private val enumSetting by setting("Enum Setting", ExampleEnum.VALUE_ONE).group(Group.GENERIC)
5555

5656
// Numeric
57-
private val doubleSetting by setting("Double Setting", 3.14159, 0.0..100.0, 0.1).group(Group.NUMERIC)
58-
private val floatSetting by setting("Float Setting", 3.14f, 0.0f..100.0f, 0.1f).group(Group.NUMERIC)
59-
private val integerSetting by setting("Integer Setting", 42, 0..1000).group(Group.NUMERIC)
60-
private val longSetting by setting("Long Setting", 100000L, 0L..1000000L, 1000L).group(Group.NUMERIC)
57+
private val doubleSetting by setting("Double Setting", 3.14159, 0.0..100.0, 0.1, unit = " crumbs").group(Group.NUMERIC)
58+
private val floatSetting by setting("Float Setting", 3.14f, 0.0f..100.0f, 0.1f, unit = " pies").group(Group.NUMERIC)
59+
private val integerSetting by setting("Integer Setting", 42, 0..1000, unit = " apples").group(Group.NUMERIC)
60+
private val longSetting by setting("Long Setting", 100000L, 0L..1000000L, 1000L, unit = " pizzas").group(Group.NUMERIC)
6161

6262
// Collections
6363
private val stringList by setting("String List", listOf("Hello", "World"), listOf("Hello", "World")).group(Group.COLLECTIONS)

0 commit comments

Comments
 (0)