Fix[controls]: Take into account framework rounding

This commit is contained in:
Mathias-Boulay 2022-11-19 20:45:17 +01:00
parent 641eae051b
commit 012685b3c9

View File

@ -63,10 +63,13 @@ public class EditControlPopup {
if(internalChanges) return; if(internalChanges) return;
internalChanges = true; internalChanges = true;
if(right != (int)safeParseFloat(mWidthEditText.getText().toString())){ int width = (int)(safeParseFloat(mWidthEditText.getText().toString()));
if(width >= 0 && Math.abs(right - width) > 1){
mWidthEditText.setText(String.valueOf(right - left)); mWidthEditText.setText(String.valueOf(right - left));
} }
if(bottom != (int) safeParseFloat(mHeightEditText.getText().toString())){ int height = (int)(safeParseFloat(mHeightEditText.getText().toString()));
if(height >= 0 && Math.abs(bottom - height) > 1){
mHeightEditText.setText(String.valueOf(bottom - top)); mHeightEditText.setText(String.valueOf(bottom - top));
} }
@ -211,7 +214,6 @@ public class EditControlPopup {
mAdapter = new ArrayAdapter<>(mRootView.getContext(), R.layout.item_centered_textview); mAdapter = new ArrayAdapter<>(mRootView.getContext(), R.layout.item_centered_textview);
mSpecialArray = ControlData.buildSpecialButtonArray(); mSpecialArray = ControlData.buildSpecialButtonArray();
for (int i = 0; i < mSpecialArray.length; i++) { for (int i = 0; i < mSpecialArray.length; i++) {
//TODO this will break for sure
mSpecialArray[i] = "SPECIAL_" + mSpecialArray[i]; mSpecialArray[i] = "SPECIAL_" + mSpecialArray[i];
} }
Collections.reverse(Arrays.asList(mSpecialArray)); Collections.reverse(Arrays.asList(mSpecialArray));
@ -386,8 +388,11 @@ public class EditControlPopup {
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
if(internalChanges) return; if(internalChanges) return;
mCurrentlyEditedButton.getProperties().setWidth(safeParseFloat(s.toString())); float width = safeParseFloat(s.toString());
mCurrentlyEditedButton.updateProperties(); if(width >= 0){
mCurrentlyEditedButton.getProperties().setWidth(width);
mCurrentlyEditedButton.updateProperties();
}
} }
}); });
@ -401,8 +406,11 @@ public class EditControlPopup {
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
if(internalChanges) return; if(internalChanges) return;
mCurrentlyEditedButton.getProperties().setHeight(safeParseFloat(s.toString())); float height = safeParseFloat(s.toString());
mCurrentlyEditedButton.updateProperties(); if(height >= 0){
mCurrentlyEditedButton.getProperties().setHeight(height);
mCurrentlyEditedButton.updateProperties();
}
} }
}); });
@ -522,7 +530,7 @@ public class EditControlPopup {
} }
private float safeParseFloat(String string){ private float safeParseFloat(String string){
float out = 10; // 10 px as a fallback float out = -1; // -1
try { try {
out = Float.parseFloat(string); out = Float.parseFloat(string);
}catch (NumberFormatException e){ }catch (NumberFormatException e){