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

Compare commits

..

No commits in common. "fb3b586a3569a6ee15c8ae36a12d2db0c97bf072" and "d7cda0d39b1c8fbb558d366ce27b4b4e3e692e11" have entirely different histories.

3 changed files with 10 additions and 34 deletions

View file

@ -32,12 +32,10 @@ Additions
Improvements Improvements
- **Include the SpriteBatchContext in OnDrawn, OnElementDrawn and OnSelectedElementDrawn** - **Include the SpriteBatchContext in OnDrawn, OnElementDrawn and OnSelectedElementDrawn**
- Allow scrolling panels to set height based on children by setting TreatSizeAsMaximum - Allow scrolling panels to set height based on children by setting TreatSizeAsMaximum
- Track element area update recursion count in UiMetrics
Fixes Fixes
- Fixed hidden scroll bars inhibiting scrolling on their parent panel - Fixed hidden scroll bars inhibiting scrolling on their parent panel
- Fixed scroll bars doing unnecessary calculations when hidden - Fixed scroll bars doing unnecessary calculations when hidden
- Fixed auto-sized elements sometimes updating their location based on outdated parent positions
## 6.3.1 ## 6.3.1

View file

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

View file

@ -29,15 +29,6 @@ namespace MLEM.Ui {
/// The amount of times that <see cref="Element.Update"/> was called. /// The amount of times that <see cref="Element.Update"/> was called.
/// </summary> /// </summary>
public uint Updates { get; internal set; } 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> /// <summary>
/// The amount of time that <see cref="Element.Draw(Microsoft.Xna.Framework.GameTime,Microsoft.Xna.Framework.Graphics.SpriteBatch,float,MLEM.Graphics.SpriteBatchContext)"/> took. /// The amount of time that <see cref="Element.Draw(Microsoft.Xna.Framework.GameTime,Microsoft.Xna.Framework.Graphics.SpriteBatch,float,MLEM.Graphics.SpriteBatchContext)"/> took.
@ -58,8 +49,6 @@ namespace MLEM.Ui {
this.ForceAreaUpdates = 0; this.ForceAreaUpdates = 0;
this.ActualAreaUpdates = 0; this.ActualAreaUpdates = 0;
this.Updates = 0; this.Updates = 0;
this.SummedRecursionDepth = 0;
this.MaxRecursionDepth = 0;
} }
/// <summary> /// <summary>
@ -73,7 +62,7 @@ namespace MLEM.Ui {
/// <summary>Returns the fully qualified type name of this instance.</summary> /// <summary>Returns the fully qualified type name of this instance.</summary>
/// <returns>The fully qualified type name.</returns> /// <returns>The fully qualified type name.</returns>
public override string ToString() { 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.SummedRecursionDepth)}: {this.SummedRecursionDepth}, {nameof(this.MaxRecursionDepth)}: {this.MaxRecursionDepth}, {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.DrawTime)}: {this.DrawTime}, {nameof(this.Draws)}: {this.Draws}";
} }
/// <summary> /// <summary>
@ -89,8 +78,6 @@ namespace MLEM.Ui {
ForceAreaUpdates = left.ForceAreaUpdates + right.ForceAreaUpdates, ForceAreaUpdates = left.ForceAreaUpdates + right.ForceAreaUpdates,
ActualAreaUpdates = left.ActualAreaUpdates + right.ActualAreaUpdates, ActualAreaUpdates = left.ActualAreaUpdates + right.ActualAreaUpdates,
Updates = left.Updates + right.Updates, Updates = left.Updates + right.Updates,
SummedRecursionDepth = left.SummedRecursionDepth + right.SummedRecursionDepth,
MaxRecursionDepth = left.MaxRecursionDepth + right.MaxRecursionDepth,
DrawTime = left.DrawTime + right.DrawTime, DrawTime = left.DrawTime + right.DrawTime,
Draws = left.Draws + right.Draws Draws = left.Draws + right.Draws
}; };
@ -109,8 +96,6 @@ namespace MLEM.Ui {
ForceAreaUpdates = left.ForceAreaUpdates - right.ForceAreaUpdates, ForceAreaUpdates = left.ForceAreaUpdates - right.ForceAreaUpdates,
ActualAreaUpdates = left.ActualAreaUpdates - right.ActualAreaUpdates, ActualAreaUpdates = left.ActualAreaUpdates - right.ActualAreaUpdates,
Updates = left.Updates - right.Updates, Updates = left.Updates - right.Updates,
SummedRecursionDepth = left.SummedRecursionDepth - right.SummedRecursionDepth,
MaxRecursionDepth = left.MaxRecursionDepth - right.MaxRecursionDepth,
DrawTime = left.DrawTime - right.DrawTime, DrawTime = left.DrawTime - right.DrawTime,
Draws = left.Draws - right.Draws Draws = left.Draws - right.Draws
}; };