Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customising ScrollContainer's scrollbar mapping #6415

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading