Bug in R2021a with current Point of UIAxes

4 views (last 30 days)
Arne T
Arne T on 15 Nov 2021
Commented: Benjamin Kraus on 17 Nov 2021
Hi,
I was using R2019b and made a GUI-Programm. Everything worked fine. Now i updated to R2021a and have a bug with the current Point of UIAxes.
There is a UIAxes in my GUI and I ask for the current point, if i press a Button and save the current Point in a global variable. If i click on another button I check, if the saved current Point is equal to the actual current point. The result is false in every case. I dont know why the current point is changing, it worked in R2019a, so there cant be a logic mistake.
UPDATE: I found out that in R2021a the current point is not the last point clicked in the UIAxes, it is the last point clicked in the GUI, what is absolutly without any sense!
Does anybody know how to get the last point clciked in the UIAxes and not in general?
Thanks!

Accepted Answer

Benjamin Kraus
Benjamin Kraus on 17 Nov 2021
The CurrentPoint property on UIAxes will always reflect the last click detected anywhere in the figure. That is how CurrentPoint has worked on regular axes for a long time, and how it has worked on UIAxes for as long as CurrentPoint has been supported on UIAxes. I just tested in a simple figure in R2019b and R2021a and that is the behavior I am seeing in both versions.
There was a limitation in R2019b that if you clicked within a panel (but not on a UIAxes) and on some other UI components, that click was not being detected, and therefore the CurrentPoint was not updated. If you clicked on the figure directly (not inside a panel or another container or component), those clicks would be detected and the CurrentPoint would be updated. This limitation was removed in R2020b, and I suspect that is why you are seeing this change in behavior in your app.
For example, in the picture below:
  • If you click the green dot you should see the current point reflect [0.5 0.5]. This is what you were expecting.
  • If you click the red dot you should see the current point reflect [0.1 -0.05]. Even though that dot is outside the axes, the current point will show you the place you clicked relative to the data values in the plot.
  • If you click the blue dot you should see the current point reflect [1.2 0.5], for the same reason as the red dot.
  • In R2019b, if you click anywhere in the yellow region, CurrentPoint will not be updated. This was a limitation in R2019b that has since been removed. In R2020b and later, if you click anywhere in the yellow region, CurrentPoint will be updated.
  • In R2019b, R2021a, or any other release, clicking on the figure itself (the outer region outside the yellow region), CurrentPoint will be updated.
If your goal is to record the last point clicked, then you have a few options:
  1. Use the ButtonDownFcn on the axes (or UIAxes) itself. Starting in R2020b you can use the ButtonDownFcn on UIAxes (it did not work in R2020a or earlier releases). This callback will only fire when you click on the uiaxes/axes. To use this effectively, you may need to disable HitTest on objects in the axes. See Capturing Mouse Clicks for more details.
  2. Add a WindowButtonDownFcn to the figure, and when the callback fires (a) read the CurrentPoint property on the uiaxes/axes, (b) check if the CurrentPoint is within the axes limits, and if so (c) store the CurrentPoint somewhere for use later. Unlike ButtonDownFcn on the uaixes/axes, WindowButtonDownFcn on the figure will fire even if there are other objects in the axes that get in the way.
f = uifigure;
p1 = uipanel(f,'Position',[10 10 525 400],'BackgroundColor','yellow');
p2 = uipanel(p1,'Position',[25 25 475 350]);
u = uiaxes(p2);
f.WindowButtonDownFcn = @(~,~) disp(u.CurrentPoint(1,1:2));
s = scatter(u,[0.1 0.5 1.2],[-0.05 0.5 0.5],[],eye(3),'filled');
axis(u,[0 1 0 1])
s.Clipping = 'off';
legend(u,'Location','NEO')
  2 Comments
Benjamin Kraus
Benjamin Kraus on 17 Nov 2021
The reason for this behavior is that CurrentPoint does double-duty for both clicks (the WindowButtonDownFcn and ButtonDownFcn) and motion events (WindowButtonMotionFcn). There is a note in the documentation that says this: "The two points indicate the location of the last mouse click. However, if the figure has a WindowButtonMotionFcn callback defined, then the points indicate the last location of the mouse pointer."
The fact that CurrentPoint can reflect points outside the axes is much more useful for things like click-and-drag (which leveral the WindowButtonMotionFcn). To give a concrete example, when you are panning on an axes, you click the axes and start dragging. During the drag, the CurrentPoint continues to be updated wherever the cursor is, allowing you to keep panning even though the cursor is outside the axes.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by