improve widget alignment

This commit is contained in:
True Zhuanjia committed 2026-05-21 20:31:54 +08:00
1 parent 5f4fe6a040
commit c36051fffc
2 files changed
+36 -9

No files matched your search

@@ -138,11 +138,14 @@
*/ */
horizontalGuideline.backgroundColor = [UIColor blueColor]; // change horizontal guideline back to blue if it doesn't line up with one of the on screen buttons horizontalGuideline.backgroundColor = [UIColor blueColor]; // change horizontal guideline back to blue if it doesn't line up with one of the on screen buttons
OnScreenWidgetView.isHorizontallyAligned = false;
for (CALayer *button in self.OSCButtonLayerPool) { // horizontal guideline position check for (CALayer *button in self.OSCButtonLayerPool) { // horizontal guideline position check
if ((layerBeingDragged != button) && !button.isHidden) { if ((layerBeingDragged != button) && !button.isHidden) {
if ((horizontalGuideline.center.y < button.position.y + 1) && if ((horizontalGuideline.center.y < button.position.y + 2) &&
(horizontalGuideline.center.y > button.position.y - 1)) { (horizontalGuideline.center.y > button.position.y - 2)) {
horizontalGuideline.backgroundColor = [UIColor yellowColor]; horizontalGuideline.backgroundColor = [UIColor yellowColor];
OnScreenWidgetView.isHorizontallyAligned = true;
OnScreenWidgetView.alignedY = button.position.y;
break; break;
} }
} }
@@ -151,32 +154,38 @@
if ([view isKindOfClass:[OnScreenWidgetView class]] && view != widget) { if ([view isKindOfClass:[OnScreenWidgetView class]] && view != widget) {
OnScreenWidgetView* otherWidget = (OnScreenWidgetView *) view; OnScreenWidgetView* otherWidget = (OnScreenWidgetView *) view;
if(widget.isFolder && widget.bulkMoveEnabled && [widget.sequenceSet containsObject:@(otherWidget.sequence)]) break; if(widget.isFolder && widget.bulkMoveEnabled && [widget.sequenceSet containsObject:@(otherWidget.sequence)]) break;
if((horizontalGuideline.center.y < view.center.y + 1) && (horizontalGuideline.center.y > view.center.y - 1)) { if((horizontalGuideline.center.y < view.center.y + 2) && (horizontalGuideline.center.y > view.center.y - 2)) {
horizontalGuideline.backgroundColor = [UIColor yellowColor]; horizontalGuideline.backgroundColor = [UIColor yellowColor];
OnScreenWidgetView.isHorizontallyAligned = true;
OnScreenWidgetView.alignedY = view.center.y;
break; break;
} }
} }
} }
verticalGuideline.backgroundColor = [UIColor blueColor]; // change vertical guideline back to blue if it doesn't line up with one of the on screen buttons verticalGuideline.backgroundColor = [UIColor blueColor]; // change vertical guideline back to blue if it doesn't line up with one of the on screen buttons
OnScreenWidgetView.isVerticallyAligned = false;
for (CALayer *button in self.OSCButtonLayerPool) { // vertical guideline position check for (CALayer *button in self.OSCButtonLayerPool) { // vertical guideline position check
if ((layerBeingDragged != button) && !button.isHidden) { if ((layerBeingDragged != button) && !button.isHidden) {
if ((verticalGuideline.center.x < button.position.x + 1) && if ((verticalGuideline.center.x < button.position.x + 2) &&
(verticalGuideline.center.x > button.position.x - 1)) { (verticalGuideline.center.x > button.position.x - 2)) {
verticalGuideline.backgroundColor = [UIColor yellowColor]; verticalGuideline.backgroundColor = [UIColor yellowColor];
OnScreenWidgetView.isVerticallyAligned = true;
OnScreenWidgetView.alignedX = button.position.x;
break; break;
} }
} }
} }
for(UIView* view in self.layoutToolVC.view.subviews){ for(UIView* view in self.layoutToolVC.view.subviews){
if ([view isKindOfClass:[OnScreenWidgetView class]] && view != widget) { if ([view isKindOfClass:[OnScreenWidgetView class]] && view != widget) {
if ((verticalGuideline.center.x < view.center.x + 1) && (verticalGuideline.center.x > view.center.x - 1)) { if ((verticalGuideline.center.x < view.center.x + 2) && (verticalGuideline.center.x > view.center.x - 2)) {
verticalGuideline.backgroundColor = [UIColor yellowColor]; verticalGuideline.backgroundColor = [UIColor yellowColor];
OnScreenWidgetView.isVerticallyAligned = true;
OnScreenWidgetView.alignedX = view.center.x;
break; break;
} }
} }
} }
} }
- (void) updateGuidelinesForLegacyOnScreenControls{ - (void) updateGuidelinesForLegacyOnScreenControls{
+20 -2
View File
@@ -3248,6 +3248,14 @@ import ObjectiveC.runtime
} }
} }
if OnScreenWidgetView.isVerticallyAligned {
self.center = CGPoint(x:OnScreenWidgetView.alignedX, y:self.center.y)
OnScreenWidgetView.isVerticallyAligned = false
}
if OnScreenWidgetView.isHorizontallyAligned {
self.center = CGPoint(x:self.center.x, y:OnScreenWidgetView.alignedY)
OnScreenWidgetView.isHorizontallyAligned = false
}
} }
@objc public func setAutoTapIntervalByText(str: String){ @objc public func setAutoTapIntervalByText(str: String){
@@ -4039,6 +4047,10 @@ import ObjectiveC.runtime
v.layer.shadowRadius = 2 v.layer.shadowRadius = 2
return v return v
}() }()
@objc static var isHorizontallyAligned:Bool = false
@objc static var alignedX:CGFloat = 0
@objc static var isVerticallyAligned:Bool = false
@objc static var alignedY:CGFloat = 0
private static func updateStreamViewGuidelines(for widget:OnScreenWidgetView){ private static func updateStreamViewGuidelines(for widget:OnScreenWidgetView){
if !widget.moveableButtonLongPressed() {return} if !widget.moveableButtonLongPressed() {return}
@@ -4055,9 +4067,15 @@ import ObjectiveC.runtime
var verticallyAligned = false var verticallyAligned = false
widget.forEachWidget{ otherWidget in widget.forEachWidget{ otherWidget in
guard otherWidget != widget else {return} guard otherWidget != widget else {return}
if widget.isFolder, widget.bulkMoveEnabled, widget.sequenceSet.contains(otherWidget.sequence) {return} if widget.isFolder, widget.bulkMoveEnabled, widget.sequenceSet.contains(otherWidget.sequence) {return}
verticallyAligned = verticallyAligned ? verticallyAligned : widget.center.x > otherWidget.center.x-1 && widget.center.x < otherWidget.center.x+1 verticallyAligned = verticallyAligned ? verticallyAligned : widget.center.x > otherWidget.center.x-2 && widget.center.x < otherWidget.center.x+2
horizontallyAligned = horizontallyAligned ? horizontallyAligned : widget.center.y > otherWidget.center.y-1 && widget.center.y < otherWidget.center.y+1 OnScreenWidgetView.isVerticallyAligned = verticallyAligned;
if verticallyAligned {OnScreenWidgetView.alignedX = otherWidget.center.x}
horizontallyAligned = horizontallyAligned ? horizontallyAligned : widget.center.y > otherWidget.center.y-2 && widget.center.y < otherWidget.center.y+2
OnScreenWidgetView.isHorizontallyAligned = horizontallyAligned;
if horizontallyAligned {OnScreenWidgetView.alignedY = otherWidget.center.y}
} }
horizontalGuideline.backgroundColor = horizontallyAligned ? .yellow : .blue horizontalGuideline.backgroundColor = horizontallyAligned ? .yellow : .blue
verticalGuideline.backgroundColor = verticallyAligned ? .yellow : .blue verticalGuideline.backgroundColor = verticallyAligned ? .yellow : .blue