How can I add a mouse movement listener to a custom ui component?

9 visualizaciones (últimos 30 días)
Hello everyone,
I have created a MatLab app that uses mousemovement events. It uses the WindowButtonMotion callback of the UIFigure that was described here https://nl.mathworks.com/matlabcentral/answers/775147-how-to-create-mouse-movement-event-on-uiaxes-in-app-designer-to-catch-cursor-location-on-the-axes in the answer (Method 2) by Adam Danz
The app works nicely. However, now that the project is evolving, I would like to convert the App to a Custom UI Component. But MatLab components do not seem to include a UIFigure, and therefore no WindowsButtonMotion event/callback. The Custom UI Component itself (comp) and UIAxes do not have a WindowButtonMotion event.
What I would like is a mousemovement event/callback/listener that calls a function so that I can check the mouse position against criteria and take appropriate action. This seems like very common functionality, but I cannot figure out how to accomplish this in a Custom UI Component.
Any ideas?
=== edit ===
To provide some details: The Custom UI Component has an Axes component that displays data. Rectangles are drawn on the Axes to highlight a portion of the data. These rectangles can be selected and deselected by a mouseclick. The mousemovement event is used in two ways. 1) if the cursor position is near the border of a selected rectangle, the cursor icon should change to a double arrow, and change back to a pointer when it is not near a border. 2) to drag the border of a rectangle to change its size.
The only solution I can think of is to let the parent app pass on the cursor position to the component using the apps WindowButtonMotion callback. That works, but requires adding code in the parent app, which is not very elegant. If anyone has a nicer solution, I would love to hear it. Thanks!

Respuestas (1)

Animesh
Animesh el 11 de Jun. de 2024
To implement a mouse movement event in a Custom UI Component in MATLAB, you can consider using JavaScript within the HTML code of the component. MATLAB allows you to integrate HTML/JavaScript with your MATLAB code, which can be used to detect mouse movements.
For more information on "Creating Custom UI Component With HTML", please refer to the following link - https://www.mathworks.com/help/matlab/creating_guis/customize-extensible-ui-component-properties.html

Categorías

Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by