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:
parent
2fa265ac10
commit
8866bc889d
16
dialogs.cpp
16
dialogs.cpp
@ -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;
|
||||
|
3
hyper.h
3
hyper.h
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user