2
votes

While specifyfing the callback type for a pushbutton using Matlab's GUIDE, there are several options, two of which are described below:(words quoted from Matlab's documentation)

  1. ButtonDownFcn:Executes when the user presses a mouse button while the pointer is on or within five pixels of a component or figure

  2. Callback:Control action. Executes, for example, when a user clicks a push button or selects a menu item.

The description seems to suggest that they do the same thing.What is the difference between these two callback type?

2

2 Answers

4
votes

The ButtonDownFcn callback should fire when you press the mouse button down over the uicontrol, whether or not you release the mouse button, and whether or not your action eventually activates the uicontrol.

The Callback callback should fire when the uicontrol is activated. Activated means different things for different uicontols - for a pushbutton it means that the pushbutton is pushed, for a checkbox it means that the checkbox is selected or deselected, for an editbox it means that the text contents are modified.

Let's say you have a pushbutton with a Callback callback, but no ButtonDownFcn callback. If you hover over the pushbutton, click and hold the mouse, move away from the pushbutton, and then release, the Callback callback should not be fired, as the pushbutton was not activated. But if it had a ButtonDownFcn callback instead, that would have fired as soon as you clicked the mouse the first time, even though the pushbutton was not eventually activated.

If it had both, and you fully clicked and released on the pushbutton to activate it, the ButtonDownFcn should fire first, as it fires on the down-click, which is before the activation.

0
votes

The Callback callback should fire when the uicontrol is activated. Activated means different things for different uicontols - for a pushbutton it means that the pushbutton is pushed, for a checkbox it means that the checkbox is selected or deselected, for an editbox it means that the text contents are modified

The ButtonDownFcn callback should fire when you press the mouse button down over the uicontrol, whether or not you release the mouse button, and whether or not your action eventually activates the uicontrol.