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

Allow overriding SetAreaAndUpdateChildren and switch to using it in some locations

This commit is contained in:
Ell 2021-12-11 17:39:49 +01:00
parent 103d7c7503
commit 55fae16768
3 changed files with 10 additions and 7 deletions

View file

@ -646,7 +646,7 @@ namespace MLEM.Ui.Elements {
newSize.Y = parentArea.Bottom - pos.Y; newSize.Y = parentArea.Bottom - pos.Y;
} }
this.SetAreaDirectlyAndUpdateChildren(new RectangleF(pos, newSize)); this.SetAreaAndUpdateChildren(new RectangleF(pos, newSize));
if (this.SetWidthBasedOnChildren || this.SetHeightBasedOnChildren) { if (this.SetWidthBasedOnChildren || this.SetHeightBasedOnChildren) {
Element foundChild = null; Element foundChild = null;
@ -701,7 +701,7 @@ namespace MLEM.Ui.Elements {
/// Note that this method does not take into account any auto-sizing, anchoring or positioning, and so it should be used sparingly, if at all. /// Note that this method does not take into account any auto-sizing, anchoring or positioning, and so it should be used sparingly, if at all.
/// </summary> /// </summary>
/// <seealso cref="ForceUpdateArea"/> /// <seealso cref="ForceUpdateArea"/>
public void SetAreaDirectlyAndUpdateChildren(RectangleF area) { public virtual void SetAreaAndUpdateChildren(RectangleF area) {
this.area = area; this.area = area;
this.System.InvokeOnElementAreaUpdated(this); this.System.InvokeOnElementAreaUpdated(this);
foreach (var child in this.Children) foreach (var child in this.Children)

View file

@ -104,12 +104,15 @@ namespace MLEM.Ui.Elements {
throw new NotSupportedException($"A panel that scrolls overflow cannot contain another panel that scrolls overflow ({child})"); throw new NotSupportedException($"A panel that scrolls overflow cannot contain another panel that scrolls overflow ({child})");
} }
} }
base.ForceUpdateArea(); base.ForceUpdateArea();
this.SetScrollBarStyle();
}
/// <inheritdoc />
public override void SetAreaAndUpdateChildren(RectangleF area) {
base.SetAreaAndUpdateChildren(area);
this.ScrollChildren(); this.ScrollChildren();
this.ScrollSetup(); this.ScrollSetup();
this.SetScrollBarStyle();
} }
private void ScrollChildren() { private void ScrollChildren() {

View file

@ -20,13 +20,13 @@ namespace MLEM.Ui.Elements {
} }
/// <inheritdoc /> /// <inheritdoc />
public override void ForceUpdateArea() { public override void SetAreaAndUpdateChildren(RectangleF area) {
base.ForceUpdateArea(); base.SetAreaAndUpdateChildren(area);
// we squish children in order of priority, since auto-anchoring is based on addition order // we squish children in order of priority, since auto-anchoring is based on addition order
for (var i = 0; i < this.SortedChildren.Count; i++) { for (var i = 0; i < this.SortedChildren.Count; i++) {
var child = this.SortedChildren[i]; var child = this.SortedChildren[i];
if (SquishChild(child, out var squished)) if (SquishChild(child, out var squished))
child.SetAreaDirectlyAndUpdateChildren(squished); child.SetAreaAndUpdateChildren(squished);
} }
} }