是否可以在WindowButtonMotionFcn中使用多个回调?

编程入门 行业动态 更新时间:2024-10-24 17:21:56
本文介绍了是否可以在WindowButtonMotionFcn中使用多个回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建了一个类,它为构建一个图添加了功能。这个类为 WindowMouseMotion 事件创建一个监听器;然而,要使这个事件触发,我不得不为图的 WindowButtonMotionFcn 属性添加一个虚拟回调函数。我首先检查这个属性是否已经填充。如果不是,那么我将它设置为一个无效的哑回调函数。

I created a class which adds functionality to a figure on construction. This class creates a listener for the WindowMouseMotion event; however, to get this event to fire I had to add a dummy callback function for the figure's WindowButtonMotionFcn property. I first check if this property is already populated. If it isn't then I set it to a dummy callback function that does nothing.

不是检查属性是否已经设置,对任何现有的回调虚假回调?回调属性是否可以调用多个函数?

Instead of checking if the property is already set or not, can I simply add this dummy callback to any existing callbacks? Is it possible for a callback property to call multiple functions?

EDIT

当使用 handle.listener 方法处理下面给出的 WindowButtonMotionEvent 事件时,请务必使用 eventdata.CurrentPoint 以访问当前鼠标位置。该图的 CurrentPoint 属性在以这种方式处理 WindowButtonMotionEvent 事件之前不会更新。

When using the handle.listener approach to handle the WindowButtonMotionEvent event given below, be sure to use eventdata.CurrentPoint to access the current mouse position. The CurrentPoint property of the figure does not get updated before handling the WindowButtonMotionEvent event in this manner.

推荐答案

相关文章可以在Yair Altman的Undocumented MATLAB博客上找到,来自客户博客Matt Whitaker。您所指的是回调链,并在博客中引用:

A related article can be found on Yair Altman's Undocumented MATLAB blog, from guest blogger Matt Whitaker. What you are alluding to is callback chaining, and quoting from the blog:

坦率地说, b $ b以前处理callback chaining,我宁愿用叉子戳眼睛。

Frankly, having written code previously that handles callback chaining, I would rather poke myself in the eye with a fork!

<幸运的是,在这篇文章中似乎有一个替代解决方案。使用发布在那里的代码片段,我能够得到一个函数来执行鼠标移动,而不必设置'WindowButtonMotionFcn'。我添加了一个监听器到当前的数字,像这样:

Luckily, there appears to be an alternative solution in that article. Using a snippet from the code posted there, I was able to get a function to execute on mouse movement without having to set the 'WindowButtonMotionFcn'. I added a listener to the current figure like so:

myListener = handle.listener(gcf,'WindowButtonMotionEvent',... @(hSource,eventData) disp('hello'));

当我显示 hello 在窗口中移动鼠标。

And the message hello was displayed when I moved the mouse in the window.

更多推荐

是否可以在WindowButtonMotionFcn中使用多个回调?

本文发布于:2023-11-25 04:10:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628267.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   回调   WindowButtonMotionFcn

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!