1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-29 19:40: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

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

View File

@ -1842,7 +1842,8 @@ namespace dialog {
string view_edited_string();
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);
}