1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 12:58:33 +01:00

Increased some recursion limits, and added useful Element ToString

This commit is contained in:
Ell 2023-02-20 11:01:15 +01:00
parent dbd7f66c89
commit c4836eedd6
3 changed files with 25 additions and 6 deletions

View file

@ -19,10 +19,16 @@ Fixes
- Fixed TextInput drawing characters with the wrong width if a masking character is used - Fixed TextInput drawing characters with the wrong width if a masking character is used
- Fixed a multiline TextInput's cursor not returning to the default position when the last character is removed - Fixed a multiline TextInput's cursor not returning to the default position when the last character is removed
Improvements
- Increased TextFormatter macro recursion limit to 64
### 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
Improvements
- Increased Element area calculation recursion limit to 64
## 6.1.0 ## 6.1.0
### MLEM ### MLEM

View file

@ -801,8 +801,8 @@ namespace MLEM.Ui.Elements {
// we want to leave some leeway to prevent float rounding causing an infinite loop // we want to leave some leeway to prevent float rounding causing an infinite loop
if (!autoSize.Equals(this.UnscrolledArea.Size, Element.Epsilon)) { if (!autoSize.Equals(this.UnscrolledArea.Size, Element.Epsilon)) {
recursion++; recursion++;
if (recursion >= 16) if (recursion >= 64)
throw new ArithmeticException($"The area of {this} with root {this.Root.Name} has recursively updated too often. Does its child {foundChild} contain any conflicting auto-sizing settings?"); throw new ArithmeticException($"The area of {this} has recursively updated too often. Does its child {foundChild} contain any conflicting auto-sizing settings?");
UpdateDisplayArea(autoSize); UpdateDisplayArea(autoSize);
} }
} }
@ -1150,6 +1150,18 @@ namespace MLEM.Ui.Elements {
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
/// <inheritdoc />
public override string ToString() {
var ret = this.GetType().ToString();
// elements will contain their path up to the root (Paragraph@Panel@...@RootName)
if (this.Parent != null) {
ret += $"@{this.Parent}";
} else if (this.Root?.Element == this) {
ret += $"@{this.Root.Name}";
}
return ret;
}
/// <summary> /// <summary>
/// Performs the specified action on this element and all of its <see cref="Children"/> /// Performs the specified action on this element and all of its <see cref="Children"/>
/// </summary> /// </summary>

View file

@ -131,21 +131,22 @@ namespace MLEM.Formatting {
public string ResolveMacros(string s) { public string ResolveMacros(string s) {
// resolve macros that resolve into macros // resolve macros that resolve into macros
var rec = 0; var rec = 0;
var ret = s;
bool matched; bool matched;
do { do {
matched = false; matched = false;
foreach (var macro in this.Macros) { foreach (var macro in this.Macros) {
s = macro.Key.Replace(s, m => { ret = macro.Key.Replace(ret, m => {
// if the match evaluator was queried, then we know we matched something // if the match evaluator was queried, then we know we matched something
matched = true; matched = true;
return macro.Value(this, m, macro.Key); return macro.Value(this, m, macro.Key);
}); });
} }
rec++; rec++;
if (rec >= 16) if (rec >= 64)
throw new ArithmeticException($"A string resolved macros recursively too many times. Does it contain any conflicting macros?\n{s}"); throw new ArithmeticException($"A string resolved macros recursively too many times. Does it contain any conflicting macros?\nOriginal: {s}\nCurrent: {ret}");
} while (matched); } while (matched);
return s; return ret;
} }
private Code GetNextCode(string s, int index, int maxIndex = int.MaxValue) { private Code GetNextCode(string s, int index, int maxIndex = int.MaxValue) {