2011-04-21 18:22:03 |
Ryan Pedersen |
description |
I am implementing the CoolSlider in one of my projects as a custom slider control and noticed that sometimes the button is inconsistent on where it is positioned depending on the last position it was at. This could have something to do with the size of my images but after a lot of experimentation I was unable to come up with anything to prevent the issue. After digging in the code I found that if I added a line of code to doMoveThumbHorizontally which would exit if the width variable was 0 the problem went away (shown below).
Information on my CoolSlider:
CoolSlider constructor parameters:
dimensions of leftmost image - 96x42
dimensions of left image - 96x42
dimensions of thumbImageNormal image - 42x42
dimensions of thumbImageHover image - 42x42
dimensions of thumbImagePressed image - 42x42
dimensions of right image - 96x42
dimensions of rightmost image - 96x42
snapValues:
max = 768
min = 0
increment = 96
I also call setBounds with the following parameters: (40, 104, 768, 64)
New code starts at "if (width == 0){" and ends at "else if(width < 0){":
private void doMoveThumbHorizontally(double x, boolean update){
int width = (int)x - thumb.getBounds().width/2 - leftmostRegion.getBounds().width;
if(width > getClientArea().width-thumb.getBounds().width-rightmostRegion.getBounds().width){
width = getClientArea().width-thumb.getBounds().width-rightmostRegion.getBounds().width;
}
if (width == 0){
// button hasn't moved so exit
return;
}
else if(width < 0){
int mW = leftmostRegion.getBounds().width + width;
if(mW < 0){
mW = 0;
}
leftmostRegion.updatePosition(mW);
width = 0;
}else{
leftmostRegion.resetToDefault();
}
leftRegion.updatePosition(width);
layout();
if(update){
double percentage = x/(getClientArea().width);
if(snapStyle){
percentage = Math.round((maximum-minimum)*percentage)+minimum;
}else{
percentage = (leftmostRegion.getBounds().width+leftRegion.getBounds().width*1.0)
/(getClientArea().width-thumb.getBounds().width);
}
updateTooltipMoving(percentage);
updatePostionListeners(percentage);
previousPosition = percentage;
}
}
Overall the control has worked great, thanks for your hard work on this project. |
I am implementing the CoolSlider in one of my projects as a custom slider control and noticed that sometimes the button is inconsistent on where it is positioned depending on the last position it was at. This could have something to do with the size of my images but after a lot of experimentation I was unable to come up with anything to prevent the issue. After digging in the code I found that if I added a line of code to doMoveThumbHorizontally which would exit if the width variable was 0 the problem went away (shown below).
Information on my CoolSlider:
CoolSlider constructor parameters:
dimensions of leftmost image - 96x42
dimensions of left image - 96x42
dimensions of thumbImageNormal image - 42x42
dimensions of thumbImageHover image - 42x42
dimensions of thumbImagePressed image - 42x42
dimensions of right image - 96x42
dimensions of rightmost image - 96x42
snapValues:
max = 768
min = 0
increment = 96
I also call setBounds with the following parameters: (40, 104, 768, 64)
New code starts at "if (width == 0){" and ends at "else if(width < 0){":
private void doMoveThumbHorizontally(double x, boolean update){
int width = (int)x - thumb.getBounds().width/2 - leftmostRegion.getBounds().width;
if(width > getClientArea().width-thumb.getBounds().width-rightmostRegion.getBounds().width){
width = getClientArea().width-thumb.getBounds().width-rightmostRegion.getBounds().width;
}
if (width == 0){
// button hasn't moved so exit
return;
}
else if(width < 0){
int mW = leftmostRegion.getBounds().width + width;
if(mW < 0){
mW = 0;
}
leftmostRegion.updatePosition(mW);
width = 0;
}else{
leftmostRegion.resetToDefault();
}
leftRegion.updatePosition(width);
layout();
if(update){
double percentage = x/(getClientArea().width);
if(snapStyle){
percentage = Math.round((maximum-minimum)*percentage)+minimum;
}else{
percentage = (leftmostRegion.getBounds().width+leftRegion.getBounds().width*1.0)
/(getClientArea().width-thumb.getBounds().width);
}
updateTooltipMoving(percentage);
updatePostionListeners(percentage);
previousPosition = percentage;
}
}
Overall the control has worked great, thanks for your hard work on this project. |
|