Unexpected UIAxes Interaction behaviour
Show older comments
Hello all,
I have an annoying little problem in Matlab that I fail to understand and don't know how to solve. Whenever I am making an app in AppDesigner, and I want to switch or change the built-in axes interactions, the app only becomes responsive if moving my mouse away from the UIAxis, onto a different item, and then moving back.
Attached is a small demonstrator app that shows the behaviour. This app plots a random 3D line with its default [rotate zoom]-interactions. When I press the Control-key it will switch this default interaction to [pan zoom]-interactions. Again pressing control will switch back (effectively toggling the behaviour).
However, upon pressing control (without moving the mouse) it will disable any interaction. Clicking and dragging the mouse will not do anything. Only when the mouse is moved off the UIAxes, onto some other part of the app (for example, a panel), and then back again, the interactions will function (and indeed be switched).
This is the main snippet of code that should hopefully make it clear:
% properties (Access = public)
Store % Container used for storing in the app
% Code that executes after component creation
function startupFcn(app)
% Set default parameter
app.Store.InteractionType = true;
% Create data to display
app.Store.Data = rand([10 3]);
% Plot data in UIAxes
app.Store.Plot = plot3(app.UIAxes, app.Store.Data(:,1), app.Store.Data(:,2), app.Store.Data(:,3), ...
LineWidth=2, Marker="o", MarkerEdgeColor=[1.0 0.6 0.6], MarkerFaceColor=[1.0 0.0 0.0]);
end
% Key press function: UIFigure
function UIFigureKeyPress(app, event)
% React to only the Control key
if strcmpi(event.Key, 'control')
% Change behaviour based on wether or not this has been clicked before, essentially "toggling"
% the behaviour
if app.Store.InteractionType
% Change the default behaviour to pan and zoom, and change value
app.UIAxes.Interactions = [panInteraction zoomInteraction];
app.Store.InteractionType = false;
else
% Change the default behaviour to pan and zoom, and change value
app.UIAxes.Interactions = [rotateInteraction zoomInteraction];
app.Store.InteractionType = true;
end
end
end
Am I doing something wrong? How can I make sure the app will function immediately after releasing the control button?
Answers (2)
Mark Kamps
on 12 Sep 2023
0 votes
Raj
on 15 Sep 2023
0 votes
Hi Mark,
I understand that you are facing issues while designing your App. I was able to reproduce the issue you had and was able to understand your observations.
I have an alternate approach to your problem which works just fine and doesn’t have any issue.
Instead of KeyPressFcn, you can use KeyReleaseFcn and make the necessary changes in the code and the callbacks and you can go ahead with your project. This works without any issue and on pressing the ‘control’ key, the screen doesn’t freeze as it was before.
I've attached the file for your reference.
I hope this resolves your issue and you are able to proceed further!!
2 Comments
Mark Kamps
on 15 Sep 2023
Raj
on 20 Sep 2023
Hi Mark,
In R2023a, it works just as how you mentioned. The interactions switches after the control button is released, even when the cursor button is on the object.
You can try using the R2023a version and I hope your issue gets resolved.
Categories
Find more on Environment and Settings 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!