From 439b0f02b3b0f6a542661104014a9cc3b4ff712a Mon Sep 17 00:00:00 2001 From: SerpentSpirale Date: Wed, 28 Jul 2021 17:20:15 +0200 Subject: [PATCH] Clean up snap/align feature --- .../customcontrols/buttons/ControlButton.java | 53 ++++--------------- 1 file changed, 9 insertions(+), 44 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlButton.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlButton.java index 4cb73e6eb..82e84b96b 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlButton.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlButton.java @@ -315,27 +315,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp setY(currentY); ControlButton nearButton; - /* - for(ControlButton button : ((ControlLayout) getParent()).getButtonChildren()){ - if(button == ControlButton.this){ - continue; - } - if(distanceBetweenViews(ControlButton.this, button) < MIN_DISTANCE){ - if(Math.abs(getTop() - button.getBottom()) < MIN_DISTANCE){ // Bottom snap - currentY = button.getBottom(); - } - //System.out.println(button.getTop() - getBottom()); - if(Math.abs(button.getTop() - getBottom()) < MIN_DISTANCE){ //Top snap - currentY = button.getTop() - getHeight(); - } - if(Math.abs(button.getLeft() - getRight()) < MIN_DISTANCE){ //Left snap - currentX = button.getLeft() - getWidth(); - } - if(Math.abs(getLeft() - button.getRight()) < MIN_DISTANCE){ //Right snap - currentX = button.getRight(); - } - } - */ + for(ControlButton button : ((ControlLayout) getParent()).getButtonChildren()){ if(button == this) continue; if(MathUtils.dist(button.getX() + button.getProperties().getWidth()/2, @@ -353,47 +333,32 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp float left = getX(); float right = getX() + getProperties().getWidth(); - - /* - if(MathUtils.dist(button.getX(), button.getY(), currentX, currentY) < MIN_DISTANCE){ - currentX = button.getX(); - currentY = button.getY(); - } - */ - + * For each axis, we try to snap to the nearest + */ if(Math.abs(top - button_bottom) < MIN_DISTANCE){ // Bottom snap currentY = button_bottom; - } - //System.out.println(button.getTop() - getBottom()); - if(Math.abs(button_top - bottom) < MIN_DISTANCE){ //Top snap + }else if(Math.abs(button_top - bottom) < MIN_DISTANCE){ //Top snap currentY = button_top - getProperties().getHeight(); } if(currentY != getY()){ //If we snapped - if(Math.abs(button_left - left) < MIN_DISTANCE){ //Left align snap + if(Math.abs(button_left - left) < MIN_DISTANCE/2){ //Left align snap currentX = button_left; - - } - if(Math.abs(button_right - right) < MIN_DISTANCE){ //Right align snap + }else if(Math.abs(button_right - right) < MIN_DISTANCE/2){ //Right align snap currentX = button_right - getProperties().getWidth(); - } } if(Math.abs(button_left - right) < MIN_DISTANCE){ //Left snap currentX = button_left - getProperties().getWidth(); - } - if(Math.abs(left - button_right) < MIN_DISTANCE){ //Right snap + }else if(Math.abs(left - button_right) < MIN_DISTANCE){ //Right snap currentX = button_right; } if(currentX != getX()){ - if(Math.abs(button_top - top) < MIN_DISTANCE){ + if(Math.abs(button_top - top) < MIN_DISTANCE/2){ currentY = button_top; - - } - if(Math.abs(button_bottom - bottom) < MIN_DISTANCE){ + }else if(Math.abs(button_bottom - bottom) < MIN_DISTANCE/2){ currentY = button_bottom - getProperties().getHeight(); - } }