1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 06:28:35 +01:00

made the text field remove mismatching characters on mobile input

This commit is contained in:
Ellpeck 2019-09-01 19:50:17 +02:00
parent 334dea8b39
commit f65cd58a80

View file

@ -56,7 +56,7 @@ namespace MLEM.Ui.Elements {
var title = this.MobileTitle ?? this.PlaceholderText;
var result = await KeyboardInput.Show(title, this.MobileDescription, this.Text);
if (result != null)
this.SetText(result.Replace('\n', ' '));
this.SetText(result.Replace('\n', ' '), true);
}
};
}
@ -112,8 +112,15 @@ namespace MLEM.Ui.Elements {
base.Draw(time, batch, alpha, offset);
}
public void SetText(object text) {
if (!this.InputRule(this, text.ToString()))
public void SetText(object text, bool removeMismatching = false) {
if (removeMismatching) {
var result = new StringBuilder();
foreach (var c in text.ToString()) {
if (this.InputRule(this, c.ToString()))
result.Append(c);
}
text = result.ToString();
} else if (!this.InputRule(this, text.ToString()))
return;
this.text.Clear();
this.text.Append(text);