135 /** {@inheritDoc} */ 136 @Override protected void layoutChildren(final double x, final double y, 137 final double w, final double h) { 138 139 final ScrollBar s = getSkinnable(); 140 141 /** 142 * Compute the percentage length of thumb as (visibleAmount/range) 143 * if max isn't greater than min then there is nothing to do here 144 */ 145 double visiblePortion; 146 if (s.getMax() > s.getMin()) { 147 visiblePortion = s.getVisibleAmount()/(s.getMax() - s.getMin()); 148 } 149 else { 150 visiblePortion = 1.0; 151 } 152 153 if (s.getOrientation() == Orientation.VERTICAL) { 154 if (!Properties.IS_TOUCH_SUPPORTED) { 155 double decHeight = snapSize(decButton.prefHeight(-1)); 156 double incHeight = snapSize(incButton.prefHeight(-1)); 157 158 decButton.resize(w, decHeight); 159 incButton.resize(w, incHeight); 160 161 trackLength = snapSize(h - (decHeight + incHeight)); 162 thumbLength = snapSize(Utils.clamp(minThumbLength(), (trackLength * visiblePortion), trackLength)); 163 164 trackBackground.resizeRelocate(snapPosition(x), snapPosition(y), w, trackLength+decHeight+incHeight); 165 decButton.relocate(snapPosition(x), snapPosition(y)); 166 incButton.relocate(snapPosition(x), snapPosition(y + h - incHeight)); 167 track.resizeRelocate(snapPosition(x), snapPosition(y + decHeight), w, trackLength); 168 thumb.resize(snapSize(x >= 0 ? w : w + x), thumbLength); // Account for negative padding (see also RT-10719) 169 positionThumb(); 170 } 171 else { 172 trackLength = snapSize(h); 173 thumbLength = snapSize(Utils.clamp(minThumbLength(), (trackLength * visiblePortion), trackLength)); 174 175 track.resizeRelocate(snapPosition(x), snapPosition(y), w, trackLength); 176 thumb.resize(snapSize(x >= 0 ? w : w + x), thumbLength); // Account for negative padding (see also RT-10719) 177 positionThumb(); 178 } 179 } else { 180 if (!Properties.IS_TOUCH_SUPPORTED) { 181 double decWidth = snapSize(decButton.prefWidth(-1)); 182 double incWidth = snapSize(incButton.prefWidth(-1)); 183 184 decButton.resize(decWidth, h); 185 incButton.resize(incWidth, h); 186 187 trackLength = snapSize(w - (decWidth + incWidth)); 188 thumbLength = snapSize(Utils.clamp(minThumbLength(), (trackLength * visiblePortion), trackLength)); 189 190 trackBackground.resizeRelocate(snapPosition(x), snapPosition(y), trackLength+decWidth+incWidth, h); 191 decButton.relocate(snapPosition(x), snapPosition(y)); 192 incButton.relocate(snapPosition(x + w - incWidth), snapPosition(y)); 193 track.resizeRelocate(snapPosition(x + decWidth), snapPosition(y), trackLength, h); 194 thumb.resize(thumbLength, snapSize(y >= 0 ? h : h + y)); // Account for negative padding (see also RT-10719) 195 positionThumb(); 196 } 197 else { 198 trackLength = snapSize(w); 199 thumbLength = snapSize(Utils.clamp(minThumbLength(), (trackLength * visiblePortion), trackLength)); 200 201 track.resizeRelocate(snapPosition(x), snapPosition(y), trackLength, h); 202 thumb.resize(thumbLength, snapSize(y >= 0 ? h : h + y)); // Account for negative padding (see also RT-10719) 203 positionThumb(); 204 } 205 206 s.resize(snapSize(s.getWidth()), snapSize(s.getHeight())); 207 } 208 209 // things should be invisible only when well below minimum length 210 if (s.getOrientation() == Orientation.VERTICAL && h >= (computeMinHeight(-1, (int)y , snappedRightInset(), snappedBottomInset(), (int)x) - (y+snappedBottomInset())) || 211 s.getOrientation() == Orientation.HORIZONTAL && w >= (computeMinWidth(-1, (int)y , snappedRightInset(), snappedBottomInset(), (int)x) - (x+snappedRightInset()))) { 212 trackBackground.setVisible(true); 213 track.setVisible(true); 214 thumb.setVisible(true); 215 if (!Properties.IS_TOUCH_SUPPORTED) { 216 incButton.setVisible(true); 217 decButton.setVisible(true); 218 } 219 } 220 else { 221 trackBackground.setVisible(false); 222 track.setVisible(false); 223 thumb.setVisible(false); 224 225 if (!Properties.IS_TOUCH_SUPPORTED) { 226 /* 599 double minTrackLength() { 600 return 2.0f * getBreadth(); 601 } 602 603 /** 604 * Called when ever either min, max or value changes, so thumb's layoutX, Y is recomputed. 605 */ 606 void positionThumb() { 607 ScrollBar s = getSkinnable(); 608 double clampedValue = Utils.clamp(s.getMin(), s.getValue(), s.getMax()); 609 trackPos = (s.getMax() - s.getMin() > 0) ? ((trackLength - thumbLength) * (clampedValue - s.getMin()) / (s.getMax() - s.getMin())) : (0.0F); 610 611 if (!Properties.IS_TOUCH_SUPPORTED) { 612 if (s.getOrientation() == Orientation.VERTICAL) { 613 trackPos += decButton.prefHeight(-1); 614 } else { 615 trackPos += decButton.prefWidth(-1); 616 } 617 } 618 619 thumb.setTranslateX( snapPosition(s.getOrientation() == Orientation.VERTICAL ? snappedLeftInset() : trackPos + snappedLeftInset())); 620 thumb.setTranslateY( snapPosition(s.getOrientation() == Orientation.VERTICAL ? trackPos + snappedTopInset() : snappedTopInset())); 621 } 622 623 private Node getThumb() { 624 return thumb; 625 } 626 627 private Node getTrack() { 628 return track; 629 } 630 631 private Node getIncrementButton() { 632 return incButton; 633 } 634 635 private Node getDecrementButton() { 636 return decButton; 637 } 638 639 640 | 135 /** {@inheritDoc} */ 136 @Override protected void layoutChildren(final double x, final double y, 137 final double w, final double h) { 138 139 final ScrollBar s = getSkinnable(); 140 141 /** 142 * Compute the percentage length of thumb as (visibleAmount/range) 143 * if max isn't greater than min then there is nothing to do here 144 */ 145 double visiblePortion; 146 if (s.getMax() > s.getMin()) { 147 visiblePortion = s.getVisibleAmount()/(s.getMax() - s.getMin()); 148 } 149 else { 150 visiblePortion = 1.0; 151 } 152 153 if (s.getOrientation() == Orientation.VERTICAL) { 154 if (!Properties.IS_TOUCH_SUPPORTED) { 155 double decHeight = snapSizeY(decButton.prefHeight(-1)); 156 double incHeight = snapSizeY(incButton.prefHeight(-1)); 157 158 decButton.resize(w, decHeight); 159 incButton.resize(w, incHeight); 160 161 trackLength = snapSizeY(h - (decHeight + incHeight)); 162 thumbLength = snapSizeY(Utils.clamp(minThumbLength(), (trackLength * visiblePortion), trackLength)); 163 164 trackBackground.resizeRelocate(snapPositionX(x), snapPositionY(y), w, trackLength+decHeight+incHeight); 165 decButton.relocate(snapPositionX(x), snapPositionY(y)); 166 incButton.relocate(snapPositionX(x), snapPositionY(y + h - incHeight)); 167 track.resizeRelocate(snapPositionX(x), snapPositionY(y + decHeight), w, trackLength); 168 thumb.resize(snapSizeX(x >= 0 ? w : w + x), thumbLength); // Account for negative padding (see also RT-10719) 169 positionThumb(); 170 } 171 else { 172 trackLength = snapSizeY(h); 173 thumbLength = snapSizeY(Utils.clamp(minThumbLength(), (trackLength * visiblePortion), trackLength)); 174 175 track.resizeRelocate(snapPositionX(x), snapPositionY(y), w, trackLength); 176 thumb.resize(snapSizeX(x >= 0 ? w : w + x), thumbLength); // Account for negative padding (see also RT-10719) 177 positionThumb(); 178 } 179 } else { 180 if (!Properties.IS_TOUCH_SUPPORTED) { 181 double decWidth = snapSizeX(decButton.prefWidth(-1)); 182 double incWidth = snapSizeX(incButton.prefWidth(-1)); 183 184 decButton.resize(decWidth, h); 185 incButton.resize(incWidth, h); 186 187 trackLength = snapSizeX(w - (decWidth + incWidth)); 188 thumbLength = snapSizeX(Utils.clamp(minThumbLength(), (trackLength * visiblePortion), trackLength)); 189 190 trackBackground.resizeRelocate(snapPositionX(x), snapPositionY(y), trackLength+decWidth+incWidth, h); 191 decButton.relocate(snapPositionX(x), snapPositionY(y)); 192 incButton.relocate(snapPositionX(x + w - incWidth), snapPositionY(y)); 193 track.resizeRelocate(snapPositionX(x + decWidth), snapPositionY(y), trackLength, h); 194 thumb.resize(thumbLength, snapSizeY(y >= 0 ? h : h + y)); // Account for negative padding (see also RT-10719) 195 positionThumb(); 196 } 197 else { 198 trackLength = snapSizeX(w); 199 thumbLength = snapSizeX(Utils.clamp(minThumbLength(), (trackLength * visiblePortion), trackLength)); 200 201 track.resizeRelocate(snapPositionX(x), snapPositionY(y), trackLength, h); 202 thumb.resize(thumbLength, snapSizeY(y >= 0 ? h : h + y)); // Account for negative padding (see also RT-10719) 203 positionThumb(); 204 } 205 206 s.resize(snapSizeX(s.getWidth()), snapSizeY(s.getHeight())); 207 } 208 209 // things should be invisible only when well below minimum length 210 if (s.getOrientation() == Orientation.VERTICAL && h >= (computeMinHeight(-1, (int)y , snappedRightInset(), snappedBottomInset(), (int)x) - (y+snappedBottomInset())) || 211 s.getOrientation() == Orientation.HORIZONTAL && w >= (computeMinWidth(-1, (int)y , snappedRightInset(), snappedBottomInset(), (int)x) - (x+snappedRightInset()))) { 212 trackBackground.setVisible(true); 213 track.setVisible(true); 214 thumb.setVisible(true); 215 if (!Properties.IS_TOUCH_SUPPORTED) { 216 incButton.setVisible(true); 217 decButton.setVisible(true); 218 } 219 } 220 else { 221 trackBackground.setVisible(false); 222 track.setVisible(false); 223 thumb.setVisible(false); 224 225 if (!Properties.IS_TOUCH_SUPPORTED) { 226 /* 599 double minTrackLength() { 600 return 2.0f * getBreadth(); 601 } 602 603 /** 604 * Called when ever either min, max or value changes, so thumb's layoutX, Y is recomputed. 605 */ 606 void positionThumb() { 607 ScrollBar s = getSkinnable(); 608 double clampedValue = Utils.clamp(s.getMin(), s.getValue(), s.getMax()); 609 trackPos = (s.getMax() - s.getMin() > 0) ? ((trackLength - thumbLength) * (clampedValue - s.getMin()) / (s.getMax() - s.getMin())) : (0.0F); 610 611 if (!Properties.IS_TOUCH_SUPPORTED) { 612 if (s.getOrientation() == Orientation.VERTICAL) { 613 trackPos += decButton.prefHeight(-1); 614 } else { 615 trackPos += decButton.prefWidth(-1); 616 } 617 } 618 619 thumb.setTranslateX( snapPositionX(s.getOrientation() == Orientation.VERTICAL ? snappedLeftInset() : trackPos + snappedLeftInset())); 620 thumb.setTranslateY( snapPositionY(s.getOrientation() == Orientation.VERTICAL ? trackPos + snappedTopInset() : snappedTopInset())); 621 } 622 623 private Node getThumb() { 624 return thumb; 625 } 626 627 private Node getTrack() { 628 return track; 629 } 630 631 private Node getIncrementButton() { 632 return incButton; 633 } 634 635 private Node getDecrementButton() { 636 return decButton; 637 } 638 639 640 |