diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs index 9082d2d..b3f7903 100644 --- a/MLEM.Ui/Elements/Panel.cs +++ b/MLEM.Ui/Elements/Panel.cs @@ -64,6 +64,7 @@ namespace MLEM.Ui.Elements { private StyleProp scrollBarOffset; private float lastScrollOffset; private bool childrenDirtyForScroll; + private bool scrollBarMaxHistoryDirty; /// /// Creates a new panel with the given settings. @@ -172,6 +173,14 @@ namespace MLEM.Ui.Elements { base.RemoveChildren(e => e != this.ScrollBar && (condition == null || condition(e))); } + /// + public override void Update(GameTime time) { + // reset the scroll bar's max history when an update happens, at which point we know that any scroll bar recursion has "settled" + // (this reset ensures that the max history is recursion-internal and old values aren't reused when elements get modified later) + this.ResetScrollBarMaxHistory(); + base.Update(time); + } + /// public override void Draw(GameTime time, SpriteBatch batch, float alpha, SpriteBatchContext context) { // draw children onto the render target if we have one @@ -334,6 +343,7 @@ namespace MLEM.Ui.Elements { this.scrollBarMaxHistory[0] = this.scrollBarMaxHistory[1]; this.scrollBarMaxHistory[1] = this.scrollBarMaxHistory[2]; this.scrollBarMaxHistory[2] = scrollBarMax; + this.scrollBarMaxHistoryDirty = true; this.ScrollBar.MaxValue = scrollBarMax; this.relevantChildrenDirty = true; @@ -419,9 +429,10 @@ namespace MLEM.Ui.Elements { } private void ResetScrollBarMaxHistory() { - if (this.scrollOverflow) { + if (this.scrollOverflow && this.scrollBarMaxHistoryDirty) { for (var i = 0; i < this.scrollBarMaxHistory.Length; i++) this.scrollBarMaxHistory[i] = -1; + this.scrollBarMaxHistoryDirty = false; } }