Problem with drawline and drawpoint in 2021b

8 Ansichten (letzte 30 Tage)
Hendrik Sorhage
Hendrik Sorhage am 11 Okt. 2021
Kommentiert: Cris LaPierre am 19 Okt. 2021
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 Kommentare
Cris LaPierre
Cris LaPierre am 18 Okt. 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?
Hendrik Sorhage
Hendrik Sorhage am 19 Okt. 2021
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Cris LaPierre
Cris LaPierre am 18 Okt. 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 Kommentare
Hendrik Sorhage
Hendrik Sorhage am 19 Okt. 2021
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?
Cris LaPierre
Cris LaPierre am 19 Okt. 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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Visual Exploration finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by