LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

set active slider

Solved!
Go to solution

Hello,

 

I am using a slider control with two sliders.  Clicking on the control moves the active slider to the location where you clicked (normal behavior).  My question is:  Can I check where the mouse click occured, set the active slider to the closest one, and move that one?

 

For reference, here is an example sequence of the behavior that I would want.

 

Sliders are at 10 and 100.

Move slider 1 from 100 to 160 (Slider 1 is the active slider)

Click near 5.

At this point, I would like for slider 2 to move to 5 from 10.  Instead, it is slider 1 that moves since it is currently the active slider.

 

Any ideas on how this desired behavior can be achieved?  I think I may be able to do it which some, rather poorly designed, code using a feedback loop and a lot of comparisons.  This would compare the new value to the previous two slider values, and forcefully set them so the slider which "was closer" is the one that moves.

 

I think this might work, but it seems really sloppy to me and I am hopping there is a better way.

0 Kudos
Message 1 of 8
(3,950 Views)

Hi,

 

You could use event driven approach to record clicks and activate sliders.  

 

Not sure what you mean by "click near 5".  Is that click near 5 on the first or second slider, or some other control, to change the value of the second slider?

 

You could always measure the distance from a click point to a controls location, to determine which is closest, but that would involve a lot of property nodes to compare locations ( or could store the control locations at start).

 

You question sounds plausible, but there is a lot of grey area, for example, how did the app know the second click is for the second slider, etc...

-------
Mark Ramsdale
-------
0 Kudos
Message 2 of 8
(3,945 Views)

" for example, how did the app know the second click is for the second slider, etc..."

 

This is exactly what I am trying to force it to do.  As you know, with a slider control, there are two ways of moving the slider.  You can click and drag the slider itself, or you can click on the control.  Clicking on the slider control will cause the slider to Jump to that new value.  If there is more than one slider on a single control, it is the "active" slider which moves.

 

I am trying to come up with a way to circumvent this behavior, as I do not want the "active" slider to be the one to move.  Instead, I want the slider which is closer to the final destination to move.

 

To give you a better description, I am going to be using the two sliders as a GUI control for changing the axis range on a graph.  After the user sets the max value, it is annoying to have it change should the user fail to click on the lower value slider (user error) when trying to set the minimum.

0 Kudos
Message 3 of 8
(3,939 Views)

Hi,

 

I tried using an event structure to intercept the new value location, and then choose which slider is closer.  But there seems to be no way to tie the coordinates of the click to the value ( on the scale) of the click.

 

My thought was, intercept the click, find its value on the scale, compare it to the two slider values, and move the closer one to that value by activating the closer slider and then changing its value.

 

***

 

One easy method would be to activate each slider in succession.  Starts with slider 0, then after first click activate slider 1, etc..   But this seems a bit clumsy.

 

I have attached a proto VI to 'play' with the behaviour of the slider.  In and of itself, this VI could be changed to exhibit the behaviour you want, but it would have to fit into the overall program you are writing.  A starting point anyhow.

 

-------
Mark Ramsdale
-------
0 Kudos
Message 4 of 8
(3,935 Views)

My initial thought was also to try and intercept the mouse click action, but I could see no way to do it.

 

My current attempt is to let the change occur as normal, then compare with the previous values.  If intervention is required, I change the values.  I am attaching my current attempt (only does anything if the lower slider is active).  So far, the cluster values look correct, but the slider isn't responding correctly.

 

You can play with it to try and reproduce what I am seeing.  As you play around with it, you can see that if the output cluster value is something like [500, 50000] the slider has those values for the min and max sliders.  However, if you click near the top slider, the code is supposed to intervene and move the top slider, instead of the bottom one.  You can see the ouput cluster will read something like [500, 40000] which is correct but instead, the actual slider will be set to the values [40000, 50000].  I have no idea how the slider is using values which do not match the cluster used to assign the values.

 

These are arbitrary numbers I'm reporting to describe the behavior.

0 Kudos
Message 5 of 8
(3,931 Views)
Solution
Accepted by topic author pjr1121
Message 6 of 8
(3,924 Views)

Thanks Darin,

 

That is exactly what I was trying to do.  I can't believe I didn't find it on the forums.  Although it is not exactly clear to me right now how this code achieves the desired result, I am happy to try and figure it out.  I'm new to using event structures and look forward to this as a learning opportunity

0 Kudos
Message 7 of 8
(3,910 Views)

Thanks.  I was wondering if there was some way to take the bounds and estimate location of the click in terms of the scale.

 

At least thats what this seems to be.

-------
Mark Ramsdale
-------
0 Kudos
Message 8 of 8
(3,907 Views)