Coolslider button positioning is inconsistent

Bug #768451 reported by Ryan Pedersen on 2011-04-21
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
RCP Toolbox
Medium
Unassigned

Bug 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.

Related branches

Ryan Pedersen (ryan-pedersen) wrote :

Thanks for logging the bug...
Looking at the code again scares me ... I have to suppress the urge to re-write it all :(

Anyway ... I'll submit your change, I also added the same fix to the doMoveThumbVertically(...) .

BTW: Launchpad as a really neat code review feature, if you use bazaar to propose a merge for your change ...

Changed in rcptoolbox:
status: New → Fix Committed
importance: Undecided → Medium
assignee: nobody → Craig Hewetson (craighewetson)
description: updated
Ryan Pedersen (ryan-pedersen) wrote :

Thanks for the quick turn around on this. I wanted to be sure that this change didn't mess things up on smooth_style but unfortunately it did cause some issues when moving the button near the same place where the problem occurred for me on snap style. I'm pretty sure it has to do with calculating the width of the end tiles but couldn't pinpoint a solution. There probably needs to be a deeper investigation but I will use the version 1.0.9 since that seems to work for the way I am using it.

-Ryan

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers