Fix inconsistent OSC button movements when using the arrow buttons

A combination of factors caused inconsistent button movements when using the arrow buttons to move it, namely floating point approximation and the round down performed when snapping a button to the grid. Sometimes the layman solution is the best one: adding/subtracting one to the move amount depending on the direction ensures that the button always ends up on a grid line.
This commit is contained in:
lynxnb 2023-03-31 01:45:48 +02:00 committed by Billy Laws
parent 1d6b075d5c
commit 37a2a2fbad
3 changed files with 15 additions and 7 deletions

View File

@ -209,23 +209,34 @@ abstract class OnScreenButton(
saveConfigValues()
}
/**
* Returns the amount to move the button when the user presses an arrow key
* @param gridOffset The offset to apply to the grid size so that the button always ends up on a grid line
*/
private fun getMoveAmount(gridOffset : Int) : Int {
return if (editInfo.snapToGrid)
editInfo.gridSize + gridOffset
else
OnScreenEditInfo.ArrowKeyMoveAmount
}
override fun moveUp() {
move(currentX, currentY - editInfo.arrowKeyMoveAmount)
move(currentX, currentY - getMoveAmount(-1))
saveConfigValues()
}
override fun moveDown() {
move(currentX, currentY + editInfo.arrowKeyMoveAmount)
move(currentX, currentY + getMoveAmount(+1))
saveConfigValues()
}
override fun moveLeft() {
move(currentX - editInfo.arrowKeyMoveAmount, currentY)
move(currentX - getMoveAmount(-1), currentY)
saveConfigValues()
}
override fun moveRight() {
move(currentX + editInfo.arrowKeyMoveAmount, currentY)
move(currentX + getMoveAmount(+1), currentY)
saveConfigValues()
}

View File

@ -373,7 +373,6 @@ class OnScreenControllerView @JvmOverloads constructor(context : Context, attrs
fun setSnapToGrid(snap : Boolean) {
editInfo.snapToGrid = snap
editInfo.arrowKeyMoveAmount = if (snap) editInfo.gridSize else OnScreenEditInfo.ArrowKeyMoveAmount
}
fun resetButton() {

View File

@ -40,8 +40,6 @@ class OnScreenEditInfo {
var gridSize : Int = GridSize
var arrowKeyMoveAmount : Int = ArrowKeyMoveAmount
companion object {
/**
* The size of the grid, calculated from the value of 8dp