Skip to content

Commit

Permalink
Merge pull request #6415 from peppy/expose-scroll-container-things
Browse files Browse the repository at this point in the history
Allow customising `ScrollContainer`'s scrollbar mapping
  • Loading branch information
bdach authored Nov 11, 2024
2 parents f3bdd4e + 3bab44a commit 109df77
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions osu.Framework/Graphics/Containers/ScrollContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ public bool ScrollbarOverlapsContent
/// <summary>
/// The maximum distance that the scrollbar can move in the scroll direction.
/// </summary>
public float ScrollbarMovementExtent => Math.Max(DisplayableContent - Scrollbar.DrawSize[ScrollDim], 0);
/// <remarks>
/// May not be accurate to actual display of scrollbar if <see cref="ToScrollbarPosition"/> or <see cref="FromScrollbarPosition"/> are overridden.
/// </remarks>
protected float ScrollbarMovementExtent => Math.Max(DisplayableContent - Scrollbar.DrawSize[ScrollDim], 0);

/// <summary>
/// Clamp a value to the available scroll range.
Expand Down Expand Up @@ -409,7 +412,7 @@ protected override bool OnScroll(ScrollEvent e)
return true;
}

private void onScrollbarMovement(float value) => OnUserScroll(Clamp(fromScrollbarPosition(value)), false);
private void onScrollbarMovement(float value) => OnUserScroll(Clamp(FromScrollbarPosition(value)), false);

/// <summary>
/// Immediately offsets the current and target scroll position.
Expand Down Expand Up @@ -576,12 +579,12 @@ protected override void UpdateAfterChildren()

if (ScrollDirection == Direction.Horizontal)
{
Scrollbar.X = toScrollbarPosition(Current);
Scrollbar.X = ToScrollbarPosition(Current);
ScrollContent.X = -Current + ScrollableExtent * ScrollContent.RelativeAnchorPosition.X;
}
else
{
Scrollbar.Y = toScrollbarPosition(Current);
Scrollbar.Y = ToScrollbarPosition(Current);
ScrollContent.Y = -Current + ScrollableExtent * ScrollContent.RelativeAnchorPosition.Y;
}
}
Expand All @@ -591,7 +594,7 @@ protected override void UpdateAfterChildren()
/// </summary>
/// <param name="scrollPosition">The absolute scroll position (e.g. <see cref="Current"/>).</param>
/// <returns>The scrollbar position.</returns>
private float toScrollbarPosition(float scrollPosition)
protected virtual float ToScrollbarPosition(float scrollPosition)
{
if (Precision.AlmostEquals(0, ScrollableExtent))
return 0;
Expand All @@ -604,7 +607,7 @@ private float toScrollbarPosition(float scrollPosition)
/// </summary>
/// <param name="scrollbarPosition">The scrollbar position.</param>
/// <returns>The absolute scroll position.</returns>
private float fromScrollbarPosition(float scrollbarPosition)
protected virtual float FromScrollbarPosition(float scrollbarPosition)
{
if (Precision.AlmostEquals(0, ScrollbarMovementExtent))
return 0;
Expand Down

0 comments on commit 109df77

Please sign in to comment.