Thread Subject: Slider, ButtonDownFcn

Subject: Slider, ButtonDownFcn

From: Stephan

Date: 30 Oct, 2008 08:47:01

Message: 1 of 11

I am programming a GUI. In this GUI, in need a slider to change a value. In the sliders callback, I'm showing the selected value in a edit text field.
If I select the slider-bar, I want to display the actual value before releasing the slider-bar. The problem is: If the sliders 'Enable' property is 'on', the button down function is not called with a click onto the slider-bar. Any suggestions how I can find out if anybody is pressing onto the slider-bar?

Subject: Slider, ButtonDownFcn

From: Walter Roberson

Date: 31 Oct, 2008 06:32:15

Message: 2 of 11

Stephan wrote:
> I am programming a GUI. In this GUI, in need a slider to change a value. In the sliders callback,
> I'm showing the selected value in a edit text field.
> If I select the slider-bar, I want to display the actual value before releasing the slider-bar.
> The problem is: If the sliders 'Enable' property is 'on', the button down function is not
> called with a click onto the slider-bar. Any suggestions how I can find out if anybody
> is pressing onto the slider-bar?

uicontrol behaviours are implemented in Java.

I would not like to use the design you propose: unless there is only a very small
range of slider values (e.g., 1, 2, 3, 4, and 5), the lag time in dragging makes
it too difficult to pick up the knob and move it to where you want.
Clicking on the bar to "nudge" the slider is just too useful for me to want
to override it to display the current slider value. I recommend leaving the
edit box up permanently and allow the user to type values in to it to move
the slider.

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: Slider, ButtonDownFcn

From: Stephan

Date: 31 Oct, 2008 08:47:01

Message: 3 of 11

Hi Walter

Tnx forr the suggestions, but I'm happy with using the slider as written. I don't want the user to type values into the textbox, that's why I'm using it like this. So you don't know either how to solve the problem?!

Subject: Slider, ButtonDownFcn

From: Walter Roberson

Date: 31 Oct, 2008 14:50:03

Message: 4 of 11

Stephan wrote:

> Tnx forr the suggestions, but I'm happy with using the slider as written.

If you were happy using the slider as written, you would not be trying to get rid of
the behaviour that clicking inside the bar currently has. Unless you are expecting
that somehow clicking in the bar would continue to have its current role of
changing the slider value -and- you want your routine called, two seperate actions on the
one click?

> I don't want the user to type values into the textbox, that's why I'm using it like this.

Let me quote from your original posting:

>>> In the sliders callback, I'm showing the selected value in a edit text field.

Matlab does not allow uses to type into a text box anyhow, but since you already have
an edit box (according to your original post), why not let the user use it to
control the slider position?

> So you don't know either how to solve the problem?!

What you are trying to achieve has become less and less clear.
But I will repeat: the behaviour of sliders (and all other uicontrols) is implemented
in Java. The implication of this is that if you want to change how sliders operate
then you need to manipulate the slider at the java level. If you want information
on how to do that java-level manipulation, I suggest that you seek out some of the
previous postings of Yair Altman.

In case I need to be explicit: you are trying to do something that uicontrol
sliders are designed not to support. There is no parameter in the documentation
that you have accidentally overlooked: sliders *should not* allow you to do
what you want to do, and if you want to force a slider to have the behaviour
you want, you will have to bribe the electronic guard-dogs and sneak over
the fence and sabotage the slider.

--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: Slider, ButtonDownFcn

From: Stephan

Date: 4 Nov, 2008 08:18:03

Message: 5 of 11

Tnx Walter for your help. Now my question is answered, I don't want to change the behaviour of the slider on the java level. And as you said, there is no chance to change it on matlab level.
The point is: I don't want the user to type values into the textbox, that's why I'm using a slider. You suggested to do so, but that was not my question and not a solution for my problem either.
By the way, I think the behaviour of the sliders buttonDownFcn is pretty strange. If the sliders enable property is on, it's called if you click on the 5-pixel border next to the slider. If it's inactive, it's called if you click onto the slider!

Subject: Slider, ButtonDownFcn

From: Walter Roberson

Date: 4 Nov, 2008 22:01:45

Message: 6 of 11

