CurrentPoint in UIFigure as a ginput workaround for App Designer
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I trying to create a workaround to the lack of ginput functionality in the new App Designer UIFigure. The idea is to do the following:
- Use the CurrentPoint callback to register the pixel location
- Use pixel bounding box of axes InnerPosition and inpolygon to first confirm that click was within axes
- Convert CurrentPoint position to axes position based on scaling coordinates within axes and Xlim/Ylim properties
The issue I run into is the axes itself in the UIfigure appears to corrupt the CurrentPoint parameter. Using the image below to highlight the issue, for the UIFigure (with Position property = [312 336 1284 653]) I get the following 'CurrentPoint' results for the four locations shown:
- [191 140]
- [319 210]
- [1342 210]
- [911 152]
So it seems that Points 1 and 4, outside the UIAxes, are fine (i.e. line up well with the UIFigure Position property) but 2 and 3 are seemingly 'corrupted' (or rescaled).
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/198824/image.png)
Has anyone experienced this or knows that I might have wrong?
I am using Matlab 2018b
1 commentaire
Carl Lindquist
le 18 Avr 2019
Modifié(e) : Carl Lindquist
le 18 Avr 2019
Sorry for being late to the party, ju might already have solved this...? In that case, how did you do it? If not, here as a suggestion!
Answer
I have a similar experience! I encountered this in a complied Web App, where it seems as if CurrentPoint returns the mouse position relative to the browser window only when inside the UIAxes, but relative the the lower left corner of the UIFigure elsewhere. I digged around in the undocumented properties for a while, but wasn't able to locate the size of the actual browser window. I'm sure it's in there somewhere though...
Do you experience this in an uncomplied app...? In that case, the following works for me. I set the WindowButtonMotionFcn callback and then poll the event.Source.CurrentPoint inside the callback to get the location of the pointer.
To just record the mouse click inside a UIAxes, one can do
ax = struct(app.UIAxes).Axes;
ax.ButtonDownFcn = @(h, e) click_selection(app);
...where click_selection is some callback function that one can define. Using struct() on an object might cause MATLAB to complain a bit, so if the warning annoys you, you can set
warning off MATLAB:structOnObject
to shut it up.
Réponses (0)
Voir également
Catégories
En savoir plus sur Develop uifigure-Based Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!