Roll back ControlInterface.canSnap

This commit is contained in:
artdeell 2023-04-30 22:10:42 +03:00
parent 8e669caa2e
commit a7809df1a5
2 changed files with 10 additions and 8 deletions

View File

@ -128,6 +128,7 @@ public class ControlDrawer extends ControlButton {
setVisibility(isVisible ? VISIBLE : GONE); setVisibility(isVisible ? VISIBLE : GONE);
} }
@SuppressLint("ClickableViewAccessibility")
@Override @Override
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
if(!getControlLayoutParent().getModifiable()){ if(!getControlLayoutParent().getModifiable()){
@ -163,9 +164,9 @@ public class ControlDrawer extends ControlButton {
} }
@Override @Override
public boolean cantSnap(ControlInterface button) { public boolean canSnap(ControlInterface button) {
boolean result = !super.cantSnap(button); boolean result = super.canSnap(button);
return !result || containsChild(button); return result && !containsChild(button);
} }
//Getters //Getters

View File

@ -184,17 +184,18 @@ public interface ControlInterface extends View.OnLongClickListener {
* @param button The button to check * @param button The button to check
* @return whether or not the button * @return whether or not the button
*/ */
default boolean cantSnap(ControlInterface button){ @SuppressWarnings("BooleanMethodIsAlwaysInverted")
default boolean canSnap(ControlInterface button){
float MIN_DISTANCE = Tools.dpToPx(8); float MIN_DISTANCE = Tools.dpToPx(8);
if(button == this) return true; if(button == this) return false;
return net.kdt.pojavlaunch.utils.MathUtils.dist( return !(net.kdt.pojavlaunch.utils.MathUtils.dist(
button.getControlView().getX() + button.getControlView().getWidth() / 2f, button.getControlView().getX() + button.getControlView().getWidth() / 2f,
button.getControlView().getY() + button.getControlView().getHeight() / 2f, button.getControlView().getY() + button.getControlView().getHeight() / 2f,
getControlView().getX() + getControlView().getWidth() / 2f, getControlView().getX() + getControlView().getWidth() / 2f,
getControlView().getY() + getControlView().getHeight() / 2f) getControlView().getY() + getControlView().getHeight() / 2f)
> Math.max(button.getControlView().getWidth() / 2f + getControlView().getWidth() / 2f, > Math.max(button.getControlView().getWidth() / 2f + getControlView().getWidth() / 2f,
button.getControlView().getHeight() / 2f + getControlView().getHeight() / 2f) + MIN_DISTANCE; button.getControlView().getHeight() / 2f + getControlView().getHeight() / 2f) + MIN_DISTANCE);
} }
/** /**
@ -217,7 +218,7 @@ public interface ControlInterface extends View.OnLongClickListener {
for(ControlInterface button : ((ControlLayout) getControlView().getParent()).getButtonChildren()){ for(ControlInterface button : ((ControlLayout) getControlView().getParent()).getButtonChildren()){
//Step 1: Filter unwanted buttons //Step 1: Filter unwanted buttons
if(cantSnap(button)) continue; if(!canSnap(button)) continue;
//Step 2: Get Coordinates //Step 2: Get Coordinates
float button_top = button.getControlView().getY(); float button_top = button.getControlView().getY();