Clean up snap/align feature

This commit is contained in:
SerpentSpirale 2021-07-28 17:20:15 +02:00 committed by ArtDev
parent a5cb8fa67f
commit 439b0f02b3

View File

@ -315,27 +315,7 @@ public class ControlButton extends androidx.appcompat.widget.AppCompatButton imp
setY(currentY); setY(currentY);
ControlButton nearButton; 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()){ for(ControlButton button : ((ControlLayout) getParent()).getButtonChildren()){
if(button == this) continue; if(button == this) continue;
if(MathUtils.dist(button.getX() + button.getProperties().getWidth()/2, 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 left = getX();
float right = getX() + getProperties().getWidth(); float right = getX() + getProperties().getWidth();
/* /*
if(MathUtils.dist(button.getX(), button.getY(), currentX, currentY) < MIN_DISTANCE){ * For each axis, we try to snap to the nearest
currentX = button.getX(); */
currentY = button.getY();
}
*/
if(Math.abs(top - button_bottom) < MIN_DISTANCE){ // Bottom snap if(Math.abs(top - button_bottom) < MIN_DISTANCE){ // Bottom snap
currentY = button_bottom; currentY = button_bottom;
} }else if(Math.abs(button_top - bottom) < MIN_DISTANCE){ //Top snap
//System.out.println(button.getTop() - getBottom());
if(Math.abs(button_top - bottom) < MIN_DISTANCE){ //Top snap
currentY = button_top - getProperties().getHeight(); currentY = button_top - getProperties().getHeight();
} }
if(currentY != getY()){ //If we snapped 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; currentX = button_left;
}else if(Math.abs(button_right - right) < MIN_DISTANCE/2){ //Right align snap
}
if(Math.abs(button_right - right) < MIN_DISTANCE){ //Right align snap
currentX = button_right - getProperties().getWidth(); currentX = button_right - getProperties().getWidth();
} }
} }
if(Math.abs(button_left - right) < MIN_DISTANCE){ //Left snap if(Math.abs(button_left - right) < MIN_DISTANCE){ //Left snap
currentX = button_left - getProperties().getWidth(); currentX = button_left - getProperties().getWidth();
} }else if(Math.abs(left - button_right) < MIN_DISTANCE){ //Right snap
if(Math.abs(left - button_right) < MIN_DISTANCE){ //Right snap
currentX = button_right; currentX = button_right;
} }
if(currentX != getX()){ if(currentX != getX()){
if(Math.abs(button_top - top) < MIN_DISTANCE){ if(Math.abs(button_top - top) < MIN_DISTANCE/2){
currentY = button_top; currentY = button_top;
}else if(Math.abs(button_bottom - bottom) < MIN_DISTANCE/2){
}
if(Math.abs(button_bottom - bottom) < MIN_DISTANCE){
currentY = button_bottom - getProperties().getHeight(); currentY = button_bottom - getProperties().getHeight();
} }
} }