Problem with drawline and drawpoint in 2021b
11 views (last 30 days)
Show older comments
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
Cris LaPierre
on 18 Oct 2021
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?
Answers (1)
Cris LaPierre
on 18 Oct 2021
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
Cris LaPierre
on 19 Oct 2021
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
See Also
Categories
Find more on Visual Exploration in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!