mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 06:28:35 +01:00
Fixed the scroll bar of an empty panel being positioned incorrectly
This commit is contained in:
parent
74b3c426b8
commit
d6a51776e5
2 changed files with 21 additions and 17 deletions
|
@ -46,6 +46,7 @@ Fixes
|
||||||
- Fixed UiMarkdownParser not parsing formatting in headings and blockquotes
|
- Fixed UiMarkdownParser not parsing formatting in headings and blockquotes
|
||||||
- Fixed Element.OnChildAdded and Element.OnChildRemoved being called for grandchildren when a child is added
|
- Fixed Element.OnChildAdded and Element.OnChildRemoved being called for grandchildren when a child is added
|
||||||
- Fixed an exception when trying to force-update the area of an element without a ui system
|
- Fixed an exception when trying to force-update the area of an element without a ui system
|
||||||
|
- Fixed the scroll bar of an empty panel being positioned incorrectly
|
||||||
|
|
||||||
### MLEM.Data
|
### MLEM.Data
|
||||||
Additions
|
Additions
|
||||||
|
|
|
@ -84,8 +84,9 @@ namespace MLEM.Ui.Elements {
|
||||||
return;
|
return;
|
||||||
if (e == null || !e.GetParentTree().Contains(this))
|
if (e == null || !e.GetParentTree().Contains(this))
|
||||||
return;
|
return;
|
||||||
var firstChild = this.Children.First(c => c != this.ScrollBar);
|
var firstChild = this.Children.FirstOrDefault(c => c != this.ScrollBar);
|
||||||
this.ScrollBar.CurrentValue = (e.Area.Center.Y - this.Area.Height / 2 - firstChild.Area.Top) / e.Scale + this.ChildPadding.Value.Height / 2;
|
if (firstChild != null)
|
||||||
|
this.ScrollBar.CurrentValue = (e.Area.Center.Y - this.Area.Height / 2 - firstChild.Area.Top) / e.Scale + this.ChildPadding.Value.Height / 2;
|
||||||
};
|
};
|
||||||
this.AddChild(this.ScrollBar);
|
this.AddChild(this.ScrollBar);
|
||||||
}
|
}
|
||||||
|
@ -231,28 +232,30 @@ namespace MLEM.Ui.Elements {
|
||||||
protected virtual void ScrollSetup() {
|
protected virtual void ScrollSetup() {
|
||||||
if (!this.scrollOverflow || this.IsHidden)
|
if (!this.scrollOverflow || this.IsHidden)
|
||||||
return;
|
return;
|
||||||
// if there is only one child, then we have just the scroll bar
|
|
||||||
if (this.Children.Count == 1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// the "real" first child is the scroll bar, which we want to ignore
|
float childrenHeight;
|
||||||
var firstChild = this.Children.First(c => c != this.ScrollBar);
|
if (this.Children.Count > 1) {
|
||||||
var lowestChild = this.GetLowestChild(c => c != this.ScrollBar && !c.IsHidden);
|
var firstChild = this.Children.FirstOrDefault(c => c != this.ScrollBar);
|
||||||
var childrenHeight = lowestChild.Area.Bottom - firstChild.Area.Top;
|
var lowestChild = this.GetLowestChild(c => c != this.ScrollBar && !c.IsHidden);
|
||||||
|
childrenHeight = lowestChild.Area.Bottom - firstChild.Area.Top;
|
||||||
|
} else {
|
||||||
|
// if we only have one child (the scroll bar), then the children take up no visual height
|
||||||
|
childrenHeight = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// the max value of the scrollbar is the amount of non-scaled pixels taken up by overflowing components
|
// the max value of the scroll bar is the amount of non-scaled pixels taken up by overflowing components
|
||||||
var scrollBarMax = (childrenHeight - this.ChildPaddedArea.Height) / this.Scale;
|
var scrollBarMax = (childrenHeight - this.ChildPaddedArea.Height) / this.Scale;
|
||||||
if (!this.ScrollBar.MaxValue.Equals(scrollBarMax, Element.Epsilon)) {
|
if (!this.ScrollBar.MaxValue.Equals(scrollBarMax, Element.Epsilon)) {
|
||||||
this.ScrollBar.MaxValue = scrollBarMax;
|
this.ScrollBar.MaxValue = scrollBarMax;
|
||||||
this.relevantChildrenDirty = true;
|
this.relevantChildrenDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
// update child padding based on whether the scroll bar is visible
|
// update child padding based on whether the scroll bar is visible
|
||||||
var childOffset = this.ScrollBar.IsHidden ? 0 : this.ScrollerSize.Value.X + this.ScrollBarOffset;
|
var childOffset = this.ScrollBar.IsHidden ? 0 : this.ScrollerSize.Value.X + this.ScrollBarOffset;
|
||||||
if (!this.scrollBarChildOffset.Equals(childOffset, Element.Epsilon)) {
|
if (!this.scrollBarChildOffset.Equals(childOffset, Element.Epsilon)) {
|
||||||
this.ChildPadding += new Padding(0, -this.scrollBarChildOffset + childOffset, 0, 0);
|
this.ChildPadding += new Padding(0, -this.scrollBarChildOffset + childOffset, 0, 0);
|
||||||
this.scrollBarChildOffset = childOffset;
|
this.scrollBarChildOffset = childOffset;
|
||||||
this.SetAreaDirty();
|
this.SetAreaDirty();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// the scroller height has the same relation to the scroll bar height as the visible area has to the total height of the panel's content
|
// the scroller height has the same relation to the scroll bar height as the visible area has to the total height of the panel's content
|
||||||
|
|
Loading…
Reference in a new issue