add max-chars attribute to text field
This commit is contained in:
@@ -442,16 +442,18 @@ void cTextField::handleInput(cKey key, bool record) {
|
||||
handleInput(deleteKey);
|
||||
contents = getText();
|
||||
}
|
||||
if(aTextInsert* ins = dynamic_cast<aTextInsert*>(current_action.get()))
|
||||
ins->append(key.c);
|
||||
else {
|
||||
if(current_action) history.add(current_action);
|
||||
aTextInsert* new_ins = new aTextInsert(*this, insertionPoint);
|
||||
new_ins->append(key.c);
|
||||
current_action.reset(new_ins);
|
||||
if(maxChars < 0 || contents.size() < maxChars){
|
||||
if(aTextInsert* ins = dynamic_cast<aTextInsert*>(current_action.get()))
|
||||
ins->append(key.c);
|
||||
else {
|
||||
if(current_action) history.add(current_action);
|
||||
aTextInsert* new_ins = new aTextInsert(*this, insertionPoint);
|
||||
new_ins->append(key.c);
|
||||
current_action.reset(new_ins);
|
||||
}
|
||||
contents.insert(contents.begin() + insertionPoint, char(key.c));
|
||||
selectionPoint = ++insertionPoint;
|
||||
}
|
||||
contents.insert(contents.begin() + insertionPoint, char(key.c));
|
||||
selectionPoint = ++insertionPoint;
|
||||
} else switch(key.k) {
|
||||
case key_enter: break; // Shouldn't be receiving this anyway
|
||||
case key_left: case key_word_left:
|
||||
@@ -681,6 +683,9 @@ bool cTextField::parseAttribute(ticpp::Attribute& attr, std::string tagName, std
|
||||
} else if(name == "tab-order"){
|
||||
attr.GetValue(&tabOrder);
|
||||
return true;
|
||||
} else if(name == "max-chars"){
|
||||
attr.GetValue(&maxChars);
|
||||
return true;
|
||||
}
|
||||
return cControl::parseAttribute(attr, tagName, fname);
|
||||
}
|
||||
|
@@ -90,6 +90,10 @@ private:
|
||||
rectangle text_rect;
|
||||
std::vector<snippet_t> snippets;
|
||||
int ip_row, ip_col;
|
||||
/// Setting maxChars AFTER the player has a chance to type in the field would be a bad idea.
|
||||
/// So would calling setText() with a string longer than maxChars.
|
||||
/// Really, it should probably only be set in xml, as the attribute "max-chars".
|
||||
int maxChars = -1;
|
||||
friend class aTextInsert;
|
||||
friend class aTextDelete;
|
||||
};
|
||||
|
Reference in New Issue
Block a user