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 bba7ae296..96ccea612 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 @@ -325,6 +325,25 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp return super.onTouchEvent(event); } + /** + * Passe a series of checks to determine if the ControlButton is available to be snapped on. + * + * @param button + * @return whether or not the button + */ + protected boolean canSnap(ControlButton button){ + float MIN_DISTANCE = Tools.dpToPx(8); + + if(button == this) return false; + if(com.google.android.material.math.MathUtils.dist( + button.getX() + button.getWidth()/2f, + button.getY() + button.getHeight()/2f, + getX() + getWidth()/2f, + getY() + getHeight()/2f) > Math.max(button.getWidth()/2f + getWidth()/2f, button.getHeight()/2f + getHeight()/2f) + MIN_DISTANCE) return false; + + return true; + } + /** * Try to snap, then align to neighboring buttons, given the provided coordinates. * The new position is automatically applied to the View, @@ -335,19 +354,14 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp */ protected void snapAndAlign(float x, float y){ //Time to snap ! - float MIN_DISTANCE = Tools.dpToPx(10); + float MIN_DISTANCE = Tools.dpToPx(8); setX(x); setY(y); for(ControlButton button : ((ControlLayout) getParent()).getButtonChildren()){ //Step 1: Filter unwanted buttons - if(button == this) continue; - if(com.google.android.material.math.MathUtils.dist( - button.getX() + button.getWidth()/2f, - button.getY() + button.getHeight()/2f, - getX() + getWidth()/2f, - getY() + getHeight()/2f) > Math.max(button.getWidth()/2f + getWidth()/2f, button.getHeight()/2f + getHeight()/2f) + MIN_DISTANCE) continue; + if(!canSnap(button)) continue; //Step 2: Get Coordinates float button_top = button.getY(); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlDrawer.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlDrawer.java index 32fbf923f..75332df5e 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlDrawer.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlDrawer.java @@ -101,6 +101,19 @@ public class ControlDrawer extends ControlButton { resizeButtons(); } + /** + * Check whether or not the button passed as a parameter belongs to this drawer. + * + * @param button The button to look for + * @return Whether the button is in the buttons list of the drawer. + */ + public boolean containsChild(ControlButton button){ + for(ControlButton childButton : buttons){ + if (childButton == button) return true; + } + return false; + } + @Override public ControlData preProcessProperties(ControlData properties, ControlLayout layout) { ControlData data = super.preProcessProperties(properties, layout); @@ -129,6 +142,11 @@ public class ControlDrawer extends ControlButton { return super.onTouchEvent(event); } + @Override + protected boolean canSnap(ControlButton button) { + return super.canSnap(button) && !containsChild(button); + } + @Override public void setX(float x) { super.setX(x);