mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
bugfix in the ParseTreeView
This commit is contained in:
@@ -59,8 +59,9 @@ public class ParseTreeView extends View {
|
|||||||
|
|
||||||
private MeasureResult mr = new MeasureResult();
|
private MeasureResult mr = new MeasureResult();
|
||||||
private SparseArray<PointF> coords = new SparseArray<PointF>();
|
private SparseArray<PointF> coords = new SparseArray<PointF>();
|
||||||
|
private PointF zeroPoint = new PointF();
|
||||||
|
|
||||||
private void measureTree(Object o, PointF zeroPoint) {
|
private void measureTree(Object o) {
|
||||||
if (o instanceof Bracket) {
|
if (o instanceof Bracket) {
|
||||||
Bracket bracket = (Bracket) o;
|
Bracket bracket = (Bracket) o;
|
||||||
|
|
||||||
@@ -72,8 +73,7 @@ public class ParseTreeView extends View {
|
|||||||
|
|
||||||
PointF local = coords.get(bracket.fid);
|
PointF local = coords.get(bracket.fid);
|
||||||
if (local == null) {
|
if (local == null) {
|
||||||
if (zeroPoint != null)
|
coords.put(bracket.fid, zeroPoint);
|
||||||
coords.put(bracket.fid, zeroPoint);
|
|
||||||
} else {
|
} else {
|
||||||
localWidth = 0;
|
localWidth = 0;
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ public class ParseTreeView extends View {
|
|||||||
float subHeight = 0.0f;
|
float subHeight = 0.0f;
|
||||||
float nodeCenter = 0.0f;
|
float nodeCenter = 0.0f;
|
||||||
for (int i = 0; i < bracket.children.length; i++) {
|
for (int i = 0; i < bracket.children.length; i++) {
|
||||||
measureTree(bracket.children[i], zeroPoint);
|
measureTree(bracket.children[i]);
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
nodeCenter += (subWidth + mr.nodeCenter) / 2.0;
|
nodeCenter += (subWidth + mr.nodeCenter) / 2.0;
|
||||||
@@ -134,11 +134,12 @@ public class ParseTreeView extends View {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
coords.clear();
|
||||||
|
|
||||||
float width = 0.0f;
|
float width = 0.0f;
|
||||||
float height = 0.0f;
|
float height = 0.0f;
|
||||||
PointF zeroPoint = new PointF();
|
|
||||||
for (int i = 0; i < brackets.length; i++) {
|
for (int i = 0; i < brackets.length; i++) {
|
||||||
measureTree(brackets[i], zeroPoint);
|
measureTree(brackets[i]);
|
||||||
|
|
||||||
width += mr.width;
|
width += mr.width;
|
||||||
if (i < brackets.length - 1) {
|
if (i < brackets.length - 1) {
|
||||||
@@ -154,7 +155,7 @@ public class ParseTreeView extends View {
|
|||||||
int w = getPaddingLeft() + (int) width + getPaddingRight();
|
int w = getPaddingLeft() + (int) width + getPaddingRight();
|
||||||
int h = getPaddingTop() + (int) height + getPaddingBottom();
|
int h = getPaddingTop() + (int) height + getPaddingBottom();
|
||||||
|
|
||||||
scrollRange = w+80;
|
scrollRange = w;
|
||||||
|
|
||||||
int widthReq = MeasureSpec.getSize(widthMeasureSpec);
|
int widthReq = MeasureSpec.getSize(widthMeasureSpec);
|
||||||
if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY ||
|
if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY ||
|
||||||
@@ -196,7 +197,9 @@ public class ParseTreeView extends View {
|
|||||||
float childStartY = y + layerHeight;
|
float childStartY = y + layerHeight;
|
||||||
for (int i = 0; i < bracket.children.length; i++) {
|
for (int i = 0; i < bracket.children.length; i++) {
|
||||||
Object child = bracket.children[i];
|
Object child = bracket.children[i];
|
||||||
measureTree(child, null);
|
SparseArray<PointF> copy = coords.clone();
|
||||||
|
measureTree(child);
|
||||||
|
coords = copy;
|
||||||
float w = mr.width;
|
float w = mr.width;
|
||||||
drawTree(canvas, childStartX, childStartY, bottom, lineStart, child);
|
drawTree(canvas, childStartX, childStartY, bottom, lineStart, child);
|
||||||
childStartX += w + SISTER_SKIP;
|
childStartX += w + SISTER_SKIP;
|
||||||
@@ -223,7 +226,9 @@ public class ParseTreeView extends View {
|
|||||||
for (int i = 0; i < brackets.length; i++) {
|
for (int i = 0; i < brackets.length; i++) {
|
||||||
Object child = brackets[i];
|
Object child = brackets[i];
|
||||||
|
|
||||||
measureTree(child, null);
|
SparseArray<PointF> copy = coords.clone();
|
||||||
|
measureTree(child);
|
||||||
|
coords = copy;
|
||||||
float w = mr.width;
|
float w = mr.width;
|
||||||
drawTree(canvas, startX, getPaddingTop(), getPaddingTop()+mr.height, null, child);
|
drawTree(canvas, startX, getPaddingTop(), getPaddingTop()+mr.height, null, child);
|
||||||
startX += w + SISTER_SKIP;
|
startX += w + SISTER_SKIP;
|
||||||
@@ -242,10 +247,15 @@ public class ParseTreeView extends View {
|
|||||||
float x = ev.getX();
|
float x = ev.getX();
|
||||||
final int deltaX = (int) (lastMotionX - x);
|
final int deltaX = (int) (lastMotionX - x);
|
||||||
lastMotionX = x;
|
lastMotionX = x;
|
||||||
final int offset = computeHorizontalScrollOffset() + deltaX;
|
int offset = computeHorizontalScrollOffset() + deltaX;
|
||||||
final int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent();
|
int range = computeHorizontalScrollRange() - computeHorizontalScrollExtent();
|
||||||
if (range > 0 && offset > 0 && offset < range)
|
if (range > 0) {
|
||||||
|
if (offset < 0)
|
||||||
|
offset = 0;
|
||||||
|
if (offset > range)
|
||||||
|
offset = range;
|
||||||
scrollTo(offset, 0);
|
scrollTo(offset, 0);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user