1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 04:53:29 +01:00

Fixed TextInput drawing characters with the wrong width if a masking character is used

This commit is contained in:
Ell 2023-02-17 18:33:56 +01:00
parent a47d3f50cb
commit 4029adb4bf
2 changed files with 12 additions and 10 deletions

View file

@ -16,11 +16,11 @@ Jump to version:
Fixes Fixes
- Fixed control characters being included in TextInput - Fixed control characters being included in TextInput
- Fixed TextInputs behaving incorrectly when switching between multiline and single-line modes - Fixed TextInputs behaving incorrectly when switching between multiline and single-line modes
- Fixed TextInput drawing characters with the wrong width if a masking character is used
### MLEM.Ui ### MLEM.Ui
Fixes Fixes
- Fixed images not updating their hidden state properly when the displayed texture changes - Fixed images not updating their hidden state properly when the displayed texture changes
- Fixed control characters being included in TextField
- Fixed a multiline text field's cursor not returning to the default position when the last character is removed - Fixed a multiline text field's cursor not returning to the default position when the last character is removed
## 6.1.0 ## 6.1.0

View file

@ -442,9 +442,14 @@ namespace MLEM.Input {
if (!this.textDataDirty || this.Font == null) if (!this.textDataDirty || this.Font == null)
return; return;
this.textDataDirty = false; this.textDataDirty = false;
var visualText = this.text;
if (this.MaskingCharacter != null)
visualText = new StringBuilder(visualText.Length).Append(this.MaskingCharacter.Value, visualText.Length);
if (this.Multiline) { if (this.Multiline) {
// soft wrap if we're multiline // soft wrap if we're multiline
this.splitText = this.Font.SplitStringSeparate(this.text, this.Size.X, this.TextScale).ToArray(); this.splitText = this.Font.SplitStringSeparate(visualText, this.Size.X, this.TextScale).ToArray();
this.displayedText = string.Join("\n", this.splitText); this.displayedText = string.Join("\n", this.splitText);
this.UpdateCaretData(); this.UpdateCaretData();
@ -471,7 +476,7 @@ namespace MLEM.Input {
} }
if (this.displayedText[i] == '\n') { if (this.displayedText[i] == '\n') {
lines++; lines++;
if (this.text[originalIndex] == '\n') if (visualText[originalIndex] == '\n')
originalIndex++; originalIndex++;
} else { } else {
originalIndex++; originalIndex++;
@ -488,28 +493,25 @@ namespace MLEM.Input {
this.splitText = null; this.splitText = null;
this.lineOffset = 0; this.lineOffset = 0;
// not multiline, so scroll horizontally based on caret position // not multiline, so scroll horizontally based on caret position
if (this.Font.MeasureString(this.text).X * this.TextScale > this.Size.X) { if (this.Font.MeasureString(visualText).X * this.TextScale > this.Size.X) {
if (this.textOffset > this.CaretPos) { if (this.textOffset > this.CaretPos) {
// if we're moving the caret to the left // if we're moving the caret to the left
this.textOffset = this.CaretPos; this.textOffset = this.CaretPos;
} else { } else {
// if we're moving the caret to the right // if we're moving the caret to the right
var importantArea = this.text.ToString(this.textOffset, Math.Min(this.CaretPos, this.text.Length) - this.textOffset); var importantArea = visualText.ToString(this.textOffset, Math.Min(this.CaretPos, visualText.Length) - this.textOffset);
var bound = this.CaretPos - this.Font.TruncateString(importantArea, this.Size.X, this.TextScale, true).Length; var bound = this.CaretPos - this.Font.TruncateString(importantArea, this.Size.X, this.TextScale, true).Length;
if (this.textOffset < bound) if (this.textOffset < bound)
this.textOffset = bound; this.textOffset = bound;
} }
var visible = this.text.ToString(this.textOffset, this.text.Length - this.textOffset); var visible = visualText.ToString(this.textOffset, visualText.Length - this.textOffset);
this.displayedText = this.Font.TruncateString(visible, this.Size.X, this.TextScale); this.displayedText = this.Font.TruncateString(visible, this.Size.X, this.TextScale);
} else { } else {
this.displayedText = this.Text; this.displayedText = visualText.ToString();
this.textOffset = 0; this.textOffset = 0;
} }
this.UpdateCaretData(); this.UpdateCaretData();
} }
if (this.MaskingCharacter != null)
this.displayedText = new string(this.MaskingCharacter.Value, this.displayedText.Length);
} }
private void UpdateCaretData() { private void UpdateCaretData() {