Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
AXES hides ButtonDownFcn

Subject: AXES hides ButtonDownFcn

From: Jan Simon

Date: 31 Jul, 2011 23:15:26

Message: 1 of 3

Dear readers,

An AXES object behind a UICONTROL hides the ButtonDown-Event:
  uicontrol('Style', 'pushbutton', 'String', 'Click me', ...
                'Position', [100, 100, 80, 24], ...
                'Callback', 'disp(''callback'')', ...
                'ButtonDownFcn', 'disp(''buttondown'')');
Now a left click writes 'callback' to the command window, and a right click writes 'buttondown'. But after an AXES is created,
  AxesH = axes;
the ButtonDownFcn is not longer called for right clicks.

Disabling the HitTest sensitivity let the button catch the right click again:
  set(AxesH, 'HitTest', 'off');

Is this behaviour 1. documented, 2. useful, 3. a known bug (I have not found it in the list of bugs)?
It appears at least under Matlab 6.5 and 2009a.

Thanks, Jan

Subject: AXES hides ButtonDownFcn

From: Steven_Lord

Date: 2 Aug, 2011 15:25:20

Message: 2 of 3



"Jan Simon" <matlab.THIS_YEAR@nMINUSsimon.de> wrote in message
news:j14nmd$e2j$1@newscl02ah.mathworks.com...
> Dear readers,
>
> An AXES object behind a UICONTROL hides the ButtonDown-Event:
> uicontrol('Style', 'pushbutton', 'String', 'Click me', ...
> 'Position', [100, 100, 80, 24], ...
> 'Callback', 'disp(''callback'')', ...
> 'ButtonDownFcn', 'disp(''buttondown'')');
> Now a left click writes 'callback' to the command window, and a right
> click writes 'buttondown'. But after an AXES is created,
> AxesH = axes;
> the ButtonDownFcn is not longer called for right clicks.
>
> Disabling the HitTest sensitivity let the button catch the right click
> again:
> set(AxesH, 'HitTest', 'off');
>
> Is this behaviour 1. documented, 2. useful, 3. a known bug (I have not
> found it in the list of bugs)?
> It appears at least under Matlab 6.5 and 2009a.

http://www.mathworks.com/help/techdoc/ref/axes_props.html#ButtonDownFcn

The axes ButtonDownFcn "Executes whenever you press a mouse button while the
pointer is within the axes, but not over another graphics object parented to
the axes. "

For the code you've written, the axes ButtonDownFcn appears to take
precedence over the uicontrol's ButtonDownFcn in this situation. While the
mouse pointer is over another graphics object in this scenario, it's not
another graphics object _parented to the axes_.

It appears from a quick experiment using release R2011a that the order in
which the graphics objects are created affect which object's ButtonDownFcn
is checked first (last one wins); try creating the axes prior to creating
the uicontrol.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: AXES hides ButtonDownFcn

From: Jan Simon

Date: 2 Aug, 2011 16:59:10

Message: 3 of 3

Dear Steven,

Thanks for this answer.
You are right: If the AXES is created at first, the UICONTROL keeps control over its ButtonDownFcn.

> The axes ButtonDownFcn "Executes whenever you press a mouse
> button while the pointer is within the axes, but not over another graphics
> object parented to the axes. "

And in addition, the AXES' ButtonDownFcn seems to be called whenever you press a mouse button while the pointer is within the axes, but not over later created GUI elements.

While this is expected when I stack several AXES objects, I thought, that UICONTROL are set on top of all AXES and AXES-children - as for the visualization and for catching the left-clicks.
I do not think, that this is an intuitive behaviour and it is not explicitely documented. But the behaviour is equal for Matlab 5.3, 6.5, 2009a and 2011a - so it is very stable. Therefore I'd do not call it a bug now and changing the behavior might reduce the backward compatibility.

I'm curious to hear if this is the same under Linux and MacOS.

Kind regards, Jan

Tags for this Thread

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.

Contact us