Problem with drawline and drawpoint in 2021b

Hi,
I created an app in matlab 2020b an now opened it in 2021b. In the app I can draw multiple lines and points over an image in UIaxes and then stop the drawline/drawpoint function by pressing a button in the app. This worked fine in 2020b but now in 2021b when I press the button at the end it draws a point/line at the edge of the axes and I cant use the button. If you need more information, just tell me.
I hope you can help me.
function DrawLinesButtonValueChanged(app, event)
import java.awt.Robot;
import java.awt.event.*;
value = app.DrawLinesButton.Value;
if value==1
userstop=false;
while ~userstop
d=drawline(app.UIAxes,"color",[0,1,0],"tag","anglelines");
if ~isvalid(d) || isempty(d.Position)
userstop=true;
else
pos = d.Position;
diffPos = diff(pos);
length = hypot(diffPos(1),diffPos(2));
end
end
if value==0
SimKey=Robot;
SimKey.keyPress(java.awt.event.KeyEvent.VK_ESCAPE);
SimKey.keyRelease(java.awt.event.KeyEvent.VK_ESCAPE);
end
end
This is the code I use in the callback of a state button. Im drawing the lines in UIAxes.

6 Comments

Please share a working example.
You mean something like a video that shows whats not working?
Hendrik
Hendrik on 18 Oct 2021
Edited: Hendrik on 18 Oct 2021
Ok, I have updated the question.
I am able to replicate an issue where, when toggling the state, a point is drawn the edge of my UIAxes closest to the button. However, the button is still usable. Is that what you are seeing?
Yes, with buttons its just the problem, that points are drawn on the edge of the axes, but I cant use edit fields at all.

Sign in to comment.

Answers (1)

What is happening is that drawline is registering the click on the canvas (i.e. it is not limiting clicks to when the cursor is over the axes). This is true for both axes and uiaxes, and figure and uifigures, both in MATLAB and in App Designer.
Because you call drawline inside a while loop, it is always actively waiting for the next click. You need to cancel your drawline operation before clicking on the button. You can do this by pressing the escape key.

2 Comments

If I cancle the drawline operation by pressing ESC it cancles the whole while loop and I cant continue drawing lines after that without clicking the "draw lines" button again.
In Matlab 2020b it would also draw a line on the edge of the axes, if I clicked somewhere outside the axes. But if you clicked on a button or edit field thats outside the axes it wouldnt happen and thats what I want. Do you know how I can get the same behavior in Matlab 2021b?
I see your point. I don't know there is anything you can do to change this behavior. If you feel this change has an adverse impact, the best thing to do is report it here: https://www.mathworks.com/support/contact_us.html

Sign in to comment.

Categories

Find more on Develop Apps Programmatically in Help Center and File Exchange

Asked:

on 11 Oct 2021

Commented:

on 19 Oct 2021

Community Treasure Hunt

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

Start Hunting!