mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 06:28:35 +01:00
Calculate panel scroll bar height based on content height
This commit is contained in:
parent
a9e243835f
commit
3d0250bf86
2 changed files with 7 additions and 3 deletions
|
@ -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 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
|
- Allow changing the entire ui style for a single element
|
||||||
- Skip unnecessary area updates for elements with dirty parents
|
- Skip unnecessary area updates for elements with dirty parents
|
||||||
|
- Calculate panel scroll bar height based on content height
|
||||||
|
|
||||||
Fixes
|
Fixes
|
||||||
- Fixed VerticalSpace height parameter being an integer
|
- Fixed VerticalSpace height parameter being an integer
|
||||||
|
|
|
@ -39,7 +39,8 @@ namespace MLEM.Ui.Elements {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StyleProp<float> StepPerScroll;
|
public StyleProp<float> StepPerScroll;
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public StyleProp<Vector2> ScrollerSize;
|
public StyleProp<Vector2> ScrollerSize;
|
||||||
|
|
||||||
|
@ -225,7 +226,10 @@ namespace MLEM.Ui.Elements {
|
||||||
var lowestChild = this.GetLowestChild(c => c != this.ScrollBar && !c.IsHidden);
|
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
|
// 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;
|
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
|
// update the render target
|
||||||
var targetArea = (Rectangle) this.GetRenderTargetArea();
|
var targetArea = (Rectangle) this.GetRenderTargetArea();
|
||||||
|
@ -253,7 +257,6 @@ namespace MLEM.Ui.Elements {
|
||||||
return;
|
return;
|
||||||
this.ScrollBar.StepPerScroll = this.StepPerScroll;
|
this.ScrollBar.StepPerScroll = this.StepPerScroll;
|
||||||
this.ScrollBar.Size = new Vector2(this.ScrollerSize.Value.X, 1);
|
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);
|
this.ScrollBar.PositionOffset = new Vector2(-this.ScrollerSize.Value.X - 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue