diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7f88478..a4b4cdb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,6 +32,7 @@ Additions
Improvements
- **Include the SpriteBatchContext in OnDrawn, OnElementDrawn and OnSelectedElementDrawn**
- Allow scrolling panels to set height based on children by setting TreatSizeAsMaximum
+- Track element area update recursion count in UiMetrics
Fixes
- Fixed hidden scroll bars inhibiting scrolling on their parent panel
diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs
index e6d10d8..ba5aa81 100644
--- a/MLEM.Ui/Elements/Element.cs
+++ b/MLEM.Ui/Elements/Element.cs
@@ -832,6 +832,11 @@ namespace MLEM.Ui.Elements {
// we want to leave some leeway to prevent float rounding causing an infinite loop
if (!autoSize.Equals(this.UnscrolledArea.Size, Element.Epsilon)) {
recursion++;
+
+ this.System.Metrics.SummedRecursionDepth++;
+ if (recursion > this.System.Metrics.MaxRecursionDepth)
+ this.System.Metrics.MaxRecursionDepth = recursion;
+
if (recursion >= 64)
throw new ArithmeticException($"The area of {this} has recursively updated too often. Does its child {foundChild} contain any conflicting auto-sizing settings?");
UpdateDisplayArea(autoSize);
diff --git a/MLEM.Ui/UiMetrics.cs b/MLEM.Ui/UiMetrics.cs
index 994cfc1..1d44366 100644
--- a/MLEM.Ui/UiMetrics.cs
+++ b/MLEM.Ui/UiMetrics.cs
@@ -29,6 +29,15 @@ namespace MLEM.Ui {
/// The amount of times that was called.
///
public uint Updates { get; internal set; }
+ ///
+ /// The total amount of recursions that went through.
+ /// Can be divided by to get an average.
+ ///
+ public uint SummedRecursionDepth { get; internal set; }
+ ///
+ /// The maximum recursion depth that went through in a single call.
+ ///
+ public int MaxRecursionDepth { get; internal set; }
///
/// The amount of time that took.
@@ -49,6 +58,8 @@ namespace MLEM.Ui {
this.ForceAreaUpdates = 0;
this.ActualAreaUpdates = 0;
this.Updates = 0;
+ this.SummedRecursionDepth = 0;
+ this.MaxRecursionDepth = 0;
}
///
@@ -62,7 +73,7 @@ namespace MLEM.Ui {
/// Returns the fully qualified type name of this instance.
/// The fully qualified type name.
public override string ToString() {
- return $"{nameof(this.ForceAreaUpdateTime)}: {this.ForceAreaUpdateTime}, {nameof(this.UpdateTime)}: {this.UpdateTime}, {nameof(this.ForceAreaUpdates)}: {this.ForceAreaUpdates}, {nameof(this.ActualAreaUpdates)}: {this.ActualAreaUpdates}, {nameof(this.Updates)}: {this.Updates}, {nameof(this.DrawTime)}: {this.DrawTime}, {nameof(this.Draws)}: {this.Draws}";
+ return $"{nameof(this.ForceAreaUpdateTime)}: {this.ForceAreaUpdateTime}, {nameof(this.UpdateTime)}: {this.UpdateTime}, {nameof(this.ForceAreaUpdates)}: {this.ForceAreaUpdates}, {nameof(this.ActualAreaUpdates)}: {this.ActualAreaUpdates}, {nameof(this.Updates)}: {this.Updates}, {nameof(this.SummedRecursionDepth)}: {this.SummedRecursionDepth}, {nameof(this.MaxRecursionDepth)}: {this.MaxRecursionDepth}, {nameof(this.DrawTime)}: {this.DrawTime}, {nameof(this.Draws)}: {this.Draws}";
}
///
@@ -78,6 +89,8 @@ namespace MLEM.Ui {
ForceAreaUpdates = left.ForceAreaUpdates + right.ForceAreaUpdates,
ActualAreaUpdates = left.ActualAreaUpdates + right.ActualAreaUpdates,
Updates = left.Updates + right.Updates,
+ SummedRecursionDepth = left.SummedRecursionDepth + right.SummedRecursionDepth,
+ MaxRecursionDepth = left.MaxRecursionDepth + right.MaxRecursionDepth,
DrawTime = left.DrawTime + right.DrawTime,
Draws = left.Draws + right.Draws
};
@@ -96,6 +109,8 @@ namespace MLEM.Ui {
ForceAreaUpdates = left.ForceAreaUpdates - right.ForceAreaUpdates,
ActualAreaUpdates = left.ActualAreaUpdates - right.ActualAreaUpdates,
Updates = left.Updates - right.Updates,
+ SummedRecursionDepth = left.SummedRecursionDepth - right.SummedRecursionDepth,
+ MaxRecursionDepth = left.MaxRecursionDepth - right.MaxRecursionDepth,
DrawTime = left.DrawTime - right.DrawTime,
Draws = left.Draws - right.Draws
};