1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 04:53:29 +01:00

Calculate panel scroll bar height based on content height

This commit is contained in:
Ell 2021-11-08 02:02:59 +01:00
parent a9e243835f
commit 3d0250bf86
2 changed files with 7 additions and 3 deletions

View file

@ -30,6 +30,7 @@ Improvements
- Allow style properties to set style values with a higher priority, which allows elements to style their default children
- Allow changing the entire ui style for a single element
- Skip unnecessary area updates for elements with dirty parents
- Calculate panel scroll bar height based on content height
Fixes
- Fixed VerticalSpace height parameter being an integer

View file

@ -39,7 +39,8 @@ namespace MLEM.Ui.Elements {
/// </summary>
public StyleProp<float> StepPerScroll;
/// <summary>
/// The size that the <see cref="ScrollBar"/>'s scroller should have, in pixels
/// The size that the <see cref="ScrollBar"/>'s scroller should have, in pixels.
/// The scroller size's height specified here is the minimum height, otherwise, it is automatically calculated based on panel content.
/// </summary>
public StyleProp<Vector2> ScrollerSize;
@ -225,7 +226,10 @@ namespace MLEM.Ui.Elements {
var lowestChild = this.GetLowestChild(c => c != this.ScrollBar && !c.IsHidden);
// the max value of the scrollbar is the amount of non-scaled pixels taken up by overflowing components
var childrenHeight = lowestChild.Area.Bottom - firstChild.Area.Top;
this.ScrollBar.MaxValue = (childrenHeight - this.Area.Height) / this.Scale + this.ChildPadding.Value.Height;
this.ScrollBar.MaxValue = (childrenHeight - this.ChildPaddedArea.Height) / this.Scale;
// 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
var scrollerHeight = this.ChildPaddedArea.Height / childrenHeight / this.Scale * this.ScrollBar.Area.Height;
this.ScrollBar.ScrollerSize = new Vector2(this.ScrollerSize.Value.X, Math.Max(this.ScrollerSize.Value.Y, scrollerHeight));
// update the render target
var targetArea = (Rectangle) this.GetRenderTargetArea();
@ -253,7 +257,6 @@ namespace MLEM.Ui.Elements {
return;
this.ScrollBar.StepPerScroll = this.StepPerScroll;
this.ScrollBar.Size = new Vector2(this.ScrollerSize.Value.X, 1);
this.ScrollBar.ScrollerSize = this.ScrollerSize;
this.ScrollBar.PositionOffset = new Vector2(-this.ScrollerSize.Value.X - 1, 0);
}