controlsfx icon indicating copy to clipboard operation
controlsfx copied to clipboard

Is it possible to get the x/y position of range slider thumbs without using CSS lookup to find the nodes?

Open QuigonJohnn opened this issue 10 months ago • 0 comments

I have two floating popups/tooltips that follow the position of the low and high thumbs when dragged. This currently works perfectly using the x/y location of the thumbs and offsetting from there. But I want to move away from the lookup method and there doesn't appear to be a way to find the thumb positions without it.

Node highThumb = slider.lookup(".high-thumb"); Node lowThumb = slider.lookup(".low-thumb");

Bounds hBounds = highThumb.getBoundsInLocal(); Bounds lBounds = lowThumb.getBoundsInLocal(); Bounds tBounds = slider.getBoundsInLocal();

double xHigh = highThumb.localToScreen(hBounds.getMinX(), hBounds.getMinY()).getX() + 10; double xLow = lowThumb.localToScreen(lBounds.getMaxX(), lBounds.getMaxY()).getX() - 10; double y = slider.localToScreen(tBounds.getMaxX(), tBounds.getMaxY()).getY() + 15;

Image

The solution I'm working on is to take the slider low/high value vs max value as a percentage of its length, and then offset from the slider's minX/maxX accordingly

double minX = slider.localToScreen(slider.getBoundsInLocal()).getMinX(); double maxX = slider.localToScreen(slider.getBoundsInLocal()).getMaxX(); double length = maxX - minX;

double sLow = slider.getLowValue(); double sHigh = slider.getHighValue(); double sMax = slider.getMax();

double xL2 = minX + ((sLow / sMax) * length) + 10; //double xH2 = minX + ((sHigh / sMax) * length) + 10; double xH2 = maxX - (((sMax - sHigh ) / sMax) * length) - 10;

This produces a very similar result, but is only accurate right at the edges of the slider. There is some drifting that occurs when the thumbs are closer to the middle, that I have so far been unable to solve.

Image

Image

Image

the drift is different depending on which side I use as the reference:

Image

Is there a better way to do this? Or is there some other way to access the x/y positions of the thumbs without using CSS lookup?

QuigonJohnn avatar Feb 20 '25 03:02 QuigonJohnn