Skip to content

Commit 1f528bb

Browse files
authored
Fix scrollbars not showing early enough when content has padding (v2) (#117)
1 parent a4f0323 commit 1f528bb

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/main/java/org/fxmisc/flowless/VirtualizedScrollPane.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,21 @@ public VirtualizedScrollPane(
7979
hbar.blockIncrementProperty().bind(hbar.visibleAmountProperty());
8080
vbar.blockIncrementProperty().bind(vbar.visibleAmountProperty());
8181

82+
Val<Double> hContentPadding = Val.map(content.paddingProperty(), p -> p.getLeft() + p.getRight());
83+
Val<Double> vContentPadding = Val.map(content.paddingProperty(), p -> p.getTop() + p.getBottom());
84+
8285
// scrollbar positions
8386
hPosEstimate = Val.combine(
8487
content.estimatedScrollXProperty(),
8588
Val.map(content.layoutBoundsProperty(), Bounds::getWidth),
86-
Val.map(content.paddingProperty(), p -> p.getLeft() + p.getRight()),
89+
hContentPadding,
8790
content.totalWidthEstimateProperty(),
8891
VirtualizedScrollPane::offsetToScrollbarPosition)
8992
.asVar(this::setHPosition);
9093
vPosEstimate = Val.combine(
9194
content.estimatedScrollYProperty(),
9295
Val.map(content.layoutBoundsProperty(), Bounds::getHeight),
93-
Val.map(content.paddingProperty(), p -> p.getTop() + p.getBottom()),
96+
vContentPadding,
9497
content.totalHeightEstimateProperty(),
9598
VirtualizedScrollPane::offsetToScrollbarPosition)
9699
.orElseConst(0.0)
@@ -128,28 +131,30 @@ public VirtualizedScrollPane(
128131
Val<Double> layoutHeight = Val.map(layoutBoundsProperty(), Bounds::getHeight);
129132
Val<Boolean> needsHBar0 = Val.combine(
130133
content.totalWidthEstimateProperty(),
131-
content.paddingProperty(),
134+
hContentPadding,
132135
layoutWidth,
133-
(cw, cp, lw) -> cw + cp.getLeft() + cp.getRight() > lw);
136+
(cw, hcp, lw) -> cw + hcp > lw);
134137
Val<Boolean> needsVBar0 = Val.combine(
135138
content.totalHeightEstimateProperty(),
136-
content.paddingProperty(),
139+
vContentPadding,
137140
layoutHeight,
138-
(ch, cp, lh) -> ch + cp.getTop() + cp.getBottom() > lh);
141+
(ch, vcp, lh) -> ch + vcp > lh);
139142
Val<Boolean> needsHBar = Val.combine(
140143
needsHBar0,
141144
needsVBar0,
142145
content.totalWidthEstimateProperty(),
146+
hContentPadding,
143147
vbar.widthProperty(),
144148
layoutWidth,
145-
(needsH, needsV, cw, vbw, lw) -> needsH || needsV && cw + vbw.doubleValue() > lw);
149+
(needsH, needsV, cw, hcp, vbw, lw) -> needsH || needsV && cw + hcp + vbw.doubleValue() > lw);
146150
Val<Boolean> needsVBar = Val.combine(
147151
needsVBar0,
148152
needsHBar0,
149153
content.totalHeightEstimateProperty(),
154+
vContentPadding,
150155
hbar.heightProperty(),
151156
layoutHeight,
152-
(needsV, needsH, ch, hbh, lh) -> needsV || needsH && ch + hbh.doubleValue() > lh);
157+
(needsV, needsH, ch, vcp, hbh, lh) -> needsV || needsH && ch + vcp + hbh.doubleValue() > lh);
153158

154159
Val<Boolean> shouldDisplayHorizontal = Val.flatMap(hbarPolicy, policy -> {
155160
switch (policy) {

0 commit comments

Comments
 (0)