appDesigner and ButtonDownFn does not work?

Documentation states that any Matlab object can respond to click events provided they meet certain conditions.
In my case, the PickableParts property is not set to 'None' and Hit Test property is set to 1, which I'm not sure how to interpret. I use this line of code to set the ButtonDownFn callback:
> set(app.TroisD,'ButtonDownFcn',@ScatterClickCallback);
app.TroisD is the name of my appDesigner axis object.
When debuging the app, I use this line of code to capture the app.TroisD object:
> Roger = get(app.TroisD);
When I browse the object Ctrl + D, I get this:
To me, this clearly shows that Matlab has honoured my ButtonDownFn callback, and its PickableParts property is not set to 'None' and HitTest is set to 1.
I have set some dummy code and a breakpoint in the Callback function code, so that I can inspect the 'event' argument:
% Button down function: TroisD
function ScatterClickCallback(app, event)
a = 333;
b = event;
end
Yet, when I run the app and click on the axis, all I get in response to my mouse click is a "beep"?

4 Comments

Shame on me for not having discovered / reasoned this out earlier.
I finally managed to get the axis to respond to a mouse click. Come to think of it, it wasn't so difficult and in line with the "philosophy" that no "building block" is to be built by the user in appDesigner. So, here's what I did, in case it helps.
First, in the Component Browser, I tried 'right-clicking' on the axis name and got some contextual menu. Oooh!
Second, as you can see in the screen capture, in the list of options was a 'familiar' Callbacks option! With the option to Add a ButtonDownFcn callback! Wow! I thought I was in business.
I selected the option and immediately, Matlab created the skeleton code to handle the event:
% Button down function: TroisD
function TroisDButtonDown(app, event)
a = 33;
b = 35;
end
Naturally, I add my usual "a" and "b" variables and set a breakpoint on the "b" assigment statement.
I pressed Run, selected some image and clicked inside the scatter3 drawn inside my app.axis and was immediately taken to my breakpoint!
So lesson learned :-)
Now onto some interesting stuff :-)
Well, trapping the mouse button down did not help :(
Because, it is only responding when clicking on a "empty" area. And I was hoping it would respond when clicking on an existing data point.
I tried creating a callback to get the mouse position when the 2D image is clicked but it's not doing anything....
Frustrating.
Got it! This post helped :
ButtonDownFunction on an image in App Designer
Modified my image creation code from this :
image(app.ImagePrincipale,img);
To this :
image(app.ImagePrincipale,img, "HitTest","off");

Sign in to comment.

Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products

Release

R2023a

Asked:

on 24 May 2024

Commented:

on 24 May 2024

Community Treasure Hunt

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

Start Hunting!