Skip to content

Commit

Permalink
further improved performance of panels when removing a large amount o…
Browse files Browse the repository at this point in the history
…f children
  • Loading branch information
Ellpeck committed Apr 2, 2024
1 parent 7f4cc77 commit 3bb3ae2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion MLEM.Ui/Elements/Panel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public StyleProp<float> ScrollBarOffset {
private float scrollBarChildOffset;
private StyleProp<float> scrollBarOffset;
private float lastScrollOffset;
private bool childrenDirtyForScroll;

/// <summary>
/// Creates a new panel with the given settings.
Expand Down Expand Up @@ -157,8 +158,16 @@ public override void RemoveChild(Element element) {

// when removing children, our scroll bar might have to be hidden
// if we don't do this before adding children again, they might incorrectly assume that the scroll bar will still be visible and adjust their size accordingly
if (this.System != null)
this.childrenDirtyForScroll = true;
}

/// <inheritdoc />
public override T AddChild<T>(T element, int index = -1) {
// if children were recently removed, make sure to update the scroll bar before adding new ones so that they can't incorrectly assume the scroll bar will be visible
if (this.childrenDirtyForScroll && this.System != null)
this.ScrollSetup();

return base.AddChild(element, index);
}

/// <inheritdoc />
Expand Down Expand Up @@ -277,6 +286,8 @@ protected internal override void RemovedFromUi() {
/// Prepares the panel for auto-scrolling, creating the render target and setting up the scroll bar's maximum value.
/// </summary>
protected virtual void ScrollSetup() {
this.childrenDirtyForScroll = false;

if (!this.scrollOverflow || this.IsHidden)
return;

Expand Down

0 comments on commit 3bb3ae2

Please sign in to comment.