diff --git a/CHANGELOG.md b/CHANGELOG.md
index 90d1cc0..2492978 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,6 +28,7 @@ Additions
- Added the ability to set the anchor that should be used when a tooltip attaches to an element or the mouse
- Added the ability to display tooltips using the auto-nav style even when using the mouse
- Added the ScissorGroup element, which applies a scissor rectangle when drawing its content
+- Added Panel.ScrollToTop and Panel.ScrollToBottom
Improvements
- **Include the SpriteBatchContext in OnDrawn, OnElementDrawn and OnSelectedElementDrawn**
@@ -39,6 +40,7 @@ Fixes
- Fixed hidden scroll bars inhibiting scrolling on their parent panel
- Fixed scroll bars doing unnecessary calculations when hidden
- Fixed auto-sized elements sometimes updating their location based on outdated parent positions
+- Fixed Panel.ScrollToElement not scrolling correctly when the panel's area is dirty
## 6.3.1
diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs
index 4b85e1e..c07ae92 100644
--- a/MLEM.Ui/Elements/Panel.cs
+++ b/MLEM.Ui/Elements/Panel.cs
@@ -236,9 +236,26 @@ namespace MLEM.Ui.Elements {
var highestValidChild = this.Children.FirstOrDefault(c => c != this.ScrollBar && !c.IsHidden);
if (highestValidChild == null)
return;
+ this.UpdateAreaIfDirty();
this.ScrollBar.CurrentValue = (elementY - this.Area.Height / 2 - highestValidChild.Area.Top) / this.Scale + this.ChildPadding.Value.Height / 2;
}
+ ///
+ /// Scrolls this panel's to the top, causing the top of this panel to be shown.
+ ///
+ public void ScrollToTop() {
+ this.UpdateAreaIfDirty();
+ this.ScrollBar.CurrentValue = 0;
+ }
+
+ ///
+ /// Scrolls this panel's to the bottom, causing the bottom of this panel to be shown.
+ ///
+ public void ScrollToBottom() {
+ this.UpdateAreaIfDirty();
+ this.ScrollBar.CurrentValue = this.ScrollBar.MaxValue;
+ }
+
///
protected override void InitStyle(UiStyle style) {
base.InitStyle(style);