Skip to content

Commit

Permalink
feature: Initial value for slider widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
lucyydotp committed Nov 2, 2023
1 parent 75cce00 commit c57d0e7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class SliderWidget(
public val min: Int,
public val max: Int,
themed: Themed,
initial: Int = min,
private val updateCallback: ((Int) -> Unit)? = null,
) :
AbstractWidget(0, 0, width, HEIGHT, Component.empty()),
Expand All @@ -36,7 +37,7 @@ public class SliderWidget(
check(max >= min + 2) { "Maximum must be larger than minimum by at least two" }
}

private var currentIndex: Int = 0
private var currentIndex: Int = initial.coerceIn(min, max)
set(value) {
field = value
updateCallback?.invoke(currentValue)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
allprojects {
group = "com.noxcrew.sheeplib"
version = "1.0.2"
version = "1.1.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public class ComponentsDialog(x: Int, y: Int) : Dialog(x, y), Themed by Theme.Ac

StringWidget(Component.literal("Buttons"), font).at(0, 0)

SliderWidget(100, 0, 8, this@ComponentsDialog).atBottom(0)
SliderWidget(100, 0, 8, this@ComponentsDialog, initial = -1).atBottom(0)
}
}

0 comments on commit c57d0e7

Please sign in to comment.