Unverified Commit 2987d9e1 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Fix scrollbar margins (#107172)

parent c1846178
......@@ -211,8 +211,10 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
/// Mustn't be null.
final Animation<double> fadeoutOpacityAnimation;
/// Distance from the scrollbar's start and end to the edge of the viewport
/// in logical pixels. It affects the amount of available paint area.
/// Distance from the scrollbar thumb's start and end to the edge of the
/// viewport in logical pixels. It affects the amount of available paint area.
///
/// The scrollbar track consumes this space.
///
/// Mustn't be null and defaults to 0.
double get mainAxisMargin => _mainAxisMargin;
......@@ -230,6 +232,8 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
/// Distance from the scrollbar thumb to the nearest cross axis edge
/// in logical pixels.
///
/// The scrollbar track consumes this space.
///
/// Must not be null and defaults to 0.
double get crossAxisMargin => _crossAxisMargin;
double _crossAxisMargin;
......@@ -488,7 +492,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
trackSize = Size(thickness + 2 * crossAxisMargin, _trackExtent);
x = crossAxisMargin + padding.left;
y = _thumbOffset;
trackOffset = Offset(x - crossAxisMargin, mainAxisMargin + padding.top);
trackOffset = Offset(x - crossAxisMargin, padding.top);
borderStart = trackOffset + Offset(trackSize.width, 0.0);
borderEnd = Offset(trackOffset.dx + trackSize.width, trackOffset.dy + _trackExtent);
break;
......@@ -497,7 +501,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
trackSize = Size(thickness + 2 * crossAxisMargin, _trackExtent);
x = size.width - thickness - crossAxisMargin - padding.right;
y = _thumbOffset;
trackOffset = Offset(x - crossAxisMargin, mainAxisMargin + padding.top);
trackOffset = Offset(x - crossAxisMargin, padding.top);
borderStart = trackOffset;
borderEnd = Offset(trackOffset.dx, trackOffset.dy + _trackExtent);
break;
......@@ -506,7 +510,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
trackSize = Size(_trackExtent, thickness + 2 * crossAxisMargin);
x = _thumbOffset;
y = crossAxisMargin + padding.top;
trackOffset = Offset(mainAxisMargin + padding.left, y - crossAxisMargin);
trackOffset = Offset(padding.left, y - crossAxisMargin);
borderStart = trackOffset + Offset(0.0, trackSize.height);
borderEnd = Offset(trackOffset.dx + _trackExtent, trackOffset.dy + trackSize.height);
break;
......@@ -515,7 +519,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
trackSize = Size(_trackExtent, thickness + 2 * crossAxisMargin);
x = _thumbOffset;
y = size.height - thickness - crossAxisMargin - padding.bottom;
trackOffset = Offset(mainAxisMargin + padding.left, y - crossAxisMargin);
trackOffset = Offset(padding.left, y - crossAxisMargin);
borderStart = trackOffset;
borderEnd = Offset(trackOffset.dx + _trackExtent, trackOffset.dy);
break;
......@@ -564,12 +568,12 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
1.0);
final double thumbExtent = math.max(
math.min(_trackExtent, minOverscrollLength),
_trackExtent * fractionVisible,
math.min(_traversableTrackExtent, minOverscrollLength),
_traversableTrackExtent * fractionVisible,
);
final double fractionOverscrolled = 1.0 - _lastMetrics!.extentInside / _lastMetrics!.viewportDimension;
final double safeMinLength = math.min(minLength, _trackExtent);
final double safeMinLength = math.min(minLength, _traversableTrackExtent);
final double newMinLength = (_beforeExtent > 0 && _afterExtent > 0)
// Thumb extent is no smaller than minLength if scrolling normally.
? safeMinLength
......@@ -588,7 +592,8 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
// The `thumbExtent` should be no greater than `trackSize`, otherwise
// the scrollbar may scroll towards the wrong direction.
return clampDouble(thumbExtent, newMinLength, _trackExtent);
final double extent = clampDouble(thumbExtent, newMinLength, _traversableTrackExtent);
return extent;
}
@override
......@@ -604,8 +609,10 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
double get _afterExtent => _isReversed ? _lastMetrics!.extentBefore : _lastMetrics!.extentAfter;
// Padding of the thumb track.
double get _mainAxisPadding => _isVertical ? padding.vertical : padding.horizontal;
// The size of the thumb track.
double get _trackExtent => _lastMetrics!.viewportDimension - 2 * mainAxisMargin - _mainAxisPadding;
// The length of the painted track.
double get _trackExtent => _lastMetrics!.viewportDimension - _mainAxisPadding;
// The length of the track that is traversable by the thumb.
double get _traversableTrackExtent => _trackExtent - (2 * mainAxisMargin);
// The total size of the scrollable content.
double get _totalContentExtent {
......@@ -621,7 +628,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
double getTrackToScroll(double thumbOffsetLocal) {
assert(thumbOffsetLocal != null);
final double scrollableExtent = _lastMetrics!.maxScrollExtent - _lastMetrics!.minScrollExtent;
final double thumbMovableExtent = _trackExtent - _thumbExtent();
final double thumbMovableExtent = _traversableTrackExtent - _thumbExtent();
return scrollableExtent * thumbOffsetLocal / thumbMovableExtent;
}
......@@ -635,7 +642,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
? clampDouble((metrics.pixels - metrics.minScrollExtent) / scrollableExtent, 0.0, 1.0)
: 0;
return (_isReversed ? 1 - fractionPast : fractionPast) * (_trackExtent - thumbExtent);
return (_isReversed ? 1 - fractionPast : fractionPast) * (_traversableTrackExtent - thumbExtent);
}
@override
......@@ -647,7 +654,7 @@ class ScrollbarPainter extends ChangeNotifier implements CustomPainter {
}
// Skip painting if there's not enough space.
if (_lastMetrics!.viewportDimension <= _mainAxisPadding || _trackExtent <= 0) {
if (_lastMetrics!.viewportDimension <= _mainAxisPadding || _traversableTrackExtent <= 0) {
return;
}
......@@ -1342,15 +1349,20 @@ class RawScrollbar extends StatefulWidget {
/// {@macro flutter.widgets.Scrollbar.scrollbarOrientation}
final ScrollbarOrientation? scrollbarOrientation;
/// Distance from the scrollbar's start and end to the edge of the viewport
/// in logical pixels. It affects the amount of available paint area.
/// Distance from the scrollbar thumb's start or end to the nearest edge of
/// the viewport in logical pixels. It affects the amount of available
/// paint area.
///
/// The scrollbar track consumes this space.
///
/// Mustn't be null and defaults to 0.
final double mainAxisMargin;
/// Distance from the scrollbar thumb side to the nearest cross axis edge
/// Distance from the scrollbar thumb's side to the nearest cross axis edge
/// in logical pixels.
///
/// The scrollbar track consumes this space.
///
/// Must not be null and defaults to 0.
final double crossAxisMargin;
......
......@@ -1230,11 +1230,11 @@ void main() {
find.byType(CupertinoScrollbar),
paints
..rect(
rect: const Rect.fromLTRB(0.0, 3.0, 9.0, 597.0),
rect: const Rect.fromLTRB(0.0, 0.0, 9.0, 600.0),
)
..line(
p1: const Offset(9.0, 3.0),
p2: const Offset(9.0, 597.0),
p1: const Offset(9.0, 0.0),
p2: const Offset(9.0, 600.0),
strokeWidth: 1.0,
)
..rrect(
......
......@@ -179,12 +179,12 @@ void main() {
find.byType(Scrollbar),
paints
..rect(
rect: const Rect.fromLTRB(770.0, 10.0, 800.0, 590.0),
rect: const Rect.fromLTRB(770.0, 0.0, 800.0, 600.0),
color: const Color(0xff000000),
)
..line(
p1: const Offset(770.0, 10.0),
p2: const Offset(770.0, 590.0),
p1: const Offset(770.0, 00.0),
p2: const Offset(770.0, 600.0),
strokeWidth: 1.0,
color: const Color(0xffffeb3b),
)
......
......@@ -1779,7 +1779,7 @@ void main() {
expect(
find.byType(RawScrollbar),
paints
..rect(rect: const Rect.fromLTRB(794.0, 10.0, 800.0, 590.0))
..rect(rect: const Rect.fromLTRB(794.0, 0.0, 800.0, 600.0))
..rect(rect: const Rect.fromLTRB(794.0, 10.0, 800.0, 358.0))
);
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment