[Custom controls] Re-calculate position after update button size

This commit is contained in:
khanhduytran0 2020-11-23 14:37:56 +07:00
parent e91f847134
commit 487151c7fb
4 changed files with 27 additions and 13 deletions

View File

@ -76,7 +76,7 @@ public class ControlButton extends Button implements OnLongClickListener, OnTouc
throw new IllegalArgumentException("Field " + ControlData.class.getName() + ".specialButtonListener must be View.OnClickListener or View.OnTouchListener, but is " + properties.specialButtonListener.getClass().getName());
}
setLayoutParams(new FrameLayout.LayoutParams(properties.width, properties.height));
setLayoutParams(new FrameLayout.LayoutParams((int) properties.width, (int) properties.height));
}
@Override
@ -86,23 +86,32 @@ public class ControlButton extends Button implements OnLongClickListener, OnTouc
mProperties.width = params.width;
mProperties.height = params.height;
// Re-calculate position
mProperties.update();
setTranslationX(mProperties.x);
setTranslationY(mProperties.y);
setModified(true);
}
@Override
public void setTranslationX(float x) {
super.setTranslationX(x);
mProperties.x = x;
setModified(true);
if (!mProperties.isDynamicBtn) {
mProperties.x = x;
setModified(true);
}
}
@Override
public void setTranslationY(float y) {
super.setTranslationY(y);
mProperties.y = y;
setModified(true);
if (!mProperties.isDynamicBtn) {
mProperties.y = y;
setModified(true);
}
}
public void updateProperties() {

View File

@ -69,8 +69,8 @@ public class ControlData implements Cloneable
public String name;
public float x;
public float y;
public int width = pixelOf50dp;
public int height = pixelOf50dp;
public float width = pixelOf50dp;
public float height = pixelOf50dp;
public int keycode;
public boolean hidden;
public boolean holdCtrl;
@ -99,7 +99,7 @@ public class ControlData implements Cloneable
this(name, keycode, x, y, isSquare ? pixelOf50dp : pixelOf80dp, isSquare ? pixelOf50dp : pixelOf30dp);
}
public ControlData(String name, int keycode, float x, float y, int width, int height) {
public ControlData(String name, int keycode, float x, float y, float width, float height) {
this.name = name;
this.keycode = keycode;
this.x = x;
@ -121,7 +121,7 @@ public class ControlData implements Cloneable
this(name, keycode, dynamicX, dynamicY, isSquare ? pixelOf50dp : pixelOf80dp, isSquare ? pixelOf50dp : pixelOf30dp);
}
public ControlData(String name, int keycode, String dynamicX, String dynamicY, int width, int height) {
public ControlData(String name, int keycode, String dynamicX, String dynamicY, float width, float height) {
this(name, keycode, 0, 0, width, height);
this.dynamicX = dynamicX;
this.dynamicY = dynamicY;
@ -146,10 +146,10 @@ public class ControlData implements Cloneable
Map<String, String> keyValueMap = new ArrayMap<>();
keyValueMap.put("top", "0");
keyValueMap.put("left", "0");
keyValueMap.put("right", Integer.toString(CallbackBridge.windowWidth - width));
keyValueMap.put("bottom", Integer.toString(CallbackBridge.windowHeight - height));
keyValueMap.put("width", Integer.toString(width));
keyValueMap.put("height", Integer.toString(height));
keyValueMap.put("right", Float.toString(CallbackBridge.windowWidth - width));
keyValueMap.put("bottom", Float.toString(CallbackBridge.windowHeight - height));
keyValueMap.put("width", Float.toString(width));
keyValueMap.put("height", Float.toString(height));
keyValueMap.put("screen_width", Integer.toString(CallbackBridge.windowWidth));
keyValueMap.put("screen_height", Integer.toString(CallbackBridge.windowHeight));
keyValueMap.put("margin", Integer.toString(pixelOf2dp));

View File

@ -8,6 +8,7 @@ import net.kdt.pojavlaunch.*;
import android.support.v7.app.*;
import java.util.*;
import java.io.*;
import net.kdt.pojavlaunch.prefs.*;
public class ControlLayout extends FrameLayout
{
@ -46,6 +47,8 @@ public class ControlLayout extends FrameLayout
for (ControlData button : controlLayout.mControlDataList) {
button.isHideable = button.keycode != ControlData.SPECIALBTN_TOGGLECTRL && button.keycode != ControlData.SPECIALBTN_VIRTUALMOUSE;
button.width = button.width / controlLayout.scaledAt * LauncherPreferences.PREF_BUTTONSIZE;
button.height = button.height / controlLayout.scaledAt * LauncherPreferences.PREF_BUTTONSIZE;
addControlView(button);
}

View File

@ -7,6 +7,7 @@ import org.lwjgl.glfw.*;
public class CustomControls
{
public float scaledAt;
public List<ControlData> mControlDataList;
public CustomControls() {
this(new ArrayList<ControlData>());
@ -14,6 +15,7 @@ public class CustomControls
public CustomControls(List<ControlData> mControlDataList) {
this.mControlDataList = mControlDataList;
this.scaledAt = 1f;
}
// Generate default control