Skip to content

Commit 114ab86

Browse files
committed
horizontal scrolling, rep speed
1 parent ee5d270 commit 114ab86

File tree

9 files changed

+71
-34
lines changed

9 files changed

+71
-34
lines changed

AndroidIDE/Highlight.pde

+6-3
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,18 @@ static class SyntaxHighlight {
5858
g.textSize(sz);
5959
int sel = sel(poi);
6060
float chw = g.textWidth('H');
61-
float ty = y + (MOBILE? sz*.333 : 0);
6261
for(int ln = max(0, floor((sy-y)/sz)); ln < min(lns.length, floor((ey-y)/sz+1)); ln++) {
6362
float cx = x;
6463
String cln = lns[ln];
6564
for (int i = 0; i < cln.length(); i++) {
6665
char cc = cln.charAt(i);
6766
int pos = i + lnstarts[ln];
6867
g.fill(cs[pos]);
69-
g.text(cc, cx, ty + ln*sz);
68+
g.text(cc, cx, y + ln*sz);
7069
int markcol = mark[pos];
7170
if (markcol != 0) {
7271
g.fill(markcol);
73-
g.text("_", cx, ty + ln*sz);
72+
g.text("_", cx, y + ln*sz);
7473
}
7574
if (sel == pos) {
7675
g.stroke(th.pair);
@@ -194,3 +193,7 @@ class Theme {
194193
int[] dfn = {#AA77BB, #EEBB44, #CC7799, #CCDD00, #B63CDA};
195194

196195
}
196+
197+
static float textY(float y, float sz) {
198+
return y + (MOBILE? sz*.333 : 0);
199+
}

AndroidIDE/Keyboard.pde

+5-4
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ class Keyboard extends Drawable {
6767
Action a = findAction();
6868
if (a != null) {
6969
a.k.redraw(a);
70-
if (millis() - mouseStart > 200) {
71-
if (a.rep && frameCount%2==1) a.call();
70+
int time = millis() - mouseStart;
71+
if (time > 200) {
72+
if (a.rep!=-1 && frameCount%a.rep == 0) a.call();
7273
}
7374
}
7475
}
@@ -180,7 +181,7 @@ class Key extends Drawable {
180181

181182
class Action {
182183
final String chr, spec, type, gotof;
183-
final boolean rep;
184+
final int rep;
184185
final Keyboard b;
185186
final Key k;
186187
Action (JSONObject o, Keyboard b, Key k) {
@@ -191,7 +192,7 @@ class Action {
191192

192193
spec = o.getString("spec");
193194
gotof = o.getString("goto");
194-
rep = o.hasKey("rep")? o.getBoolean("rep") : false;
195+
rep = o.hasKey("rep")? o.getInt("rep") : -1;
195196
this.b = b;
196197
this.k = k;
197198
}

AndroidIDE/ROText.pde

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
class ROText extends Drawable {
2-
float tsz;
2+
float tsz, chw;
33
ROText(int x, int y, int w, int h) {
44
super(x, y, w, h);
55
s = new ArrayList();
6-
tsz = min(width, height)/20;
6+
setSize(min(width, height)/20);
77
}
8-
int yoff = 0; // scroll
8+
int xoff = 0; // scroll
9+
int yoff = 0;
910
int border = 10;
1011
boolean redraw;
1112
void redraw() {
@@ -23,18 +24,27 @@ class ROText extends Drawable {
2324
int dy = -s.size();
2425
clip(x+border, y+3, w-border*2, h-6);
2526
for (String s : s) {
26-
text(s, x+border, y + dy*tsz + yoff);
27+
text(s, x+border + xoff, y + dy*tsz + yoff);
2728
dy++;
2829
}
2930
noClip();
3031
redraw = false;
3132
}
3233
void tick() {
3334
if (!visible) return;
34-
if (mousePressed && smouseIn()) {
35-
yoff+= mouseY-pmouseY;
35+
if (mousePressed && smouseIn() && (mouseY!=pmouseY || mouseX!=pmouseX)) {
3636
redraw = true;
37+
yoff+= mouseY-pmouseY;
3738
if (yoff < h-border) yoff = h-border;
39+
40+
41+
xoff+= mouseX-pmouseX;
42+
int max = 0;
43+
for (String s : s) max = max(max, s.length());
44+
float maxx = (max - 2)*chw;
45+
if (xoff < -maxx) xoff = (int) -maxx;
46+
if (w > (max + 5)*chw) xoff = 0;
47+
if (xoff > 0) xoff = 0;
3848
}
3949

4050
if (redraw) redraw();
@@ -44,15 +54,19 @@ class ROText extends Drawable {
4454
void append(String a) { // append a line
4555
s.add(a);
4656
yoff = h-border;
57+
xoff = 0;
4758
redraw = true;
4859
}
4960
void set(ArrayList<String> a) {
5061
s = a;
5162
yoff = h-border;
63+
xoff = 0;
5264
redraw = true;
5365
}
5466
void setSize(int sz) {
5567
tsz = sz;
68+
textSize(tsz);
69+
chw = g.textWidth('H');
5670
redraw = true;
5771
}
5872
void end() {

AndroidIDE/Textarea.pde

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ class APLTextarea extends Drawable implements TextReciever {
1212
super(x, y, w, h);
1313
lines = new ArrayList();
1414
lines.add("");
15+
setsz(min(width, height)/20);
1516
}
1617
int tt = 0; // caret flicker timer
1718
int xoff = 0; // scroll
1819
int yoff = 0;
1920

2021
void redraw() {
21-
setsz(min(width, height)/20);
2222
}
2323
boolean saveUndo = true;
2424
boolean modified = false;
@@ -91,7 +91,7 @@ class APLTextarea extends Drawable implements TextReciever {
9191
// //text(s, x, y + dy*tsz + yoff);
9292
// dy++;
9393
//}
94-
hl.draw(x + xoff, y + yoff, y, y+h, tsz, fullPos());
94+
hl.draw(x + xoff, textY(y + yoff, tsz), y, y+h, tsz, fullPos());
9595

9696
tt--;
9797
if (tt < 0) tt = 60;

AndroidIDE/Textfield.pde

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
class APLField extends Drawable implements TextReciever {
2-
float tsz;
2+
float tsz, chw;
33
SyntaxHighlight hl;
44
Theme th = new Theme();
55

66
float extraH = 1.2;
7+
float xoff = 0;
78

89
APLField(int x, int y, int w, int h) {
910
this(x, y, w, h, "");
@@ -18,6 +19,8 @@ class APLField extends Drawable implements TextReciever {
1819

1920
void redraw() {
2021
tsz = h/extraH;
22+
textSize(tsz);
23+
chw = textWidth("H");
2124
}
2225
boolean saveUndo = true;
2326
boolean modified = false;
@@ -29,6 +32,13 @@ class APLField extends Drawable implements TextReciever {
2932
if (mousePressed && !pmousePressed && smouseIn()) {
3033
textInput = this;
3134
}
35+
if (mousePressed && smouseIn()) {
36+
xoff+= mouseX-pmouseX;
37+
}
38+
float maxx = w*.8/chw > line.length()? 0 : (line.length() - 2)*chw;
39+
if (xoff < -maxx) xoff = (int) -maxx;
40+
if (xoff > 0) xoff = 0;
41+
3242
if (modified || saveUndo) {
3343
modified();
3444
hl = new SyntaxHighlight(line, th, g);
@@ -43,7 +53,7 @@ class APLField extends Drawable implements TextReciever {
4353
clip(x, y, w, h);
4454
if (pmousePressed && !mousePressed && smouseIn() && dist(mouseX, mouseY, smouseX, smouseY) < 10) {
4555
textSize(tsz);
46-
sx = constrain(round((mouseX-x)/textWidth("H")), 0, line.length());
56+
sx = constrain(round((mouseX-x-xoff)/textWidth("H")), 0, line.length());
4757
ex = sx;
4858
tt = 0;
4959
}
@@ -52,18 +62,18 @@ class APLField extends Drawable implements TextReciever {
5262
rectMode(CORNER);
5363
rect(x, y, w, h);
5464
//text(line, x, y + dy*tsz + h*.1);
55-
if (apl()) hl.draw(x, y, tsz, sx); //SyntaxHighlight.apltext(line, x, y + dy*tsz + h*.1, tsz, new Theme(), g);
65+
if (apl()) hl.draw(x + xoff, textY(y, tsz), tsz, sx); //SyntaxHighlight.apltext(line, x, y + dy*tsz + h*.1, tsz, new Theme(), g);
5666
else {
5767
fill(#D2D2D2);
5868
g.textAlign(LEFT, TOP);
5969
textSize(tsz);
60-
text(line, x, y);
70+
text(line, x + xoff, textY(y, tsz));
6171
}
6272
tt--;
6373
if (tt < 0) tt = 60;
6474

65-
float spx = x + max(textWidth(line.substring(0, sx)), 3);
66-
float epx = x + max(textWidth(line.substring(0, ex)), 3);
75+
float spx = x + max(textWidth(line.substring(0, sx)), 3) + xoff;
76+
float epx = x + max(textWidth(line.substring(0, ex)), 3) + xoff;
6777
float sy = y + h*.1;
6878
float ey = y + h*.9;
6979
if (tt > 30 || this != textInput) {
@@ -104,6 +114,8 @@ class APLField extends Drawable implements TextReciever {
104114
if (!one()) line = line.substring(0, min) + line.substring(max);
105115
ex = min;
106116
sx = min;
117+
modified = true;
118+
saveUndo = true;
107119
}
108120
void append(String str) {
109121
deleteSel();
@@ -195,6 +207,10 @@ class APLField extends Drawable implements TextReciever {
195207
else if (s.equals("paste")) {
196208
paste(this);
197209
}
210+
else if (s.equals("match")) {
211+
int sel = hl.sel(sx);
212+
if (sel != -1) sx = ex = sel;
213+
}
198214
else extraSpecial(s);
199215
}
200216
void pasted(String s) {

AndroidIDE/data/L.json

+1-1
Large diffs are not rendered by default.

AndroidIDE/data/P.json

+1-1
Large diffs are not rendered by default.

AndroidIDE/data/kbs.txt

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
MOD ↶ spec=undo
2-
MOD ↷ spec=redo
3-
MOD « rep spec=left
4-
MOD » rep spec=right
1+
MOD ↶ rep=6 spec=undo
2+
MOD ↷ rep=6 spec=redo
3+
MOD « rep=2 spec=left
4+
MOD » rep=2 spec=right
55
MOD ⇧ spec=shift
6-
MOD ⌫ rep spec=del
6+
MOD ⌫ rep=3 spec=del
77
MOD C spec=clear
8-
MOD ▲ rep spec=up
9-
MOD ▼ rep spec=down
8+
MOD ▲ rep=6 spec=up
9+
MOD ▼ rep=6 spec=down
1010
MOD # spec=none goto=CODE
1111
MOD A spec=none goto=ABC3
1212
MOD ⏎ spec=enter
@@ -17,7 +17,7 @@ MOD O spec=openPar chr=()
1717
MOD P spec=wrapPar chr=..)
1818
MOD č spec=copy chr=^C
1919
MOD V spec=paste chr=^V
20-
MOD ⌦ spec=rdel
20+
MOD ⌦ rep=3 spec=rdel
2121
MOD X spec=close
2222
MOD M spec=match
2323

AndroidIDE/data/parse.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ function parse(chr, mods) {
2121
if (mods[chr]) {
2222
for (let mod of mods[chr]) {
2323
if (mod === 'sd') o.sd = true;
24-
else if (mod === 'rep') o.rep = true;
2524
else {
2625
let [key, val] = mod.split(/(?<!=)=/);
27-
if (key === 'spec') o.spec = val;
26+
if (key === 'rep') {
27+
o.rep = parseInt(val);
28+
if (o.rep != val) throw new Error("couldn't parse number "+val);
29+
}
30+
else if (key === 'spec') o.spec = val;
2831
else if (key === 'goto') o.goto = val;
2932
else if (key === 'chr') o.chr = val;
3033
else if (key === 'type') o.type = val;
31-
else throw "unknown mod "+mod;
34+
else throw new Error("unknown mod "+mod);
3235
}
3336
}
3437
}

0 commit comments

Comments
 (0)