From 23913b726a26839f5f33871743e18762d35b6e7b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 11 Nov 2024 17:41:10 +0900 Subject: [PATCH 1/2] Allow customising `ScrollContainer`'s scrollbar mapping For use in osu!. --- osu.Framework/Graphics/Containers/ScrollContainer.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Framework/Graphics/Containers/ScrollContainer.cs b/osu.Framework/Graphics/Containers/ScrollContainer.cs index eae4c968ee..e838aa683f 100644 --- a/osu.Framework/Graphics/Containers/ScrollContainer.cs +++ b/osu.Framework/Graphics/Containers/ScrollContainer.cs @@ -409,7 +409,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); /// /// Immediately offsets the current and target scroll position. @@ -576,12 +576,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; } } @@ -591,7 +591,7 @@ protected override void UpdateAfterChildren() /// /// The absolute scroll position (e.g. ). /// The scrollbar position. - private float toScrollbarPosition(float scrollPosition) + protected virtual float ToScrollbarPosition(float scrollPosition) { if (Precision.AlmostEquals(0, ScrollableExtent)) return 0; @@ -604,7 +604,7 @@ private float toScrollbarPosition(float scrollPosition) /// /// The scrollbar position. /// The absolute scroll position. - private float fromScrollbarPosition(float scrollbarPosition) + protected virtual float FromScrollbarPosition(float scrollbarPosition) { if (Precision.AlmostEquals(0, ScrollbarMovementExtent)) return 0; From 3bab44a584201ace24508a6d6a2177412110ba7f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 11 Nov 2024 19:08:52 +0900 Subject: [PATCH 2/2] Make `ScrollbarMovementExtent` `protected` --- osu.Framework/Graphics/Containers/ScrollContainer.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Framework/Graphics/Containers/ScrollContainer.cs b/osu.Framework/Graphics/Containers/ScrollContainer.cs index e838aa683f..dbd89fed1c 100644 --- a/osu.Framework/Graphics/Containers/ScrollContainer.cs +++ b/osu.Framework/Graphics/Containers/ScrollContainer.cs @@ -136,7 +136,10 @@ public bool ScrollbarOverlapsContent /// /// The maximum distance that the scrollbar can move in the scroll direction. /// - public float ScrollbarMovementExtent => Math.Max(DisplayableContent - Scrollbar.DrawSize[ScrollDim], 0); + /// + /// May not be accurate to actual display of scrollbar if or are overridden. + /// + protected float ScrollbarMovementExtent => Math.Max(DisplayableContent - Scrollbar.DrawSize[ScrollDim], 0); /// /// Clamp a value to the available scroll range.