mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-10-31 21:00:51 +01:00
Fixed a stack overflow exception when a panel's scroll bar auto-hiding causes elements to gain height
This commit is contained in:
parent
6c07a7e900
commit
0571e8a4e1
2 changed files with 14 additions and 2 deletions
|
@ -34,6 +34,7 @@ Improvements
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
- Fixed panels updating their relevant children too much when the scroll bar is hidden
|
- Fixed panels updating their relevant children too much when the scroll bar is hidden
|
||||||
|
- Fixed a stack overflow exception when a panel's scroll bar auto-hiding causes elements to gain height
|
||||||
|
|
||||||
### MLEM.Data
|
### MLEM.Data
|
||||||
Fixes
|
Fixes
|
||||||
|
|
|
@ -56,6 +56,7 @@ namespace MLEM.Ui.Elements {
|
||||||
|
|
||||||
private readonly List<Element> relevantChildren = new List<Element>();
|
private readonly List<Element> relevantChildren = new List<Element>();
|
||||||
private readonly HashSet<Element> scrolledChildren = new HashSet<Element>();
|
private readonly HashSet<Element> scrolledChildren = new HashSet<Element>();
|
||||||
|
private readonly float[] scrollBarMaxHistory = new float[3];
|
||||||
private readonly bool scrollOverflow;
|
private readonly bool scrollOverflow;
|
||||||
|
|
||||||
private RenderTarget2D renderTarget;
|
private RenderTarget2D renderTarget;
|
||||||
|
@ -110,7 +111,10 @@ namespace MLEM.Ui.Elements {
|
||||||
throw new NotSupportedException($"A panel that handles overflow can't contain non-automatic anchors ({child})");
|
throw new NotSupportedException($"A panel that handles overflow can't contain non-automatic anchors ({child})");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
base.ForceUpdateArea();
|
base.ForceUpdateArea();
|
||||||
|
Array.Clear(this.scrollBarMaxHistory, 0, this.scrollBarMaxHistory.Length);
|
||||||
|
|
||||||
this.SetScrollBarStyle();
|
this.SetScrollBarStyle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,8 +277,15 @@ namespace MLEM.Ui.Elements {
|
||||||
// the max value of the scroll bar is the amount of non-scaled pixels taken up by overflowing components
|
// the max value of the scroll bar is the amount of non-scaled pixels taken up by overflowing components
|
||||||
var scrollBarMax = Math.Max(0, (childrenHeight - this.ChildPaddedArea.Height) / this.Scale);
|
var scrollBarMax = Math.Max(0, (childrenHeight - this.ChildPaddedArea.Height) / this.Scale);
|
||||||
if (!this.ScrollBar.MaxValue.Equals(scrollBarMax, Element.Epsilon)) {
|
if (!this.ScrollBar.MaxValue.Equals(scrollBarMax, Element.Epsilon)) {
|
||||||
this.ScrollBar.MaxValue = scrollBarMax;
|
// avoid a show/hide oscillation that occurs while updating our area with children that can lose height when the scroll bar is shown (like long paragraphs)
|
||||||
this.relevantChildrenDirty = true;
|
if (!this.scrollBarMaxHistory[0].Equals(this.scrollBarMaxHistory[2], Element.Epsilon) || !this.scrollBarMaxHistory[1].Equals(scrollBarMax, Element.Epsilon)) {
|
||||||
|
this.scrollBarMaxHistory[0] = this.scrollBarMaxHistory[1];
|
||||||
|
this.scrollBarMaxHistory[1] = this.scrollBarMaxHistory[2];
|
||||||
|
this.scrollBarMaxHistory[2] = scrollBarMax;
|
||||||
|
|
||||||
|
this.ScrollBar.MaxValue = scrollBarMax;
|
||||||
|
this.relevantChildrenDirty = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update child padding based on whether the scroll bar is visible
|
// update child padding based on whether the scroll bar is visible
|
||||||
|
|
Loading…
Reference in a new issue