diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs
index 55dcb71..d16f2ca 100644
--- a/MLEM.Ui/Elements/Element.cs
+++ b/MLEM.Ui/Elements/Element.cs
@@ -423,7 +423,7 @@ namespace MLEM.Ui.Elements {
/// The index to add the child at, or -1 to add it to the end of the list
/// The type of child to add
/// This element, for chaining
- public T AddChild(T element, int index = -1) where T : Element {
+ public virtual T AddChild(T element, int index = -1) where T : Element {
if (index < 0 || index > this.children.Count)
index = this.children.Count;
this.children.Insert(index, element);
@@ -443,7 +443,7 @@ namespace MLEM.Ui.Elements {
/// Removes the given child from this element.
///
/// The child element to remove
- public void RemoveChild(Element element) {
+ public virtual void RemoveChild(Element element) {
this.children.Remove(element);
// set area dirty here so that a dirty call is made
// upwards to us if the element is auto-positioned
@@ -462,7 +462,7 @@ namespace MLEM.Ui.Elements {
/// Removes all children from this element that match the given condition.
///
/// The condition that determines if a child should be removed
- public void RemoveChildren(Func condition = null) {
+ public virtual void RemoveChildren(Func condition = null) {
for (var i = this.Children.Count - 1; i >= 0; i--) {
var child = this.Children[i];
if (condition == null || condition(child)) {
diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs
index cd93684..b294127 100644
--- a/MLEM.Ui/Elements/Panel.cs
+++ b/MLEM.Ui/Elements/Panel.cs
@@ -108,11 +108,20 @@ namespace MLEM.Ui.Elements {
///
public override void ForceUpdateSortedChildren() {
base.ForceUpdateSortedChildren();
- if (this.scrollOverflow) {
- if (this.ScrollBar.Parent != this)
- throw new NotSupportedException("A panel that scrolls overflow cannot have its scroll bar removed from its list of children");
+ if (this.scrollOverflow)
this.relevantChildrenDirty = true;
- }
+ }
+
+ ///
+ public override void RemoveChild(Element element) {
+ if (element == this.ScrollBar)
+ throw new NotSupportedException("A panel that scrolls overflow cannot have its scroll bar removed from its list of children");
+ base.RemoveChild(element);
+ }
+
+ ///
+ public override void RemoveChildren(Func condition = null) {
+ base.RemoveChildren(e => e != this.ScrollBar && (condition == null || condition(e)));
}
///