From f22d05a34e1a18d765219427acf936e2f4e777ad Mon Sep 17 00:00:00 2001 From: TrueZhuanjia Date: Sun, 20 Jul 2025 16:22:33 +0800 Subject: [PATCH] - prevent onscreen widget moved out of superView bounds --- VoidLink/Input/OnScreenWidgetView.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/VoidLink/Input/OnScreenWidgetView.swift b/VoidLink/Input/OnScreenWidgetView.swift index c3e34d09..2cea3abc 100644 --- a/VoidLink/Input/OnScreenWidgetView.swift +++ b/VoidLink/Input/OnScreenWidgetView.swift @@ -1134,10 +1134,15 @@ import UIKit let currentLocation: CGPoint if OnScreenWidgetView.editMode {currentLocation = touch.location(in: superview)} else {currentLocation = touch.location(in: self)} + + let offsetX = currentLocation.x - latestTouchLocation.x; + let offsetY = currentLocation.y - latestTouchLocation.y; + + let outOfBoundsX = center.x+offsetX > (self.superview?.bounds.width)! || center.x+offsetX < 0 + let outOfBoundsY = center.y+offsetY > (self.superview?.bounds.height)! || center.y+offsetY < 0 + + center = CGPoint(x: outOfBoundsX ? center.x : center.x+offsetX, y: outOfBoundsY ? center.y : center.y+offsetY) - let offsetX = currentLocation.x - latestTouchLocation.x - let offsetY = currentLocation.y - latestTouchLocation.y - center = CGPoint(x: center.x + offsetX, y: center.y + offsetY) latestTouchLocation = currentLocation // center = currentLocation; //NSLog("x coord: %f, y coord: %f", self.frame.origin.x, self.frame.origin.y)