Stephan wrote:
> The point is: I don't want the user to type values into the textbox, that's why I'm using a
> slider. You suggested to do so, but that was not my question and not a solution for my
> problem either.

It still isn't clear to me what the problem -is-. If you want to update a text control
or edit control with the current value of the slider, you can do so in the Callback
routine without invoking the buttonDownFcn. The current value of the slider is available
as get(src,'Value') and you can num2str() that value and set() the 'String' property of
a uicontrol('Style','edit') or a uicontrol('Style','text') or text() object.

> By the way, I think the behaviour of the sliders buttonDownFcn is pretty strange.
> If the sliders enable property is on, it's called if you click on the 5-pixel border
> next to the slider. If it's inactive, it's called if you click onto the slider!

That's not what the documentation says, at least not in R2007a:

>>> Button-press callback routine. A callback routine that can execute when
>>> you press a mouse button while the pointer is on or near a uicontrol. Specifically:

>>> If the uicontrol's Enable property is set to on, the ButtonDownFcn callback
>>> executes when you click the right or left mouse button in a 5-pixel border around
>>> the uicontrol or when you click the right mouse button on the control itself.

>>> If the uicontrol's Enable property is set to inactive or off, the ButtonDownFcn
>>> executes when you click the right or left mouse button in the 5-pixel border or
>>> on the control itself.


