1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 06:28:35 +01:00

properly stop a panel's scroll bar from being removed

This commit is contained in:
Ell 2021-03-24 22:01:02 +01:00
parent be9748e70e
commit 5f7956a7a3
2 changed files with 16 additions and 7 deletions

View file

@ -423,7 +423,7 @@ namespace MLEM.Ui.Elements {
/// <param name="index">The index to add the child at, or -1 to add it to the end of the <see cref="Children"/> list</param> /// <param name="index">The index to add the child at, or -1 to add it to the end of the <see cref="Children"/> list</param>
/// <typeparam name="T">The type of child to add</typeparam> /// <typeparam name="T">The type of child to add</typeparam>
/// <returns>This element, for chaining</returns> /// <returns>This element, for chaining</returns>
public T AddChild<T>(T element, int index = -1) where T : Element { public virtual T AddChild<T>(T element, int index = -1) where T : Element {
if (index < 0 || index > this.children.Count) if (index < 0 || index > this.children.Count)
index = this.children.Count; index = this.children.Count;
this.children.Insert(index, element); this.children.Insert(index, element);
@ -443,7 +443,7 @@ namespace MLEM.Ui.Elements {
/// Removes the given child from this element. /// Removes the given child from this element.
/// </summary> /// </summary>
/// <param name="element">The child element to remove</param> /// <param name="element">The child element to remove</param>
public void RemoveChild(Element element) { public virtual void RemoveChild(Element element) {
this.children.Remove(element); this.children.Remove(element);
// set area dirty here so that a dirty call is made // set area dirty here so that a dirty call is made
// upwards to us if the element is auto-positioned // 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. /// Removes all children from this element that match the given condition.
/// </summary> /// </summary>
/// <param name="condition">The condition that determines if a child should be removed</param> /// <param name="condition">The condition that determines if a child should be removed</param>
public void RemoveChildren(Func<Element, bool> condition = null) { public virtual void RemoveChildren(Func<Element, bool> condition = null) {
for (var i = this.Children.Count - 1; i >= 0; i--) { for (var i = this.Children.Count - 1; i >= 0; i--) {
var child = this.Children[i]; var child = this.Children[i];
if (condition == null || condition(child)) { if (condition == null || condition(child)) {

View file

@ -108,11 +108,20 @@ namespace MLEM.Ui.Elements {
/// <inheritdoc /> /// <inheritdoc />
public override void ForceUpdateSortedChildren() { public override void ForceUpdateSortedChildren() {
base.ForceUpdateSortedChildren(); base.ForceUpdateSortedChildren();
if (this.scrollOverflow) { 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");
this.relevantChildrenDirty = true; this.relevantChildrenDirty = true;
} }
/// <inheritdoc />
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);
}
/// <inheritdoc />
public override void RemoveChildren(Func<Element, bool> condition = null) {
base.RemoveChildren(e => e != this.ScrollBar && (condition == null || condition(e)));
} }
/// <inheritdoc /> /// <inheritdoc />