Unverified Commit 5235a0f0 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Add ScrollMetrics.extentTotal for completeness (#126607)

When implementing scrollbars, I found that it would be useful and idiomatic to be able to do `m.extentInside / m.extentTotal` to get the scrollbar thumb size.
parent 25a9efe9
...@@ -115,11 +115,12 @@ mixin ScrollMetrics { ...@@ -115,11 +115,12 @@ mixin ScrollMetrics {
/// This is the content above the content described by [extentInside]. /// This is the content above the content described by [extentInside].
double get extentBefore => math.max(pixels - minScrollExtent, 0.0); double get extentBefore => math.max(pixels - minScrollExtent, 0.0);
/// The quantity of content conceptually "inside" the viewport in the scrollable. /// The quantity of content conceptually "inside" the viewport in the
/// scrollable (including empty space if the total amount of content is less
/// than the [viewportDimension]).
/// ///
/// The value is typically the height of the viewport when [outOfRange] is false. /// The value is typically the extent of the viewport ([viewportDimension])
/// It could be less if there is less content visible than the size of the /// when [outOfRange] is false. It can be less when overscrolling.
/// viewport, such as when overscrolling.
/// ///
/// The value is always non-negative, and less than or equal to [viewportDimension]. /// The value is always non-negative, and less than or equal to [viewportDimension].
double get extentInside { double get extentInside {
...@@ -135,6 +136,12 @@ mixin ScrollMetrics { ...@@ -135,6 +136,12 @@ mixin ScrollMetrics {
/// This is the content below the content described by [extentInside]. /// This is the content below the content described by [extentInside].
double get extentAfter => math.max(maxScrollExtent - pixels, 0.0); double get extentAfter => math.max(maxScrollExtent - pixels, 0.0);
/// The total quantity of content available.
///
/// This is the sum of [extentBefore], [extentInside], and [extentAfter], modulo
/// any rounding errors.
double get extentTotal => maxScrollExtent - minScrollExtent + viewportDimension;
/// The [FlutterView.devicePixelRatio] of the view that the [Scrollable] /// The [FlutterView.devicePixelRatio] of the view that the [Scrollable]
/// associated with this metrics object is drawn into. /// associated with this metrics object is drawn into.
double get devicePixelRatio; double get devicePixelRatio;
......
...@@ -31,6 +31,7 @@ void main() { ...@@ -31,6 +31,7 @@ void main() {
expect(event.metrics.extentBefore, 0.0); expect(event.metrics.extentBefore, 0.0);
expect(event.metrics.extentInside, 600.0); expect(event.metrics.extentInside, 600.0);
expect(event.metrics.extentAfter, 400.0); expect(event.metrics.extentAfter, 400.0);
expect(event.metrics.extentTotal, 1000.0);
events.clear(); events.clear();
final TestGesture gesture = await tester.startGesture(const Offset(100.0, 100.0)); final TestGesture gesture = await tester.startGesture(const Offset(100.0, 100.0));
...@@ -53,6 +54,7 @@ void main() { ...@@ -53,6 +54,7 @@ void main() {
expect(event.metrics.extentBefore, 10.0); expect(event.metrics.extentBefore, 10.0);
expect(event.metrics.extentInside, 590.0); expect(event.metrics.extentInside, 590.0);
expect(event.metrics.extentAfter, 0.0); expect(event.metrics.extentAfter, 0.0);
expect(event.metrics.extentTotal, 600.0);
events.clear(); events.clear();
// The content dimensions does not change. // The content dimensions does not change.
......
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