Skip to content

Commit

Permalink
Reduce scroll noise (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jugen committed Aug 28, 2020
1 parent 0d0ed41 commit 1314a20
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/main/java/org/fxmisc/flowless/SizeTracker.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.fxmisc.flowless;

import java.time.Duration;
import java.util.Optional;
import java.util.function.Function;

import javafx.beans.value.ObservableObjectValue;
import javafx.geometry.Bounds;
import javafx.scene.control.IndexRange;

import org.reactfx.EventStreams;
import org.reactfx.Subscription;
import org.reactfx.collection.LiveList;
import org.reactfx.collection.MemoizationList;
Expand Down Expand Up @@ -117,11 +119,15 @@ public SizeTracker(

Val<Double> firstCellMinY = firstVisibleCell.flatMap(orientation::minYProperty);

lengthOffsetEstimate = Val.combine(
totalKnownLengthBeforeFirstVisibleCell,
unknownLengthEstimateBeforeFirstVisibleCell,
firstCellMinY,
(a, b, minY) -> a + b - minY).orElseConst(0.0);
lengthOffsetEstimate = Val.wrap( EventStreams.combine(
totalKnownLengthBeforeFirstVisibleCell.values(),
unknownLengthEstimateBeforeFirstVisibleCell.values(),
firstCellMinY.values()
)
.filter( t3 -> t3.test( (a,b,minY) -> a != null && b != null && minY != null ) )
.thenRetainLatestFor( Duration.ofMillis( 1 ) )
.map( t3 -> t3.map( (a,b,minY) -> Double.valueOf( a + b - minY ) ) )
.toBinding( 0.0 ) );

// pinning totalLengthEstimate and lengthOffsetEstimate
// binds it all together and enables memoization
Expand Down

0 comments on commit 1314a20

Please sign in to comment.