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

fixed a regression where panels sometimes revert back to old, larger sizes after children change size

This commit is contained in:
Ell 2024-10-30 19:34:51 +01:00
parent dbd52d5b9d
commit c46b11f4fc

View file

@ -64,6 +64,7 @@ namespace MLEM.Ui.Elements {
private StyleProp<float> scrollBarOffset;
private float lastScrollOffset;
private bool childrenDirtyForScroll;
private bool scrollBarMaxHistoryDirty;
/// <summary>
/// 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)));
}
/// <inheritdoc />
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);
}
/// <inheritdoc />
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;
}
}