Adjust scroll behaviour to feel better

This commit is contained in:
Dean Herbert 2021-08-20 17:40:56 +09:00
parent 2d19f37dc6
commit 03e6ca5ba9
1 changed files with 15 additions and 3 deletions

View File

@ -112,7 +112,7 @@ public Drawable HeaderBackground
/// <summary>
/// The percentage of the container to consider the centre-point for deciding the active section (and scrolling to a requested section).
/// </summary>
private const float scroll_y_centre = 0.2f;
private const float scroll_y_centre = 0.1f;
public SectionsContainer()
{
@ -147,10 +147,22 @@ public override void Add(T drawable)
public void ScrollTo(Drawable target)
{
lastKnownScroll = null;
float fixedHeaderSize = FixedHeader?.BoundingBox.Height ?? 0;
// implementation similar to ScrollIntoView but a bit more nuanced.
float top = scrollContainer.GetChildPosInContent(target);
var bottomScrollExtent = scrollContainer.ScrollableExtent - fixedHeaderSize;
if (top > bottomScrollExtent)
scrollContainer.ScrollToEnd();
else
scrollContainer.ScrollTo(top - fixedHeaderSize - scrollContainer.DisplayableContent * scroll_y_centre);
if (target is T section)
lastClickedSection = section;
scrollContainer.ScrollTo(scrollContainer.GetChildPosInContent(target) - scrollContainer.DisplayableContent * scroll_y_centre - (FixedHeader?.BoundingBox.Height ?? 0));
}
public void ScrollToTop() => scrollContainer.ScrollTo(0);