Move SSD view dimension checks to typed Kotlin
ober
9390deb058f66db2c1c3dddd05c55fd6089d406d
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -1178,6 +1178,7 @@ rotationIs90 rotationIs180 rotationIs270 touchMoveExceeded shouldCollectSelectionMatches selectionUsesRawRect selectionHasMatches + viewDimensionsReady previousViewSizeMissing motionActionIsDown motionActionIsMove motionActionIsUp motionActionIsUpOrCancel) (type Int32) @@ -1210,6 +1211,10 @@ (not snapSelectionToCells)) (def (selectionHasMatches (matchingCount : Int32)) : Bool (> matchingCount (int32 0))) + (def (viewDimensionsReady (width : Int32) (height : Int32)) : Bool + (and (> width (int32 0)) (> height (int32 0)))) + (def (previousViewSizeMissing (oldWidth : Int32) (oldHeight : Int32)) : Bool + (not (viewDimensionsReady oldWidth oldHeight))) (def (motionActionMatches (action : Int32) (expected : Int32)) : Bool (= action expected)) (def (motionActionIsDown (action : Int32) (down : Int32)) : Bool @@ -7601,7 +7606,7 @@ " })" "" " override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {" - " if (oldw <= 0 || oldh <= 0 || bitmap == null) {" + " if (previousViewSizeMissing(oldw, oldh) || bitmap == null) {" " fitImage()" " } else {" " clampOffsets()" @@ -7685,7 +7690,7 @@ "" " fun fitImage() {" " val img = bitmap ?: return" - " if (width <= 0 || height <= 0) return" + " if (!viewDimensionsReady(width, height)) return" " val displayWidth = rotatedDisplayWidth(rotationDegrees, img.width, img.height)" " val displayHeight = rotatedDisplayHeight(rotationDegrees, img.width, img.height)" " scale = fitImageScale(width.toFloat(), height.toFloat(), displayWidth.toFloat(), displayHeight.toFloat())" @@ -7722,7 +7727,7 @@ " }" "" " fun centerOnGroup(group: SsdGroup) {" - " if (bitmap == null || width <= 0 || height <= 0) return" + " if (bitmap == null || !viewDimensionsReady(width, height)) return" " scale = focusGroupScale(scale, width.toFloat(), height.toFloat(), group)" " updateMatrix()" " val groupCenter = groupCenterPoint(group)" @@ -7914,7 +7919,7 @@ "" " private fun clampOffsets() {" " val img = bitmap ?: return" - " if (width <= 0 || height <= 0) return" + " if (!viewDimensionsReady(width, height)) return" " val displayWidth = rotatedDisplayWidthFloat(rotationDegrees, img.width, img.height)" " val displayHeight = rotatedDisplayHeightFloat(rotationDegrees, img.width, img.height)" " val scaledWidth = displayWidth * scale"