I suspect, from you wording, that you want ButtonDownFcn to execute when the
user clicks while the user is pointed to the control, as -well- as the Callback
executing. (Mathworks would have to decide which of the two callbacks was done first,
but that's not a show stopper.) You should, however, take it as a general rule that
when you click on something, only *one* callback will be executed.

(It is not a strict rule, in that some levels have callback "filters", routines
that the user can provide to determine whether the callback should be handled at
the current level or should be passed on to the next level down, and one could
-argue- that each such filter routine triggered was a callback that had been
executed.)
--
.signature note: I am now avoiding replying to unclear or ambiguous postings.
Please review questions before posting them. Be specific. Use examples of what you mean,
of what you don't mean. Specify boundary conditions, and data classes and value
relationships -- what if we scrambled your data or used -Inf, NaN, or complex(rand,rand)?

Subject: Slider, ButtonDownFcn

From: Kelly Kearney

Date: 4 Nov, 2008 23:09:02

Message: 7 of 11

"Stephan " <schmutz@pyl.unibe.ch> wrote in message <gebsa5$8ns$1@fred.mathworks.com>...
> I am programming a GUI. In this GUI, in need a slider to change a value. In the sliders callback, I'm showing the selected value in a edit text field.
> If I select the slider-bar, I want to display the actual value before releasing the slider-bar. The problem is: If the sliders 'Enable' property is 'on', the button down function is not called with a click onto the slider-bar. Any suggestions how I can find out if anybody is pressing onto the slider-bar?

*
*
As Walter has detailed, Matlab's sliders cannot do this. However, if you really need this type of behavior, you can create your own pseudo-slider using an axis and patch, combining the use of the patch's ButtonDownFunction along with the figure's WindowButtonUpFcn and WindowButtonMotionFcn. Basically, use the button down and up function to turn on and off, respectively, a variable indicating action, and use the motion function to detect that variable and perform said action if it's set to on. I've done similar things to create scrollable axes and figures; I think there are examples on the File Exchange as well.
*
This method will quickly get bogged down if you're trying to update too many things while the scrolling motion is occurring, but I think updating a single edit box will be fine.
*
*
-Kelly

Subject: Slider, ButtonDownFcn

From: matt dash

Date: 5 Nov, 2008 01:06:03

Message: 8 of 11

"Stephan " <schmutz@pyl.unibe.ch> wrote in message <gep0fr$kuk$1@fred.mathworks.com>...
> Tnx Walter for your help. Now my question is answered, I don't want to change the behaviour of the slider on the java level. And as you said, there is no chance to change it on matlab level.
> The point is: I don't want the user to type values into the textbox, that's why I'm using a slider. You suggested to do so, but that was not my question and not a solution for my problem either.
> By the way, I think the behaviour of the sliders buttonDownFcn is pretty strange. If the sliders enable property is on, it's called if you click on the 5-pixel border next to the slider. If it's inactive, it's called if you click onto the slider!

I'll just add that changing the java behavior isnt as tricky as it sounds. Search this group for "instant update scrollbar" where I have posted an example of how to get the callback to run while the slider is dragged. It only requires two lines of (matlab) code, but uses the findjobj file from the file exchange.

As for not letting users edit the text box, why not just use a statictext uicontrol instead of edit.

Subject: Slider, ButtonDownFcn

From: Stephan

Date: 5 Nov, 2008 08:07:03

Message: 9 of 11

> By the way, I think the behaviour of the sliders buttonDownFcn is pretty strange.
> If the sliders enable property is on, it's called if you click on the 5-pixel border
> next to the slider. If it's inactive, it's called if you click onto the slider!

That's not what the documentation says, at least not in R2007a:

--> That was a change in R2008a. The behaviour is different now, as I said. Anyways, it's not the problem as you desrcibe. If you used R2008a, you knew that the slider callback is called with the Button up action (unlike in R2007, and for me, that was a BUG), that means after you release the slider. So there are not two callbacks to call at the same time: One is called with the button down function, the other one (the normal callback) with the button up.

Subject: Slider, ButtonDownFcn

From: Walter Roberson

Date: 5 Nov, 2008 18:33:41

Message: 10 of 11

Stephan wrote:
>> By the way, I think the behaviour of the sliders buttonDownFcn is pretty strange.
>> If the sliders enable property is on, it's called if you click on the 5-pixel border
>> next to the slider. If it's inactive, it's called if you click onto the slider!
 
> That's not what the documentation says, at least not in R2007a:

> --> That was a change in R2008a. The behaviour is different now, as I said.

Are you saying that it changed in R2008a to the behaviour that I quoted? But I quoted
from the R2007a document. Are you saying that it changed in R2008a to the behaviour
that you had indicated? If that is your claim, then see this document:
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/uicontrol_props.html

>>> Button-press callback routine. A callback routine that can execute when you
>>> press a mouse button while the pointer is on or near a uicontrol. Specifically:

>>> * If the uicontrol's Enable property is set to on, the ButtonDownFcn callback
>>> executes when you click the right or left mouse button in a 5-pixel border
>>> around the uicontrol or when you click the right mouse button on the control itself.

>>> * If the uicontrol's Enable property is set to inactive or off, the ButtonDownFcn
>>> executes when you click the right or left mouse button in the 5-pixel border or
>>> on the control itself.


For comparison, see also the R13 documentation,
http://www.mathworks.com/access/helpdesk_r13/help/techdoc/ref/uicontrol_props.html

>>> Button press callback routine. A callback routine that executes whenever you
>>> press a mouse button while the pointer is in a five-pixel wide border around
>>> the uicontrol. When the uicontrol's Enable property is set to inactive or off,
>>> the ButtonDownFcn executes when you click the mouse in the five-pixel border
>>> or on the control itself.

Which, as I read it, describes exactly the same behaviour except in different words.


If you have documentation that establishes that the behaviour was the way you described
in some release, please post a reference and possibly a quotation.

Subject: Slider, ButtonDownFcn

From: Stephan

Date: 6 Nov, 2008 07:16:07

Message: 11 of 11

I said that the behaviour is different now. You said that there is a problem to call two callbacks at the same click, at the same moment (You said: "I suspect, from you wording, that you want ButtonDownFcn to execute when the user clicks while the user is pointed to the control, as -well- as the Callback executing. (Mathworks would have to decide which of the two callbacks was done first, but that's not a show stopper.) You should, however, take it as a general rule that when you click on something, only *one* callback will be executed".) But that's not a problem in my case. Because it's not the same moment: One callback is called with the Button Down Action, the other one (the normal callback) with the button up. So there is no problem as you described it, where you have to call two callbacks at the same moment.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
gui Stiphu 30 Oct, 2008 04:50:20
slider Stiphu 30 Oct, 2008 04:50:20
button down fun... Stiphu 30 Oct, 2008 04:50:20
buttondownfcn Stiphu 30 Oct, 2008 04:50:20
rssFeed for this Thread

Contact us at files@mathworks.com