mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-08-08 17:18:42 +00:00
some fixes
This commit is contained in:
parent
de027afea8
commit
ebf02257cf
4 changed files with 45 additions and 23 deletions
|
@ -24,13 +24,7 @@ import com.panda3ds.pandroid.view.PandaLayoutController;
|
||||||
|
|
||||||
public class GameActivity extends BaseActivity {
|
public class GameActivity extends BaseActivity {
|
||||||
private final DrawerFragment drawerFragment = new DrawerFragment();
|
private final DrawerFragment drawerFragment = new DrawerFragment();
|
||||||
private final AlberInputListener inputListener = new AlberInputListener(() -> {
|
private final AlberInputListener inputListener = new AlberInputListener(this::onBackPressed);
|
||||||
if (drawerFragment.isOpened()) {
|
|
||||||
drawerFragment.close();
|
|
||||||
} else {
|
|
||||||
drawerFragment.open();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
@ -95,6 +89,8 @@ public class GameActivity extends BaseActivity {
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (drawerFragment.isOpened()) {
|
if (drawerFragment.isOpened()) {
|
||||||
drawerFragment.close();
|
drawerFragment.close();
|
||||||
|
} else {
|
||||||
|
drawerFragment.open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,8 +95,6 @@ public class CodeEditorActivity extends BaseActivity {
|
||||||
} else {
|
} else {
|
||||||
findViewById(R.id.keybar).setVisibility(View.GONE);
|
findViewById(R.id.keybar).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(height + "/" + currentHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupReadOnlyEditor() {
|
private void setupReadOnlyEditor() {
|
||||||
|
@ -131,7 +129,6 @@ public class CodeEditorActivity extends BaseActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||||
System.out.println();
|
|
||||||
if (event.getKeyCode() == KeyEvent.KEYCODE_TAB) {
|
if (event.getKeyCode() == KeyEvent.KEYCODE_TAB) {
|
||||||
if (event.getAction() == KeyEvent.ACTION_UP) {
|
if (event.getAction() == KeyEvent.ACTION_UP) {
|
||||||
editor.insert(TAB_CONTENT);
|
editor.insert(TAB_CONTENT);
|
||||||
|
|
|
@ -9,6 +9,7 @@ import android.graphics.Rect;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.Layout;
|
import android.text.Layout;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
@ -30,6 +31,8 @@ public class BaseEditor extends BasicTextEditor {
|
||||||
private int visibleHeight;
|
private int visibleHeight;
|
||||||
private int contentWidth;
|
private int contentWidth;
|
||||||
private Layout textLayout;
|
private Layout textLayout;
|
||||||
|
private int currentWidth = -1;
|
||||||
|
private int currentHeight = -1;
|
||||||
|
|
||||||
private final char[] textBuffer = new char[1];
|
private final char[] textBuffer = new char[1];
|
||||||
protected final int[] colors = new int[256];
|
protected final int[] colors = new int[256];
|
||||||
|
@ -54,6 +57,15 @@ public class BaseEditor extends BasicTextEditor {
|
||||||
EditorColors.obtainColorScheme(colors, getContext());
|
EditorColors.obtainColorScheme(colors, getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initialize() {
|
||||||
|
super.initialize();
|
||||||
|
getViewTreeObserver().addOnGlobalLayoutListener(() -> {
|
||||||
|
adjustScroll();
|
||||||
|
requireUpdate = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressLint("MissingSuperCall")
|
@SuppressLint("MissingSuperCall")
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas) {
|
public void draw(Canvas canvas) {
|
||||||
|
@ -280,6 +292,16 @@ public class BaseEditor extends BasicTextEditor {
|
||||||
protected void onRefreshColorScheme(byte[] buffer, int index, int length) {
|
protected void onRefreshColorScheme(byte[] buffer, int index, int length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
if (currentWidth != getMeasuredWidth() || currentHeight != getMeasuredHeight()) {
|
||||||
|
currentWidth = getMeasuredWidth();
|
||||||
|
currentHeight = getMeasuredHeight();
|
||||||
|
invalidateAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void invalidateAll() {
|
protected void invalidateAll() {
|
||||||
requireUpdate = true;
|
requireUpdate = true;
|
||||||
invalidate();
|
invalidate();
|
||||||
|
|
|
@ -25,6 +25,7 @@ import com.panda3ds.pandroid.view.SimpleTextWatcher;
|
||||||
|
|
||||||
public class BasicTextEditor extends AppCompatEditText {
|
public class BasicTextEditor extends AppCompatEditText {
|
||||||
private GestureDetector gestureDetector;
|
private GestureDetector gestureDetector;
|
||||||
|
private final Rect visibleRect = new Rect();
|
||||||
|
|
||||||
public BasicTextEditor(@NonNull Context context) {
|
public BasicTextEditor(@NonNull Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
@ -79,7 +80,24 @@ public class BasicTextEditor extends AppCompatEditText {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScroll(int x, int y) {
|
public void setScroll(int x, int y) {
|
||||||
super.scrollTo(x, y);
|
x = Math.max(0, x);
|
||||||
|
y = Math.max(0, y);
|
||||||
|
|
||||||
|
int maxHeight = Math.round(getLineCount() * getLineHeight());
|
||||||
|
getGlobalVisibleRect(visibleRect);
|
||||||
|
maxHeight = Math.max(0, maxHeight - visibleRect.height());
|
||||||
|
|
||||||
|
int maxWidth = (int) getPaint().measureText(getText(), 0, length());
|
||||||
|
maxWidth += getPaddingLeft() + getPaddingRight();
|
||||||
|
|
||||||
|
int scrollX = x - Math.max(Math.min(maxWidth - visibleRect.width(), x), 0);
|
||||||
|
int scrollY = Math.min(maxHeight, y);
|
||||||
|
|
||||||
|
super.scrollTo(scrollX, scrollY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void adjustScroll(){
|
||||||
|
setScroll(getScrollX(), getScrollY());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onTextChanged() {
|
protected void onTextChanged() {
|
||||||
|
@ -96,8 +114,6 @@ public class BasicTextEditor extends AppCompatEditText {
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ScrollGesture implements GestureDetector.OnGestureListener {
|
private class ScrollGesture implements GestureDetector.OnGestureListener {
|
||||||
private final Rect visibleRect = new Rect();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDown(@NonNull MotionEvent e) {
|
public boolean onDown(@NonNull MotionEvent e) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -117,16 +133,7 @@ public class BasicTextEditor extends AppCompatEditText {
|
||||||
public boolean onScroll(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) {
|
public boolean onScroll(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) {
|
||||||
int scrollX = (int) Math.max(0, getScrollX() + distanceX);
|
int scrollX = (int) Math.max(0, getScrollX() + distanceX);
|
||||||
int scrollY = (int) Math.max(0, getScrollY() + distanceY);
|
int scrollY = (int) Math.max(0, getScrollY() + distanceY);
|
||||||
int maxHeight = Math.round(getLineCount() * getLineHeight());
|
setScroll(scrollX, scrollY);
|
||||||
getGlobalVisibleRect(visibleRect);
|
|
||||||
maxHeight = Math.max(0, maxHeight - visibleRect.height());
|
|
||||||
|
|
||||||
int maxWidth = (int) getPaint().measureText(getText(), 0, length());
|
|
||||||
maxWidth += getPaddingLeft() + getPaddingRight();
|
|
||||||
|
|
||||||
scrollX = Math.max(Math.min(maxWidth - visibleRect.width(), scrollX), 0);
|
|
||||||
|
|
||||||
setScroll(scrollX, Math.min(maxHeight, scrollY));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue