1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-01-04 14:30:35 +00:00

string editor now may restrict the available keys

This commit is contained in:
Zeno Rogue 2018-11-24 22:49:45 +01:00
parent 2fa265ac10
commit 8866bc889d
2 changed files with 14 additions and 5 deletions

View File

@ -990,8 +990,14 @@ namespace dialog {
editpos = isize(s); editpos = isize(s);
} }
bool handle_edit_string(int sym, int uni) { string editchecker(int sym, int uni) {
if(uni >= 32 && uni < 127) return string("") + char(uni);
return "";
}
bool handle_edit_string(int sym, int uni, function<string(int, int)> checker) {
auto& es = *edited_string; auto& es = *edited_string;
string u2;
if(sym == SDLK_LEFT) editpos--; if(sym == SDLK_LEFT) editpos--;
else if(sym == SDLK_RIGHT) editpos++; else if(sym == SDLK_RIGHT) editpos++;
else if(uni == 8) { else if(uni == 8) {
@ -999,9 +1005,11 @@ namespace dialog {
es.replace(editpos-1, 1, ""); es.replace(editpos-1, 1, "");
editpos--; editpos--;
} }
else if(uni >= 32 && uni < 128) { else if((u2 = checker(sym, uni)) != "") {
es.insert(editpos, 1, uni); for(char c: u2) {
editpos++; es.insert(editpos, 1, c);
editpos ++;
}
} }
else return false; else return false;
return true; return true;

View File

@ -1842,7 +1842,8 @@ namespace dialog {
string view_edited_string(); string view_edited_string();
void start_editing(string& s); void start_editing(string& s);
bool handle_edit_string(int sym, int uni); string editchecker(int sym, int uni);
bool handle_edit_string(int sym, int uni, function<string(int, int)> checker = editchecker);
void edit_string(string& s, string title, string help); void edit_string(string& s, string title, string help);
} }