From 0f4e67f20f9f6196b746b1b6e55ad22a4c110b38 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 10 Mar 2022 18:04:36 +0100 Subject: [PATCH] Fixed auto-navigating panels not scrolling to the center of elements properly --- CHANGELOG.md | 1 + MLEM.Ui/Elements/Panel.cs | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d858345..1c7dbf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,7 @@ Improvements Fixes - Fixed paragraph links having incorrect hover locations when using special text alignments - Fixed the graphics device's viewport being ignored for mouse and touch queries +- Fixed auto-navigating panels not scrolling to the center of elements properly Removals - Marked StyleProp equality members as obsolete diff --git a/MLEM.Ui/Elements/Panel.cs b/MLEM.Ui/Elements/Panel.cs index c8914b4..072fb44 100644 --- a/MLEM.Ui/Elements/Panel.cs +++ b/MLEM.Ui/Elements/Panel.cs @@ -79,13 +79,13 @@ namespace MLEM.Ui.Elements { }; // handle automatic element selection, the scroller needs to scroll to the right location - this.OnSelectedElementChanged += (element, otherElement) => { + this.OnSelectedElementChanged += (_, e) => { if (!this.Controls.IsAutoNavMode) return; - if (otherElement == null || !otherElement.GetParentTree().Contains(this)) + if (e == null || !e.GetParentTree().Contains(this)) return; var firstChild = this.Children.First(c => c != this.ScrollBar); - this.ScrollBar.CurrentValue = (otherElement.Area.Bottom - firstChild.Area.Top - this.Area.Height / 2) / this.Scale; + this.ScrollBar.CurrentValue = (e.UnscrolledArea.Center.Y - firstChild.Area.Height - this.Area.Height / 2) / e.Scale + this.ChildPadding.Value.Height; }; this.AddChild(this.ScrollBar); }