mirror of
https://github.com/SimpleMobileTools/Simple-Launcher.git
synced 2025-04-01 12:00:17 +02:00
handle collisions at dragging on the right side too
This commit is contained in:
parent
0d37b4c56f
commit
72debab925
@ -158,11 +158,25 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
|||||||
}
|
}
|
||||||
DRAGGING_RIGHT -> {
|
DRAGGING_RIGHT -> {
|
||||||
val newWidth = event.rawX.toInt() - frameRect.left
|
val newWidth = event.rawX.toInt() - frameRect.left
|
||||||
if (newWidth >= minWidth) {
|
val wantedRight = if (newWidth >= minWidth) {
|
||||||
frameRect.right = event.rawX.toInt()
|
event.rawX.toInt()
|
||||||
} else {
|
} else {
|
||||||
frameRect.right = frameRect.left + minWidth
|
frameRect.left + minWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val closestCellX = roundToClosestMultiplyOfNumber(wantedRight - sideMargins.left, cellWidth) / cellWidth - 1
|
||||||
|
var areAllCellsFree = true
|
||||||
|
for (yCell in cellsRect.top until cellsRect.bottom) {
|
||||||
|
if (occupiedCells.contains(Pair(closestCellX, yCell))) {
|
||||||
|
areAllCellsFree = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (areAllCellsFree && cellsRect.right != closestCellX) {
|
||||||
|
cellsRect.right = closestCellX
|
||||||
|
cellChanged()
|
||||||
|
}
|
||||||
|
frameRect.right = wantedRight
|
||||||
}
|
}
|
||||||
DRAGGING_BOTTOM -> {
|
DRAGGING_BOTTOM -> {
|
||||||
val newHeight = event.rawY.toInt() - frameRect.top
|
val newHeight = event.rawY.toInt() - frameRect.top
|
||||||
@ -204,7 +218,23 @@ class MyAppWidgetResizeFrame(context: Context, attrs: AttributeSet, defStyle: In
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DRAGGING_TOP -> frameRect.top = roundToClosestMultiplyOfNumber(frameRect.top - sideMargins.top, cellHeight) + sideMargins.top
|
DRAGGING_TOP -> frameRect.top = roundToClosestMultiplyOfNumber(frameRect.top - sideMargins.top, cellHeight) + sideMargins.top
|
||||||
DRAGGING_RIGHT -> frameRect.right = roundToClosestMultiplyOfNumber(frameRect.right - sideMargins.left, cellWidth) + sideMargins.left
|
DRAGGING_RIGHT -> {
|
||||||
|
val wantedRight = roundToClosestMultiplyOfNumber(frameRect.right - sideMargins.left, cellWidth)
|
||||||
|
val wantedRightCellX = wantedRight / cellWidth - 1
|
||||||
|
var areAllCellsFree = true
|
||||||
|
for (yCell in cellsRect.top until cellsRect.bottom) {
|
||||||
|
if (occupiedCells.contains(Pair(wantedRightCellX, yCell))) {
|
||||||
|
areAllCellsFree = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (areAllCellsFree) {
|
||||||
|
frameRect.right = wantedRight + sideMargins.left
|
||||||
|
cellsRect.right = wantedRightCellX
|
||||||
|
} else {
|
||||||
|
frameRect.right = (cellsRect.right + 1) * cellWidth + sideMargins.left
|
||||||
|
}
|
||||||
|
}
|
||||||
DRAGGING_BOTTOM -> frameRect.bottom = roundToClosestMultiplyOfNumber(frameRect.bottom - sideMargins.top, cellHeight) + sideMargins.top
|
DRAGGING_BOTTOM -> frameRect.bottom = roundToClosestMultiplyOfNumber(frameRect.bottom - sideMargins.top, cellHeight) + sideMargins.top
|
||||||
}
|
}
|
||||||
redrawFrame()
|
redrawFrame()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user