@@ -879,6 +879,7 @@ public void keyTyped(char ch) {
879
879
}
880
880
txt .insert (cpos , ch );
881
881
cpos ++;
882
+ findCursor ();
882
883
}
883
884
public void keyPressed (int code ) {
884
885
switch (code ) {
@@ -949,6 +950,34 @@ public void delete() {
949
950
if (cpos == txt .length ()) return ;
950
951
txt .deleteCharAt (cpos );
951
952
}
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
+ }
952
981
}
953
982
954
983
public static class ScrollBar {
@@ -1065,30 +1094,7 @@ public void renderFields() {
1065
1094
setOrtho ();
1066
1095
for (int a =0 ;a <fields .size ();a ++) {
1067
1096
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 );
1092
1098
}
1093
1099
}
1094
1100
0 commit comments