@@ -1142,45 +1142,95 @@ void rg_gui_draw_virtual_keyboard(int x_pos, int y_pos, const rg_keyboard_layout
11421142 }
11431143}
11441144
1145+ static const rg_keyboard_layout_t keyboard_layouts [] = {
1146+ // Lowercase letters
1147+ {
1148+ .layout = "1234567890"
1149+ "qwertyuiop"
1150+ "asdfghjkl "
1151+ "zxcvbnm.,?" ,
1152+ .columns = 10 ,
1153+ .rows = 4 ,
1154+ .is_upper = false,
1155+ .is_symbols = false
1156+ },
1157+ // Uppercase letters
1158+ {
1159+ .layout = "1234567890"
1160+ "QWERTYUIOP"
1161+ "ASDFGHJKL "
1162+ "ZXCVBNM.,?" ,
1163+ .columns = 10 ,
1164+ .rows = 4 ,
1165+ .is_upper = true,
1166+ .is_symbols = false
1167+ },
1168+ // Symbols
1169+ {
1170+ .layout = "!@#$%^&*()"
1171+ "[]{}|\\:;\"'"
1172+ "<>?/+=_-~ "
1173+ "1234567890" ,
1174+ .columns = 10 ,
1175+ .rows = 4 ,
1176+ .is_upper = false,
1177+ .is_symbols = true
1178+ }
1179+ };
1180+
1181+ // TODO: Abstract all the redundant/similar code between rg_gui_input_str and rg_gui_input_char
1182+
1183+ int rg_gui_input_char (const rg_keyboard_layout_t * map )
1184+ {
1185+ if (!map )
1186+ map = & keyboard_layouts [0 ];
1187+
1188+ int cursor = -1 ;
1189+ int count = map -> columns * map -> rows ;
1190+
1191+ rg_input_wait_for_key (RG_KEY_ALL , false, 1000 );
1192+
1193+ while (1 )
1194+ {
1195+ uint32_t joystick = rg_input_read_gamepad ();
1196+ int prev_cursor = cursor ;
1197+
1198+ if (joystick & RG_KEY_A )
1199+ return map -> layout [cursor ];
1200+ if (joystick & RG_KEY_B )
1201+ break ;
1202+
1203+ if (joystick & RG_KEY_LEFT )
1204+ cursor -- ;
1205+ if (joystick & RG_KEY_RIGHT )
1206+ cursor ++ ;
1207+ if (joystick & RG_KEY_UP )
1208+ cursor -= map -> columns ;
1209+ if (joystick & RG_KEY_DOWN )
1210+ cursor += map -> columns ;
1211+
1212+ if (cursor > count - 1 )
1213+ cursor = prev_cursor ;
1214+ else if (cursor < 0 )
1215+ cursor = prev_cursor ;
1216+
1217+ cursor = RG_MIN (RG_MAX (cursor , 0 ), count - 1 );
1218+
1219+ if (cursor != prev_cursor )
1220+ rg_gui_draw_virtual_keyboard (RG_GUI_CENTER , RG_GUI_BOTTOM , map , cursor , false);
1221+
1222+ rg_input_wait_for_key (RG_KEY_ALL , false, 500 );
1223+ rg_input_wait_for_key (RG_KEY_ANY , true, 500 );
1224+
1225+ rg_system_tick (0 );
1226+ }
1227+
1228+ return -1 ;
1229+ }
1230+
11451231char * rg_gui_input_str (const char * title , const char * message , const char * default_value )
11461232{
11471233 // Virtual keyboard implementation for Wi-Fi credential input
1148- static const rg_keyboard_layout_t layouts [] = {
1149- // Lowercase letters
1150- {
1151- .layout = "1234567890"
1152- "qwertyuiop"
1153- "asdfghjkl "
1154- "zxcvbnm.,?" ,
1155- .columns = 10 ,
1156- .rows = 4 ,
1157- .is_upper = false,
1158- .is_symbols = false
1159- },
1160- // Uppercase letters
1161- {
1162- .layout = "1234567890"
1163- "QWERTYUIOP"
1164- "ASDFGHJKL "
1165- "ZXCVBNM.,?" ,
1166- .columns = 10 ,
1167- .rows = 4 ,
1168- .is_upper = true,
1169- .is_symbols = false
1170- },
1171- // Symbols
1172- {
1173- .layout = "!@#$%^&*()"
1174- "[]{}|\\:;\"'"
1175- "<>?/+=_-~ "
1176- "1234567890" ,
1177- .columns = 10 ,
1178- .rows = 4 ,
1179- .is_upper = false,
1180- .is_symbols = true
1181- }
1182- };
1183-
11841234 char input_buffer [128 ] = {0 };
11851235 if (default_value )
11861236 strncpy (input_buffer , default_value , sizeof (input_buffer ) - 1 );
@@ -1190,7 +1240,7 @@ char *rg_gui_input_str(const char *title, const char *message, const char *defau
11901240 int input_length = strlen (input_buffer );
11911241 bool cancelled = false;
11921242
1193- const rg_keyboard_layout_t * current_layout = & layouts [layout_idx ];
1243+ const rg_keyboard_layout_t * current_layout = & keyboard_layouts [layout_idx ];
11941244
11951245 // Follow the same pattern as rg_gui_dialog
11961246 rg_input_wait_for_key (RG_KEY_ALL , false, 1000 );
@@ -1271,7 +1321,7 @@ char *rg_gui_input_str(const char *title, const char *message, const char *defau
12711321 {
12721322 layout_idx = 1 ; // Switch to uppercase
12731323 }
1274- current_layout = & layouts [layout_idx ];
1324+ current_layout = & keyboard_layouts [layout_idx ];
12751325 cursor_pos = 0 ;
12761326 redraw = true;
12771327 redraws = 0 ;
0 commit comments