Skip to content

Commit 77409fa

Browse files
committed
fix TextField rendering outside of field
1 parent 9ed128e commit 77409fa

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

src/jfcraft/opengl/RenderScreen.java

+30-24
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,7 @@ public void keyTyped(char ch) {
879879
}
880880
txt.insert(cpos, ch);
881881
cpos++;
882+
findCursor();
882883
}
883884
public void keyPressed(int code) {
884885
switch (code) {
@@ -949,6 +950,34 @@ public void delete() {
949950
if (cpos == txt.length()) return;
950951
txt.deleteCharAt(cpos);
951952
}
953+
public void render(boolean focus) {
954+
if (back != null) {
955+
renderBar(x1, y1 + fontSize + 4, width, fontSize + 4, back);
956+
}
957+
int x = x1;
958+
int y = y1;
959+
int sl = txt.length();
960+
int xp = 0;
961+
if (center) {
962+
x += (width - sl * fontSize * scale) / 2;
963+
xp = x;
964+
}
965+
t_text.bind();
966+
int cnt = 0;
967+
for(int p=dpos;p<txt.length() && cnt < chars;p++) {
968+
renderChar(x+1,y+1,txt.charAt(p),Static.white4, scale);
969+
x += fontSize * scale;
970+
cnt++;
971+
}
972+
if (showCursor && focus) {
973+
if (center) {
974+
renderChar(x, y,'<', Static.white, scale);
975+
renderChar(xp - fontSize * scale, y,'>', Static.white, scale);
976+
} else {
977+
renderChar(xp + ((cpos - dpos) * fontSize), y,(char)219, Static.white, scale);
978+
}
979+
}
980+
}
952981
}
953982

954983
public static class ScrollBar {
@@ -1065,30 +1094,7 @@ public void renderFields() {
10651094
setOrtho();
10661095
for(int a=0;a<fields.size();a++) {
10671096
TextField field = fields.get(a);
1068-
if (field.back != null) {
1069-
renderBar(field.x1, field.y1 + fontSize + 4, field.width, fontSize + 4, field.back);
1070-
}
1071-
int x = field.x1;
1072-
int y = field.y1;
1073-
int sl = field.txt.length();
1074-
int x1 = 0;
1075-
if (field.center) {
1076-
x += (field.width - sl * fontSize * field.scale) / 2;
1077-
x1 = x;
1078-
}
1079-
t_text.bind();
1080-
for(int p=field.dpos;p<field.txt.length();p++) {
1081-
renderChar(x+1,y+1,field.txt.charAt(p),Static.white4, field.scale);
1082-
x += fontSize * field.scale;
1083-
}
1084-
if (showCursor && focus == field) {
1085-
if (field.center) {
1086-
renderChar(x, y,'<', Static.white, field.scale);
1087-
renderChar(x1 - fontSize * field.scale, y,'>', Static.white, field.scale);
1088-
} else {
1089-
renderChar(field.x1 + ((field.cpos - field.dpos) * fontSize), y,(char)219, Static.white, field.scale);
1090-
}
1091-
}
1097+
field.render(focus == field);
10921098
}
10931099
}
10941100

0 commit comments

Comments
 (0)