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

Compare commits

...

2 commits

3 changed files with 34 additions and 10 deletions

View file

@ -32,10 +32,12 @@ 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
- Fixed scroll bars doing unnecessary calculations when hidden
- Fixed auto-sized elements sometimes updating their location based on outdated parent positions
## 6.3.1

View file

@ -683,20 +683,22 @@ namespace MLEM.Ui.Elements {
return;
this.stopwatch.Restart();
var parentArea = this.ParentArea;
var parentCenterX = parentArea.X + parentArea.Width / 2;
var parentCenterY = parentArea.Y + parentArea.Height / 2;
var actualSize = this.CalcActualSize(parentArea);
var recursion = 0;
UpdateDisplayArea(actualSize);
UpdateDisplayArea();
this.stopwatch.Stop();
this.System.Metrics.ForceAreaUpdateTime += this.stopwatch.Elapsed;
this.System.Metrics.ForceAreaUpdates++;
void UpdateDisplayArea(Vector2 newSize) {
void UpdateDisplayArea(Vector2? overrideSize = null) {
var parentArea = this.ParentArea;
var parentCenterX = parentArea.X + parentArea.Width / 2;
var parentCenterY = parentArea.Y + parentArea.Height / 2;
var intendedSize = this.CalcActualSize(parentArea);
var newSize = overrideSize ?? intendedSize;
var pos = new Vector2();
switch (this.anchor) {
case Anchor.TopLeft:
case Anchor.AutoLeft:
@ -822,14 +824,19 @@ namespace MLEM.Ui.Elements {
}
if (this.TreatSizeAsMinimum) {
autoSize = Vector2.Max(autoSize, actualSize);
autoSize = Vector2.Max(autoSize, intendedSize);
} else if (this.TreatSizeAsMaximum) {
autoSize = Vector2.Min(autoSize, actualSize);
autoSize = Vector2.Min(autoSize, intendedSize);
}
// 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);

View file

@ -29,6 +29,15 @@ namespace MLEM.Ui {
/// The amount of times that <see cref="Element.Update"/> was called.
/// </summary>
public uint Updates { get; internal set; }
/// <summary>
/// The total amount of recursions that <see cref="Element.ForceUpdateArea"/> went through.
/// Can be divided by <see cref="ForceAreaUpdates"/> to get an average.
/// </summary>
public uint SummedRecursionDepth { get; internal set; }
/// <summary>
/// The maximum recursion depth that <see cref="Element.ForceUpdateArea"/> went through in a single call.
/// </summary>
public int MaxRecursionDepth { get; internal set; }
/// <summary>
/// The amount of time that <see cref="Element.Draw(Microsoft.Xna.Framework.GameTime,Microsoft.Xna.Framework.Graphics.SpriteBatch,float,MLEM.Graphics.SpriteBatchContext)"/> took.
@ -49,6 +58,8 @@ namespace MLEM.Ui {
this.ForceAreaUpdates = 0;
this.ActualAreaUpdates = 0;
this.Updates = 0;
this.SummedRecursionDepth = 0;
this.MaxRecursionDepth = 0;
}
/// <summary>
@ -62,7 +73,7 @@ namespace MLEM.Ui {
/// <summary>Returns the fully qualified type name of this instance.</summary>
/// <returns>The fully qualified type name.</returns>
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}";
}
/// <summary>
@ -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
};