-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Knob Grabbing #2
Conversation
Uses calculateThumbLocation from the underlying BasicSliderUI to get an accurate location of the slider knobs, making them much easier to grab.
Hi Rowan, at first, thank you for your help,I really appretiate it. Unfortunately your changes broke thumb rendering (since RangeSliderUI extends BasicSliderUI). We must seach another solution. Best regards Andrey |
Hi Andrey, could you post an image of the issue? I have tested both Metal and GTK UI's and the thumbs render fine. If you want you could try my latest commit that simplifies the paint call a lot. smasher816@24d10c5 This is what it looks like for me: |
Hi Rowan, screenshot attached. I tried to debug it - it uses painting method from BasicSliderUI. Best regards Andrey Von: Rowan Decker [mailto:notifications@github.com] Hi Andrey, could you post an image of the issue? I have tested both Metal and GTK UI's and the thumbs render fine. If you want you could try my latest commit that simplifies the paint call a lot. smasher816@ smasher816@24d10c5 24d10c5 This is what it looks like for me: — |
Unfortunately I can't seem to find an attached image. I'm not sure if On Fri, Dec 18, 2015 at 1:42 PM, Andrey Kuznetsov notifications@github.com
|
Von: Rowan Decker [mailto:notifications@github.com] Unfortunately I can't seem to find an attached image. I'm not sure if On Fri, Dec 18, 2015 at 1:42 PM, Andrey Kuznetsov <notifications@github.com mailto:notifications@github.com >
— |
Hi Rowan, I found the solution. We need RangeSliderUI just for thumb calculations. So instead of slider.setUI() we call installUI(slider) and keep reference on it. Best regards Andrey Von: Rowan Decker [mailto:notifications@github.com] Unfortunately I can't seem to find an attached image. I'm not sure if On Fri, Dec 18, 2015 at 1:42 PM, Andrey Kuznetsov <notifications@github.com mailto:notifications@github.com >
— |
Thanks for this neat little library. I wanted to use a RangeSlider but JIDE was too big of a dependency for just one item and https://ernienotes.wordpress.com/2010/12/27/creating-a-java-swing-range-slider/ lacked features like ticks because of the custom ui. Yours fit the bill nicely. It's a shame more people have not found it 👍
Unfortunately in my testing I found that grabbing the knobs was very awkward. With the default parameters the range was way too small, forcing you to put your cursor towards the inside of the handles. If you put it in the middle or towards the outside your grabs would be ignored. I tried tweaking the constants in mouseMoved but ended up with strange results. With larger values you could grab the knobs past their rendered image on the outer sides, yet still not be able to grab the very inner images. It was clear there was some issue with the math/scaling not centering around the knobs correctly.
On a hunt for clues I looked at BasicSliderUI to see how they determined if a knob was grabbed. It turns out that they use rectangle clipping detection to check if the mouse is over the image. Unfortunately the rectangles it was using were protected and unable to be accessed from your code. However, by using a custom subclass of BasicSliderUI I made a public function to access the protected variable. With access to these variables checking for the various states became trivial.
With these changes grabbing the knobs works perfectly both horizontally and vertically. In my mind not using magic constants is a good thing; what if swing changed their images to a larger one? Suddenly the old acceptable range of '3' would be even more broken. With the rectangle clipping this issue is no longer present.
I hope this change helps you (future) others.